Project A-two
Diploma of IT
资讯科技文凭
IAPP001 - Applications Programming
应用程序编程
ASSESSMENT TASK #2: PROJECT A
评估任务#2:项目a
TASK DESCRIPTION
任务描述
This project requires students to create an Object Oriented design and coded solution for a chosen application, using all the concepts taught in the subject.
该项目要求学生使用本课程所教授的所有概念,为选定的应用程序创建一个面向对象的设计和编码解决方案。
You may choose to complete this assessment with at most one (1) other person. To work as a pair; you and your partner MUST be in the same tutorial class. You will need to spend approx. 10 hours together working on the assessment (outside of tutorial hours). If you do not intend to spend this time working together – choose to complete the assessment on your own. Both partners must put in an equal amount of work and effort, or the group will be dissolved by the tutor.
您可以选择与最多一(1)人一起完成此评估。成对工作;你和你的伴侣必须在同一个辅导班。你将需要花费大约。一起花10个小时做评估(除了辅导时间)。如果你不打算花这段时间一起工作-选择自己完成评估。双方都必须付出同等的努力,否则这个小组就会被导师解散。
Your code will be assessed against the learning outcomes below using techniques taught in the subject.
您的代码将使用本主题中教授的技术,根据以下学习结果进行评估。
LEARNING OUTCOMES
学习成果
Demonstrate a working knowledge of lists in Java.
展示Java中列表的工作知识。
Judge if a solution is well-designed.
判断解决方案是否设计良好。
Design a good OO solution from a specification.
根据规范设计一个好的OO解决方案。
Use inheritance in Java.
使用Java中的继承。
BRIEF
This is a take home assessment to evaluate your understanding of object oriented concepts taught so far in IAPP001. The assessment will be composed of three (4) parts: the scenario, the design, the code and explanation (including proof of testing).
这是一个带回家的评估,用来评估你对IAPP001中迄今为止所教授的面向对象概念的理解。评估将由三(4)部分组成:场景、设计、代码和解释(包括测试证明)。
All code must compile and run in BlueJ version 4.1.2 to be marked.
所有代码必须在BlueJ 4.1.2版本中编译和运行才能被标记。
The scenario: (200 words)
情景:(200字)
You will decide on the topic for your project. You should choose a business for example, a café.
你将决定你项目的主题。你应该选择一个行业,比如咖啡馆。
You will write the basic usecases for the business, including identifying the major functionality the application must provide. At a minimum, your scenario needs to add objects to collections, retrieve a specific object from a collection (using list lookup) and display all objects in each collection.
您将为业务编写基本用例,包括确定应用程序必须提供的主要功能。至少,您的场景需要向集合中添加对象,从集合中检索特定对象(使用列表查找),并显示每个集合中的所有对象。
The design: (200 words)
You will create a simplified class diagram for your application, which shows the attributes/methods for each class and the inheritance. You should aim to have between 6 and 8 classes for your application. The classes should be: Main/driver class, parent class (at least 1), enum, child classes (at least 2), group class (at least 1).
您将为您的应用程序创建一个简化的类图,其中显示每个类和继承的属性/方法。您的应用程序应该有6到8个类。这些类应该是:主/驱动类,父类(至少1个),enum,子类(至少2个),组类(至少1个)。
You will explain how your design will provide the needed functionality for the application.
您将解释您的设计将如何为应用程序提供所需的功能。
The code:
You will write the code for the application using the design. Make sure you follow the guidelines setout in the subject eg use camelCase for objects, LetterCase for classes, all classes have toString(). Public mutators should be used sparingly etc
您将使用该设计为应用程序编写代码。确保您遵循主题中设置的指导方针,例如使用camelCase对象,LetterCase类,所有类都有toString()。应该谨慎使用公共mutator等
Your solution will need to use either interface or implementation inheritance (or both); overloading, overriding, menus with recursion and for each loops.
您的解决方案将需要使用接口或实现继承(或两者);重载、重写、递归菜单和for每个循环。
The explanation: (300 words)
解释:(300字)
You will explain the code you wrote and any problems you encountered and how you fixed them. At minimum you need to identify :
你要解释你写的代码,你遇到的任何问题,以及你是如何解决它们的。至少你需要确定:
All inheritance – including why inheritance was used in this/these class(es)
所有继承——包括为什么在这个/这些类中使用继承
All overloaded methods – why overloading was used in each case
所有重载方法-为什么在每种情况下都使用重载
All overriding methods – why overriding was used in each case
所有重写方法-为什么在每种情况下都使用重写
All enum classes – why enum was used in each case
所有枚举类——为什么在每种情况下都使用枚举
Any polymorphism – how it affected the code
任何多态性——它如何影响代码
You also need to include at least 1 screen shot of your code being testing on the object bench.
您还需要包含至少一个在对象工作台上测试代码的屏幕截图。
Please double check your code compiles and your submission document contains the updated version of all code prior to submission.
请在提交之前再次检查代码编译和提交文件中是否包含所有代码的更新版本。
SUBMISSION
You will submit your assessment in MS Word document format – yourName-studNo.doc.
您将以MS Word文档格式提交您的评估-您的姓名- studno .doc。
(You should also submit a copy of your blueJ project as a zip file)
(您还应该以zip文件的形式提交blueJ项目的副本)
The document will have 4 sections:
该文件将包含4个部分:
The scenario: You will write the usecases for your business
场景:您将为您的业务编写用例
The design: You will produce a simplified class diagram for your business
设计:您将为您的业务生成一个简化的类图
The code: You will copy the code from your BlueJ project into this section
代码:您将把BlueJ项目中的代码复制到本节中
The explanation: you will explain your code choices and reasoning. You also need to include at least one screenshot of testing your code. Include any issues you had and how you resolved them. Minimum 300 words.
解释:你将解释你的代码选择和推理。您还需要包含至少一个测试代码的屏幕截图。包括你遇到的任何问题以及你是如何解决的。最少300字。
The deadline for submission of this project is Friday 11:59pm in week 8.
这个项目的提交截止日期是第八周周五晚上11:59。
Draft Project idea: due Friday 11:59pm Week 6 for tutor approval
项目草稿:第六周周五晚上11:59交导师批准
Draft Project A: due Tutorial B Week 7 – draft code review by tutor
项目草案A:交教程B第7周-由导师审查代码草案
All projects submitted after the deadline will incur late penalties of 1 grade band every 2 days (or part thereof).
所有在截止日期后提交的项目将每2天(或部分时间)被罚1个等级。
REMINDER: ALL of the code must be your own unique work using concepts and techniques taught in the subject to satisfy academic integrity.
提醒:所有的代码必须是你自己独特的工作,使用的概念和技术,在学科教授,以满足学术诚信
However, you may use In, Record & Records classes – indeed - it is strongly advised that you incorporate these classes into your solution.
但是,您可以使用In, Record & Records类-确实-强烈建议您将这些类合并到您的解决方案中
**TASK DESCRIPTION**
This project requires students to create an Object Oriented design and coded solution for a chosen application, using all the concepts taught in the subject.
You may choose to complete this assessment with at most one (1) other person. To work as a pair; you and your partner MUST be in the same tutorial class. You will need to spend approx. 10 hours together working on the assessment (outside of tutorial hours). If you do not intend to spend this time working together – choose to complete the assessment on your own. Both partners must put in an equal amount of work and effort, or the group will be dissolved by the tutor.
Your code will be assessed against the learning outcomes below using techniques taught in the subject.
**LEARNING OUTCOMES**
1. Demonstrate a working knowledge of lists in Java.
2. Judge if a solution is well-designed.
3. Design a good OO solution from a specification.
4. Use inheritance in Java.
**BRIEF**
This is a take home assessment to evaluate your understanding of object oriented concepts taught so far in IAPP001. The assessment will be composed of three (4) parts: the scenario, the design, the code and explanation (including proof of testing).
All code must compile and run in BlueJ version 4.1.2 to be marked.
**The scenario: (200 words)**
You will decide on the topic for your project. You should choose a business for example, a café.
You will write the basic usecases for the business, including identifying the major functionality the application must provide. At a minimum, your scenario needs to add objects to collections, retrieve a specific object from a collection (using list lookup) and display all objects in each collection.
**The design: (200 words)**
You will create a simplified class diagram for your application, which shows the attributes/methods for each class and the inheritance. You should aim to have between 6 and 8 classes for your application. The classes should be: Main/driver class, parent class (at least 1), enum, child classes (at least 2), group class (at least 1).
You will explain how your design will provide the needed functionality for the application.
**The code:**
You will write the code for the application using the design. Make sure you follow the guidelines setout in the subject eg use camelCase for objects, LetterCase for classes, all classes have toString(). Public mutators should be used sparingly etc
Your solution will need to use either interface or implementation inheritance (or both); overloading, overriding, menus with recursion and for each loops.
**The explanation: (300 words)**
You will explain the code you wrote and any problems you encountered and how you fixed them. At minimum you need to identify :
- All inheritance – including why inheritance was used in this/these class(es)
- All overloaded methods – why overloading was used in each case
- All overriding methods – why overriding was used in each case
- All enum classes – why enum was used in each case
- Any polymorphism – how it affected the code
You also need to include at least 1 screen shot of your code being testing on the object bench.
**Please double check your code compiles and your submission document contains the updated version of all code prior to submission.**
场景描述「200字」
选择一个咖啡馆作为项目主题,咖啡馆里有各种各样的咖啡和食物。
用户可以选择需要的食物和饮料并为其支付。我们的程序包含:添加商品订单、查询特定的商品以及显示所有的可用的商品。
设计描述「200字」
程序包含以下类别:
- Main:主程序类;
- Product:产品的父类,属性包括价格、名称等;
- Drink 和 Food 是 Product 的子类。
- 例如:Drink 可以有额外的“冷热”。
- ProductType:枚举类,区分饮料和食物。
- Order:订单类,其中包含一个商品列表;
- Cafe:包含所有订单和商品的集合。
设计的目的是为了将饮料和食物统一处理,同时方便扩展到其他类型的商品,如甜点等。
代码:
这部分需要按照上面的设计,实际编写 Java 代码。
解释「300字」
在项目开发过程中,我使用了以下面向对象概念:
- 继承: 使用 Drink 和 Food 继承 Product 类,这样可以避免重复代码,并确保所有产品都有基本的属性。
- 方法重载: 在 Order 类中,可能会有几种不同的方法来添加产品,例如:通过产品 ID 或直接通过产品对象。
- 方法重写: 例如:如果 Drink 类有一个特殊的 toString 方法来同时显示价格和冷/热状态,这将覆盖类的 toString 方法。
- 枚举: 使用 ProductType 枚举来区分不同类型的产品,简化类型判断。
- 多态: 通过将饮料和食物视为产品,我们可以在订单中统一处理它们。
在开发过程中遇到的问题包括如何有效的查询特定的商品以及如何组织订单。通过使用列表和循环,以及利用 Java 的集合库,我们成功解决了这些问题。
截图略......
提交之前,确保在 blueJ 版本上正确编译运行。
代码
// 抽象父类 "Product" 代表所有的产品
public abstract class Product {
private String name; // 产品名称
private double price; // 产品价格
// 构造函数
public Product(String name, double price) {
this.name = name;
this.price = price;
}
// 获取产品名称
public String getName() {
return name;
}
// 获取产品价格
public double getPrice() {
return price;
}
// 抽象方法获取产品类型(由子类实现)
public abstract String getType();
// 覆盖toString方法返回产品名称和价格
@Override
public String toString() {
return name + " (" + price + ")";
}
}
// "Drink" 类是 "Product" 的子类,代表饮料
public class Drink extends Product {
private boolean isCold; // 判断是否是冷饮
// 构造函数
public Drink(String name, double price, boolean isCold) {
super(name, price);
this.isCold = isCold;
}
// 返回饮料是否是冷的
public boolean isCold() {
return isCold;
}
// 实现父类的抽象方法,返回产品类型
@Override
public String getType() {
return "Drink";
}
// 覆盖toString方法返回产品详情
@Override
public String toString() {
return super.toString() + " - " + (isCold ? "Cold" : "Hot");
}
}
// "Food" 类是 "Product" 的子类,代表食物
public class Food extends Product {
// 构造函数
public Food(String name, double price) {
super(name, price);
}
// 实现父类的抽象方法,返回产品类型
@Override
public String getType() {
return "Food";
}
}
// 枚举 "ProductType" 定义产品的种类
public enum ProductType {
DRINK, // 饮料
FOOD; // 食物
}
import java.util.ArrayList;
import java.util.List;
// "Order" 类表示顾客的订单
public class Order {
private List<Product> products; // 该订单中的产品列表
// 构造函数
public Order() {
this.products = new ArrayList<>();
}
// 向订单中添加产品
public void addProduct(Product product) {
products.add(product);
}
// 获取订单的总价格
public double getTotalPrice() {
double total = 0;
for (Product product : products) {
total += product.getPrice();
}
return total;
}
// 覆盖toString方法返回订单详情
@Override
public String toString() {
return "Order: " + products.toString() + " Total Price: " + getTotalPrice();
}
}
import java.util.ArrayList;
import java.util.List;
// "Cafe" 类表示咖啡馆
public class Cafe {
private List<Product> availableProducts; // 可供选择的产品列表
private List<Order> orders; // 已完成的订单列表
// 构造函数
public Cafe() {
this.availableProducts = new ArrayList<>();
this.orders = new ArrayList<>();
}
// 向咖啡馆添加产品
public void addProduct(Product product) {
availableProducts.add(product);
}
// 记录新的订单
public void newOrder(Order order) {
orders.add(order);
}
// 获取可供选择的产品列表
public List<Product> getAvailableProducts() {
return availableProducts;
}
}
// 主类,程序的入口点
public class Main {
public static void main(String[] args) {
Cafe cafe = new Cafe(); // 创建一个新的咖啡馆
Product coffee = new Drink("Coffee", 2.5, false); // 创建咖啡产品
Product sandwich = new Food("Sandwich", 3.0); // 创建三明治产品
cafe.addProduct(coffee); // 向咖啡馆添加咖啡
cafe.addProduct(sandwich);// 向咖啡馆添加三明治
Order order1 = new Order(); // 创建新的订单
order1.addProduct(coffee); // 向订单添加咖啡
order1.addProduct(sandwich);// 向订单添加三明治
cafe.newOrder(order1); // 记录新订单
System.out.println(order1); // 打印订单详情
}
}
所有的 arraylist 改成 linkedlist:
以下是修改后的代码,将所有的 ArrayList
改为 LinkedList
:
Product.java, Drink.java, Food.java, 和 ProductType.java 的代码可以保持不变,因为这些类中并没有使用到
ArrayList
。Order.java:
import java.util.LinkedList;
import java.util.List;
public class Order {
private List<Product> products;
public Order() {
this.products = new LinkedList<>(); // 将ArrayList更改为LinkedList
}
public void addProduct(Product product) {
products.add(product);
}
public double getTotalPrice() {
double total = 0;
for (Product product : products) {
total += product.getPrice();
}
return total;
}
@Override
public String toString() {
return "Order: " + products.toString() + " Total Price: " + getTotalPrice();
}
}
import java.util.LinkedList;
import java.util.List;
public class Cafe {
private List<Product> availableProducts;
private List<Order> orders;
public Cafe() {
this.availableProducts = new LinkedList<>(); // 将ArrayList更改为LinkedList
this.orders = new LinkedList<>(); // 将ArrayList更改为LinkedList
}
public void addProduct(Product product) {
availableProducts.add(product);
}
public void newOrder(Order order) {
orders.add(order);
}
public List<Product> getAvailableProducts() {
return availableProducts;
}
}
- Main.java 的代码可以保持不变,因为该类中并没有直接使用到
ArrayList
。
通过上述更改,已经将所有的 ArrayList
修改为了 LinkedList
。
我将在 Main
类中添加一个命令行交互功能,并为咖啡馆提供一个类似菜单的界面,允许用户进行选择。下面是代码的更新部分。
import java.util.Scanner;
public class Main {
private static Cafe cafe = new Cafe();
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
showMainMenu();
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
displayProducts();
break;
case 2:
addNewProduct();
break;
case 3:
createNewOrder();
break;
case 4:
System.out.println("Exiting...");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
private static void showMainMenu() {
System.out.println("===== CAFE MENU =====");
System.out.println("1. Display Available Products");
System.out.println("2. Add New Product");
System.out.println("3. Create New Order");
System.out.println("4. Exit");
System.out.print("Please enter your choice: ");
}
private static void displayProducts() {
System.out.println("===== PRODUCTS =====");
for (Product product : cafe.getAvailableProducts()) {
System.out.println(product);
}
}
private static void addNewProduct() {
System.out.println("===== ADD NEW PRODUCT =====");
System.out.println("1. Drink");
System.out.println("2. Food");
System.out.print("Enter type (1 or 2): ");
int type = scanner.nextInt();
scanner.nextLine(); // consume newline
System.out.print("Enter product name: ");
String name = scanner.nextLine();
System.out.print("Enter product price: ");
double price = scanner.nextDouble();
scanner.nextLine(); // consume newline
if (type == 1) {
System.out.print("Is the drink cold? (yes or no): ");
boolean isCold = scanner.nextLine().equalsIgnoreCase("yes");
cafe.addProduct(new Drink(name, price, isCold));
} else if (type == 2) {
cafe.addProduct(new Food(name, price));
} else {
System.out.println("Invalid type. Product not added.");
}
}
private static void createNewOrder() {
Order order = new Order();
while (true) {
displayProducts();
System.out.println("Enter product name to add (or type 'done' to finish): ");
String productName = scanner.nextLine();
if (productName.equalsIgnoreCase("done")) {
break;
}
Product selectedProduct = null;
for (Product product : cafe.getAvailableProducts()) {
if (product.getName().equalsIgnoreCase(productName)) {
selectedProduct = product;
break;
}
}
if (selectedProduct != null) {
order.addProduct(selectedProduct);
System.out.println(productName + " added to order.");
} else {
System.out.println("Product not found.");
}
}
cafe.newOrder(order);
System.out.println("Order created: " + order);
}
}
import java.util.Scanner;
public class Main {
// 创建一个 Cafe 实例,用于存储产品和订单
private static Cafe cafe = new Cafe();
// 创建一个 Scanner 实例,用于从控制台获取输入
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// 循环显示主菜单,直到用户选择退出
while (true) {
showMainMenu();
int choice = scanner.nextInt();
scanner.nextLine(); // 消耗回车
// 根据用户的选择执行相应的操作
switch (choice) {
case 1:
displayProducts();
break;
case 2:
addNewProduct();
break;
case 3:
createNewOrder();
break;
case 4:
System.out.println("Exiting...");
System.exit(0); // 退出程序
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
// 显示主菜单
private static void showMainMenu() {
System.out.println("===== CAFE MENU =====");
System.out.println("1. Display Available Products");
System.out.println("2. Add New Product");
System.out.println("3. Create New Order");
System.out.println("4. Exit");
System.out.print("Please enter your choice: ");
}
// 显示所有可用产品
private static void displayProducts() {
System.out.println("===== PRODUCTS =====");
for (Product product : cafe.getAvailableProducts()) {
System.out.println(product);
}
}
// 添加新产品的功能
private static void addNewProduct() {
System.out.println("===== ADD NEW PRODUCT =====");
System.out.println("1. Drink");
System.out.println("2. Food");
System.out.print("Enter type (1 or 2): ");
int type = scanner.nextInt();
scanner.nextLine(); // 消耗回车
System.out.print("Enter product name: ");
String name = scanner.nextLine();
System.out.print("Enter product price: ");
double price = scanner.nextDouble();
scanner.nextLine(); // 消耗回车
if (type == 1) {
System.out.print("Is the drink cold? (yes or no): ");
boolean isCold = scanner.nextLine().equalsIgnoreCase("yes");
cafe.addProduct(new Drink(name, price, isCold)); // 添加饮料
} else if (type == 2) {
cafe.addProduct(new Food(name, price)); // 添加食物
} else {
System.out.println("Invalid type. Product not added.");
}
}
// 创建新订单并添加产品
private static void createNewOrder() {
Order order = new Order();
while (true) {
displayProducts();
System.out.println("Enter product name to add (or type 'done' to finish): ");
String productName = scanner.nextLine();
if (productName.equalsIgnoreCase("done")) {
break;
}
// 查找选择的产品
Product selectedProduct = null;
for (Product product : cafe.getAvailableProducts()) {
if (product.getName().equalsIgnoreCase(productName)) {
selectedProduct = product;
break;
}
}
if (selectedProduct != null) {
order.addProduct(selectedProduct); // 向订单中添加产品
System.out.println(productName + " added to order.");
} else {
System.out.println("Product not found.");
}
}
cafe.newOrder(order); // 在cafe中添加新订单
System.out.println("Order created: " + order);
}
}
这个命令行交互功能使用户可以:
- 显示所有可用的商品。
- 添加新商品。
- 创建新订单并向其中添加商品。
- 退出程序。
这个程序仅仅是一个简单的命令行应用,实际生产中的应用通常需要更复杂的错误处理和用户交互机制。
公众号:AI悦创【二维码】
AI悦创·编程一对一
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
方法一:QQ
方法二:微信:Jiabcdefh
- 0
- 0
- 0
- 0
- 0
- 0