Question: - Implement an application that will read data from an input file, interpret the data, and write the result to an output file. - For
- Implement an application that will read data from an input file, interpret the data, and write the result to an output file.
- For this portion of the lab, you must implement the Item class with the following description:
| Item class | |
| Data fields | |
| name: String price: double
| The items name The items price |
| Methods | |
| +Item(name: String, price: double) +Getters/Setters
+equals(Item i): boolean
+toString(): String | Initialize an item with a given name, price
Return true if the arguments name and price match the objects, otherwise false
Create and return a String for output This String should have the form: Item, costs $price. So an Item with name Cup, and price 5.50 should have this exact toString Cup, costs $5.50, with rounding to two decimal places |
- After writing the Item class, write the Sales class:
| Sales | |
| Data fields | |
| # inventory:ArrayList
# currentSales:ArrayList
| An ArrayList of stores item types. Make this protected, not private, for testing.
An ArrayList of the items currently being sold. Make this protected |
| Methods | |
| +Sales(filename:String)
+clearSales():void
+addToSale(index:int):void
+outputSale(fn:String):void
+printItems():void | The Sales constructor should take a file as input. A sample is provided in the storeInventory.txt file. The file should be used to initialize the values of the inventory array. Each line has an item name and then a price. Duplicates should not be allowed.
Empty the currentSales ArrayList that is, nullifying a sale
A method which adds a copy of the item at index index, from the inventory List, into the currentSales list. Make sure the index is not out of bounds!
Output a sales report to the file name specified by fn, then clear the currentSales ArrayList. This sales report should list each item and the items price (using the Items toString method) that is being purchased, one line at a time. It should then print the total money earned in the sale. After a sale, the currentSales list should be cleared
Print out the contents of the inventory
|
- Finally, write a main method that tests the Sales and Item classes. It should ask the user for an input file name and output file name. Then, it should display a simple menu allowing the user to add an item for sale, clear the sales to start over, see the inventory displayed, or output the sale to their chosen output file and quit.
A sample menu interaction is shown below and a sample output file is provided:
Enter your input file name:
storeInventory.txt
Enter your output file name:
output.txt
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
1
Bear, costs $65.50
Cup, costs $5.50
Plate, costs $6.50
Orange, costs $3.30
Pear, costs $3.14
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
0
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
0
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
2
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
10
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
2
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
0
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
1
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
3
Enter the index of the item (0 is first):
2
Pick a store option:
(1) List items
(2) Clear sales
(3) Add an item to sales
(4) Save sales and exit
4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
