ICSI 201 CQUPT SPRING 2024

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

ICSI 201 CQUPT SPRING 2024
LABS 3.1, 3.2, 3.3
AGGREGATION AND INHERITANCE
(100 POINTS)
READING
Read and review the following chapters to assist you in completing this project.
• Chapter 7: Arrays & the ArrayList Class
• Chapter 8: A Second Look at Classes and Objects
• Chapter 9: Text Processing and More about Wrapper Classes
• Chapter 10: Inheritance
OBJECTIVES
• Build experience using static fields.
• Build experience implementing aggregation relations.
• Build experience implementing inheritance relations.
• Build experience using abstract classes.
• Build experience using polymorphism.

ASSIGNMENT DESCRIPTION

This project is an enhanced version of the application prototype created in Lab 2. Your program must read the inventory data from a text file. The inventory of the hardware store may contain three types of products:
• Type R products have a strong demand all year round. The price does not depend on season or quantity.
• Type B products have a regular price and a bulky price. If a customer buys 100 or more units but less than 500, then the 5% discount will apply; for 500 or more units but less than 1500 the 15% discount will apply; for 1500 or more units the 25% discount will apply.
• Type S products are seasonable. During the period starting November 1 st and until February 1st the price is discounted by 40%.

Thus, products must have an attribute for type besides name, and regular price. The main menu of your program should have three options: show the inventory, make an order, review the orders, and exit.

To make an order the user should select a product by name, enter quality, and specify the date of purchase. The program must calculate the total price and add an item to the order. A new order should be added to the order list.Page 2 of 7

There is no limit on how long the order list can be. When the user decides to exit the program, the program must save the order list to a file orders.txt.

REQUIREMENTS

In this assignment besides the driver program, you must create several classes related to each other. Each class must be a separate file. The following UML diagram gives you an idea of how classes can be organized.
Note,

(a) a question mark before invSize means that you decide on the access specifier for this class member;

(b) you decide on the names of the class members, the above diagram is an illustration only;

(c) you can add as many fields and methods as you want. For example, class Order may have information about the customer of type String (or maybe a new class);

(d) the class Date is not required, you may represent a date with three integer variables. Please control the correctness of the date input using your Project 1 materials.

The superclass Product must be an abstract class and have a static variable to hold the size of the inventory. The inventory from the text file must be saved in an array or ArrayList, assume that the inventory should not exceed 100 products. The text file with data must have at least two records for each of the three product types.

You can use the inventory from Lab 2 by adding type R, B, or S for each item. Please note that Project 2 inventory has the amount – the available number of items in the store, it will be reasonable to check the user-requested quantity against this value, but it is not required.

For the list of orders use the ArrayList class.

Use methods in your driver program whenever it is appropriate. Consider your Lab 2 experience and reuse methods.

You will create several versions, which is typical in software development—each version shown as a task below. After you have the first task completed, save your work as the first version of the project. Use the copy of the first version as the basis for the second version that satisfies the requirements of the second task. The copy of the second version is the basis for the third version that satisfies the requirements of the third task, and so on.Page 3 of 7

At the end, you need to submit the last successful version only. Moreover, you may create no versions and work on the final product from the beginning. However, be aware of the advantages of the version-based approach:

(a) you can start immediately;
(b) it is an efficient scenario to practice;
(c) it is used in the industry;

(d) it is helpful if you need to prove that it is your original work.

INSTRUCTIONS

Complete Task #1 and Task #2 as your Lab 3.1 assignment.
Complete Task #3 and Task #4 as your Lab 3.2 assignment.

Complete any of the above tasks missed, debug, test and polish the project as your Lab 3.3 assignment.

TASK #1

Create an abstract superclass Product with a static variable that holds the number of products in the inventory. Its value must grow as reading from the file progresses. You will use this variable whenever you need the size of the inventory. Override a default toString() method such that it returns product attributes, at least name, regular price, and type. 

Create three subclasses for the superclass Product. Each subclass must have a constructor. Decide on the method

total() that calculates the cost of a number of products – if it needs to be overridden or overloaded in subclasses
according to the above overview.
• For the R-product, the total is the price multiplied by the number of units.
• For the B-product, the total depends on the number of requested units.
− If the number is less than 100, the total is the price multiplied by the number of units.
− If the number is more than 100 but less than 500, the total is the 5% discounted price multiplied by the number of units.
− If the number is more than 500 but less than 1500, the total is the 15% discounted price multiplied by the number of units.
− If the number is more than 1500, the total is the 25% discounted price multiplied by the number of units.

• For the S-product, the total is the regular price multiplied by the number of units outside the season or the 40% discounted price multiplied by the number of units during November, December, and January.

Create a main menu and make sure that you can upload and print the inventory. Use the superclass method toString() to print each object.

The advantage of inheritance is the ability to create a list (array) of superclass objects to be filled with objects of different subclasses. You can use the product’s position in the list to build the product’s ID. Page 4 of 7

TASK #2

Make sure that you can find a product in the inventory by the name inputted by the user. It can be the beginning of the implementation of the second option of the main menu. Use methods developed in the Lab 2. Note that Lab 2 results must be refined to be used in Lab 3.

Make sure that all modifications you have made keep your application alive and working.

TASK #3

Decide on how you will implement dates in your project. It can be a class or three integer values. I recommend creating a class Date that has a constructor that converts a string in the format “mm/dd/yyyy” into an object with three fields – month, day, and year. Do not forget to check the string and date for correctness.

