HW Assignment3
HW Assignment3
Homework Assignment 3
Assignment goals
• Build experience working with files.
• Build experience converting text information into numerical data.
• Build experience programming basic algorithms.
• Build experience creating methods.
Description
This assignment is an improvement of the program that you have developed as your Programming
Project 1. Though hardcoded input is typical for any project's initial stage and debugging, it may not be
recommended as a permanent solution.
In this assignment, you must create a text file with the inventory. Each product from the inventory must
have a record in the file with the name, regular price, and type. There are several options for storing
records in the file. For example,
• each value takes one line in the file (i.e., three lines for one product). Then you must take care of
correct handling of the ends of the lines;
• all values are in one line that can be read as a string. Then you must handle the parsing of the
string;
• all values are in one line separated by a delimiter. Then you must handle a line with delimiters.
You are free to use any of the above or suggest your solution. However, regardless of your choice, you
will need to find information on how to handle the selected file format. Materials are available in the
lectures, textbook, and online Java manuals and documents.
There are two ways to read a file: as a Scanner object (used in lecture slides) or as a stream (used in
labs). Either can be used for this assignment.
Once you can read data from the file, you must remove hardcoded inventory. Instead, you should
program the inventory reading from the file to be saved in three arrays: Type X products, Type Y
products, and Type Z products. Assume that the inventory does not have more than 100 products of the
same type.
Use the three arrays to output the inventory menu. To handle the user's choice correctly, you must have
information about the factual number of products read from the file for each type. Once the user has
made a choice, specified the amount and date, your program must run as it was in Programming Project
1. The only addition is the name of the product in the output:
Page 1 of 3
The inventory:
1 Light Bulb 60W 3.0 Type X
2 Light Bulb 100W 5.99 Type X
3 Bolt M5 0.15 Type Y
4 Bolt M8 0.25 Type Y
5 Hose 25 feet 10.0 Type Z
6 Hose 50 feet 15.0 Type Z
Your choice: 6
Number of units: 2
When do you plan your purchase?
Month of purchase (mm): 12
Day of purchase (dd): 12
Year of purchase (yyyy): 2021
Your total for Hose 50 feet is 30 dollars 00 cents.
Convert the user's choice into array index and use getter to add the product name.
Recommendations
Read the description carefully. If necessary, clarify requirements with the instructor or TA. Use forums to
discuss the problem with your peers.1
Ask yourself what your program's input and output are. Then, think of how to divide the problem into
smaller tasks and plan to create methods for each task.
Use the lecture slides, labs, and the textbook to refresh the following concepts:
• working with files,
• classes and objects,
• arrays,
• string tokenizing.
You have three weeks and three submission attempts for this assignment. Here is the suggested
scenario on how to plan your work:
1. Start with a pseudocode or flow chart to describe your program. Discuss it with
your peers1, or TA, or instructor. At that time, you do not need detailed one week
knowledge about new concepts.
2. Write and debug your first draft. Test it. Once you have a working program that one week+
passes your test and is well documented – turn it in and back up your submission.
3. Take your time to think about your program and what can be done better: user five days of
interface, error checking, additional features, etc. Improve and polish the the last week
program and its documenting. If you can come to the working version, that is
better than the first submission – turn the second version in.
1See “Programming Assignments Requirements and Recommendations” to evaluate the acceptable level of
collaboration.
Page 2 of 3
4. In case something goes wrong or the opposite: you have the last-minute insight – the last
use the third submission. weekend
Submission
Please review your work carefully before submitting it. Read "Programming Assignments Requirements
and Recommendations." Check the grading rubric to make sure you are meeting all of the
requirements.
Submission should include:
(i) All Java source codes.
(ii) Copy of the Java source codes as PDF files, preferable as one file.
(iii) Screenshot(s) with your program dialog and outputs. The screenshot must show the full screen,
so your computer can be identified. Please resize your IDE panels the way that the required
dialog or output is visible along with the source code. Show as much source code as possible.
To submit your files, click the assignment title, then in the submission window, click the "Browse My
Computer" button to add files to the submission.
If you need it, you may add any comments in the comments area. Click the "Submit" button.
• You have three submission attempts; only the last one will be considered and graded.
• You may not retract your submission or resubmit for re-grading after the due date.
• Late submissions will not be accepted.
• If you have trouble with the submission, please contact your TA for assistance.
Page 3 of 3