本帖最后由 O_o” 于 2013-8-11 00:02 编辑
- //Acer Dell Lenovo HP IBM
- Console.WriteLine("请输入您要的笔记本品牌");
- string brand = Console.ReadLine();
- NoteBook nb = GetComputer(brand);
- nb.ShowBrand();
- Console.ReadKey();
- }
- /// <summary>
- /// 根据用户输入的笔记本品牌 创造对应的电脑
- /// </summary>
- /// <param name="brand">用户传入的笔记本品牌</param>
- /// <returns></returns>
- public static NoteBook GetComputer(string brand)
- {
- NoteBook nb = null;
- switch (brand)
- {
- case "lenovo": nb = new Lenovo();
- break;
- case "acer": nb = new Acer();
- break;
- case "hp": nb = new HP();
- break;
- case "dell": nb = new Dell();
- break;
- case "IBM": nb = new IBM();
- break;
- }
- return nb;
复制代码 |