【发布时间】:2021-03-04 19:28:57
【问题描述】:
所以我正在制作一个管理书店的程序,下面是一个应该如何处理以下主要内容的示例:
bookStore bookStore = new bookStore("Lelo");
book l1 = new TecnicalBook("H. Schildt", "\"Java: The Complete Reference\"", 80, "Computer Science- Java");
bookStore.addBook(l1);
book l2= new AdventureBook("A. Christie", "\"The Man in the Brown Suit\"", 75, 14);
bookStore.addBook(l2);
Client c1 = new Premium("B. Antunes", "antunes@books.com");
bookStore.addClient(c1);
Client c2 = new Frequent("A. Oliveira", "oliveira@books.com");
bookStore.addClient(c2);
System.out.println("Initial stock:");
bookStore.showBooks();
bookStore.sale(l1, c1);
System.out.println("Stock after selling:");
bookStore.showBooks();
System.out.println("Sales Volume:"+bookStore.SalesVolume);
bookStore.showClientsBooks(c1);
应该显示这个结果:
Initial stock:
Author:H. Schildt Title:"Java: The Complete Reference" Base Price:80.0
Author:A. Christie Title:"The Man in the Brown Suit" Base Price:75.0
B. Antunes bought "Java: The Complete Reference", Tecnical Book of Computer Science- Java, for 72.0
Stock after selling:
Author:A. Christie Title:"The Man in the Brown Suit" Base Price:75.0
Sales Volume:72.0
B. Antunes bought: "UML Distilled". "The Man in the Brown Suit".
我唯一不能做的部分是最后一行,显示每个客户购买的产品,我正在考虑创建一个包含客户名称字符串和书籍类的数组列表的类,然后让每个客户的该类的数组列表,但我不确定如何制作这个,可能有更好的方法, 谢谢
编辑:我有这些课程: 课本 类技术书扩展书 类冒险书扩展书
类客户端 类常规扩展客户端 类频繁扩展客户端 高级课程扩展客户
我有一个书店类,其中我有一个书籍和客户对象的数组列表。
【问题讨论】:
-
我认为你建议的解决方案很好!
-
@Laugslander 所以可以说我创建了一个 clientBooks 类的数组列表,其中包含客户名称的字符串和书籍对象的数组列表,然后我如何添加客户购买的书籍以及如何我打印所有的?
标签: java oop arraylist polymorphism hierarchy