using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Stock
{
public delegate void PriceRise(double money); //定义委托
public delegate void PriceDown(double money); public event PriceRise PriceRiseEvent; //定义事件
public event PriceDown PriceDownEvent; private string stockName;
private double stockPrice; public string StockName {
set;
get;
} public double StockPrice {
set;
get;
} public Stock(string name, double price) {
stockName = name; stockPrice = price;
} public void priceRise(double up) {
Console.WriteLine("股票上升: {0}", up);
PriceRiseEvent(up); //触发事件 } public void priceDown(double down) {
Console.WriteLine("股票下降: {0}", down);
PriceDownEvent(down);
} }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Buyer
{
private Stock stock; //卖家要抛售的股票 public Buyer(Stock s) {
stock = s;
} public void StockPriceRise(double up) { if (up > 0.05) {
Console.WriteLine("股票上涨已经超过5%, 买家谨慎买入");
} else {
Console.WriteLine("股票正在小幅上涨, 买家可以买入");
}
} public void StockPriceDown(double down) {
if (down > 0.05) {
Console.WriteLine("股票下跌已经超过0.05,买家可以逢低买入");
} else {
Console.WriteLine("股票正在小幅下跌,买家暂时请观望");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Seller
{
private Stock stock; //卖家要抛售的股票 public Seller(Stock s) {
stock = s;
} public void StockPriceRise(double up) { if (up > 0.05) {
Console.WriteLine("股票上涨已经超过5%, 卖家请赶快抛售");
} else {
Console.WriteLine("股票正在小幅上涨, 卖家可以继续观望");
}
} public void StockPriceDown(double down) {
if (down > 0.05) {
Console.WriteLine("股票下跌已经超过0.05,卖家请逢低补仓");
} else {
Console.WriteLine("股票正在小幅下跌,卖家请谨慎操作");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Program
{
static void Main(string[] args) { Console.WriteLine("输入股票名: ");
Stock stock = new Stock(Console.ReadLine(), ); Buyer buyer = new Buyer(stock);
Seller seller = new Seller(stock); //注册事件
stock.PriceRiseEvent += buyer.StockPriceRise;
stock.PriceDownEvent += buyer.StockPriceDown; stock.PriceRiseEvent += seller.StockPriceRise;
stock.PriceDownEvent += seller.StockPriceDown; //触发事件
Console.WriteLine("输入涨率: ");
stock.priceRise(double.Parse(Console.ReadLine()));
Console.WriteLine("输入降率: ");
stock.priceDown(double.Parse(Console.ReadLine())); }
}
}

最新文章

  1. ACCESS导入CSV文件出现乱码解决办法
  2. div标签上下滚动
  3. iOS 单例模式
  4. common-dbcp2数据库连接池参数说明
  5. Android canvas rotate():平移旋转坐标系至任意原点任意角度-------附:android反三角函数小结
  6. div+css页面居中代码
  7. 连接Oracle的几种方式
  8. Ansible好像很好玩的样子哟
  9. HDU 1557 权利指数 国家压缩 暴力
  10. SQL Server 创建表分区
  11. 【UOJ207】共价大爷游长沙(Link-Cut Tree,随机化)
  12. LINUX系统日常使用命令
  13. face recognition[MobiFace]
  14. shell模板变量替换
  15. HBase 笔记
  16. haproxy prometheus 监控docker-compose 运行试用
  17. 最高频的K个单词 · Top K Frequent Words
  18. day10(IO流汇总)
  19. 构建工具-----Gradle-----安装配置
  20. [Gradle] 获取 gradle 命令行参数

热门文章

  1. wamp 修改www目录
  2. mysql非安装包安装教程
  3. Internet History, Technology and Security (Week4)
  4. oh my god 四则运算
  5. 14_Java面向对象_第14天(Eclipse高级、类与接口作为参数返回值)_讲义
  6. Scrum 冲刺博客链接集合
  7. intel 的架构图
  8. [转帖]IBM POWER9 E950 and E980 Servers Launched
  9. ACM数论之旅13---容斥原理(一切都是命运石之门的选择(=゚ω゚)ノ)
  10. Vector源码解析