Create a class Order that aggregates other classes – Product (the superclass due to polymorphism) and Date (if you use the class Date). Override a default toString() method to print an object of this class.

Add the quantity and date input to the second menu option. Remember, if the program reads a string from the keyboard after a number, you may need to handle the new line symbol left in the input buffer. When all the information is collected, the order is ready to be created. Make sure that you can create and print a new object of type Order.

TASK #4

Create an ArrayList of orders, and make sure that the user can add multiple orders to the list by implementing the review option of the main menu. This option should print the list of orders.

Implement the exit option of the menu. ArrayList of orders must be saved in the file orders.txt before the program quits.

EXAMPLES OF PROGRAM EXECUTION
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: i
The inventory:
1
Light Bulb 60W 3.0
R
2
Light Bulb 100W 5.99
R
3
Steel Bolt M5
0.15
B
4
Steel Bolt M8
0.25
B
5
Hose 25 feet
10.0
S
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: r
Date: 11/11/2023
+---+-----------------+------+----+
|ID |Name |Price |Type|
+---+-----------------+------+----+
1
Light Bulb 60W 3.0
RPage 5 of 7
6
Hose 50 feet
15.0
S
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: o
Enter product name:
Light Bulb 60W
Enter quantity:
100
What is the date of purchasing? (mm/dd/yyyy)
11/11/2023
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: o
Enter product name:
Steel Bolt M5
Enter quantity:
1000
What is the date of purchasing? (mm/dd/yyyy)
11/11/2023
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: o
Enter product name:
Hose 25 feet
Enter quantity:
10
What is the date of purchasing? (mm/dd/yyyy)
11/11/2023
(I)nventory
(O)rder
(R)eview the order
+---+-----------------+------+----+
QTY: 100
Total: 300.0
Date: 11/11/2023
+---+-----------------+------+----+
|ID |Name |Price |Type|
+---+-----------------+------+----+
3
Steel Bolt M5
0.15
B
+---+-----------------+------+----+
QTY: 1000
Total: 127.5
Date: 11/11/2023
+---+-----------------+------+----+
|ID |Name |Price |Type|
+---+-----------------+------+----+
5
Hose 25 feet
10.0
S
+---+-----------------+------+----+
QTY: 10
Total: 60.0
(I)nventory
(O)rder
(R)eview the order
(E)xit
Your choice: e
Your order is saved. Goodbye!Page 6 of 7
(E)xit
Your choice: w
Invalid choice

GRADING GUIDELINES

The breakdown of points for this assignment is in the table below. Note, in addition to the correctness, some points count towards how well your code is written and documented. Well-written code uses proper indentation that follows the scope of your statements and employs intuitive and self-documenting variable names.

Your code should include comments that detail the purpose of blocks of code or individual statements. Good documentation does not imply that more is better. The goal is to be efficient, elegant, and succinct!

Grading item
Points
1. The software meets the specification:
• Classes are designed as required.
• Classes are in separate files.
• Array and/or ArrayList are used.
• File input and output are implemented.

20
2. The software is well documented:
• Required comments are included.
• Necessary comments are included.
• Javadoc format and tags used.
• A screenshot with the results is provided.

10
3. The implementation is error-free and well-tested:
• There are no compilation errors.
• The software produces no error for all valid inputs.

20
4. The project is complete and works correctly:
• All menu options are implemented.
• A list of products implements polymorphism.
• Total calculates correctly for all product types.
• Dates are checked for correctness.
• The exit is processed correctly.

40
5. The programming style is efficient:
• The indentations are correct.
• Naming is descriptive.
• Methods are appropriate.

10

SUBMISSION

You must submit only one, the most successful, version. Please review your work carefully before submitting it. Also, check the grading rubric to ensure that your program meets all requirements.

Your lab instructor will provide you with a detailed description of the submission process. The usual requirements are as follows.

1. Submission should include:
a. A driver source code file named Lab3Driver_yourID.java. At the beginning of the source code file, you must have
− information about the author: course, semester, lab section, first and last name, and ID
− a brief description of the project
− test data that you used to check the correctness of the program – for this project, it is the name of a text file with sample data.
b. Source code files that implement classes that you created for the project: three classes for products, one class for order, and any additional classes that you created. You can name files in your way.
c. A text file (.txt) with sample data.
d. A text file (.txt) with resulting orders.
e. Besides the source code, you must submit a screenshot with the program dialog and results (see Programming Assignments Requirements and Recommendations about the screenshot requirements).
2. We may auto-run your code and if your file and class naming conventions deviate from the above, you will lose points.
IMPORTANT: no files with extension .class are accepted.
3. You may not retract your submission or resubmit for re-grading after the due date.
4. Late submissions will not be accepted.

5. If you have trouble with the submission, please contact your instructor for assistance.

POLICY ON CHEATING

This assignment is to be completed individually – cheating is not tolerated. We will be comparing your code against that of other students in the class and similar assignments from online platforms including Generative AI. All students involved in a cheating accident (i.e., whether sharing or receiving code) will be penalized. Please, read the syllabus for our policies on cheating and refer to Programming Assignments Requirements and Recommendations for examples of what we consider cheating, as those are not only limited to what you submit. Students caught cheating will receive 0 points for the assignment and will be reported.

发表评论

电子邮件地址不会被公开。 必填项已用*标注