using Java, create a virtual shopping store. using the two txt files (items and sale), display a list of items, price and if on sale. have the user select what items they want until they press 'q' to quit. show list of what they purchased, add the total and how much they saved.   class BillProcessor { public static void prepareBill(LinkedHashMap purchases, LinkedHashMap items, LinkedHashMap sales, ArrayList itemNames) { total cost = 0 total discount = 0 for each item in purchases: compute the regular cost if item is subject to a sale (i.e. it appears in the sales lhm) determine the sales price if it's bogo - mod operator and the int/int if it's not bogo - apply the discount price compute the actual cost based on that total cost = total cost + actual cost total disc = total disc + discount print a line formatted like the example that summarizes the purchase of that item print the summary } } public class KlumpGroceryStore { private static LinkedHashMap items; // storage for the items and their costs private static LinkedHashMap sales; // storage for the itema and their sale descriptions private static LinkedHashMap purchases; // storage for the items and their quantities private static ArrayList itemNames; public static LinkedHashMap readItemsFromFile(String fname) { LinkedHashMap result = new LinkedHashMap(); itemNames = new ArrayList(); open up the file for each line of the file split it into its two parts at the tab result.put(item name, the price you read for it) itemNames.add(the item name you read) close the file Collections.sort(itemNames); return the result } public static LinkedHashMap readSalesFromFile(String fname) { LinkedHashMap result = new LinkedHashMap(); open the file for each line of the file split it at the tab result.put(item name, the sales description) close the file return the result } public static void presentMenuOfItems() { for each itemName in itemNames: print itemName along with items[itemName] and a description based on sales[itemName] add on the "q" to quit option } public static void main(String[] args) { items = readitemsFromFile("items.txt"); sales = readSalesFromFile("sales.txt"); purchases = new LinkedHashMap(); present to the user the table of grocery items do { ask them to the choice use the number and the itemNames to figure out the name of the item if the purchases lhm already has that item purchases[the item name] = purchases[the item name] + 1 else purchases[the item name] = 1; // first time purchase of that item } while they don't want to quit BillProcessor.prepareBill(purchases, items, sales, itemNames); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

using Java, create a virtual shopping store. using the two txt files (items and sale), display a list of items, price and if on sale. have the user select what items they want until they press 'q' to quit. show list of what they purchased, add the total and how much they saved.

 

class BillProcessor {
public static void prepareBill(LinkedHashMap<String, Integer> purchases, LinkedHashMap<String,Double>
items, LinkedHashMap<String,String> sales, ArrayList<String> itemNames) {
total cost = 0
total discount = 0
for each item in purchases:
compute the regular cost
if item is subject to a sale (i.e. it appears in the sales lhm)
determine the sales price
if it's bogo - mod operator and the int/int
if it's not bogo - apply the discount price
compute the actual cost based on that
total cost = total cost + actual cost
total disc = total disc + discount
print a line formatted like the example that summarizes the purchase of that item
print the summary
}
}

public class KlumpGroceryStore {
private static LinkedHashMap<String, Double> items; // storage for the items and their costs
private static LinkedHashMap<String, String> sales; // storage for the itema and their sale descriptions
private static LinkedHashMap<String, Integer> purchases; // storage for the items and their quantities
private static ArrayList<String> itemNames;
public static LinkedHashMap<String,Double> readItemsFromFile(String fname) {
LinkedHashMap<String,Double> result = new LinkedHashMap<String,Double>();
itemNames = new ArrayList<String>();
open up the file
for each line of the file
split it into its two parts at the tab
result.put(item name, the price you read for it)
itemNames.add(the item name you read)
close the file
Collections.sort(itemNames);
return the result

}
public static LinkedHashMap<String, String> readSalesFromFile(String fname) {
LinkedHashMap<String,String> result = new LinkedHashMap<String,String>();
open the file
for each line of the file
split it at the tab
result.put(item name, the sales description)
close the file
return the result
}
public static void presentMenuOfItems() {
for each itemName in itemNames:
print itemName along with items[itemName] and a description based on sales[itemName]
add on the "q" to quit option
}
public static void main(String[] args) {
items = readitemsFromFile("items.txt");
sales = readSalesFromFile("sales.txt");
purchases = new LinkedHashMap<String,Integer>();
present to the user the table of grocery items
do {
ask them to the choice
use the number and the itemNames to figure out the name of the item
if the purchases lhm already has that item
purchases[the item name] = purchases[the item name] + 1
else
purchases[the item name] = 1; // first time purchase of that item
} while they don't want to quit
BillProcessor.prepareBill(purchases, items, sales, itemNames);
}

sales.txt 8
1 Mountain Dew
2 Cereal bogo
0.20
0.30
3 Bread
4 Hamburgers 2.00
5 Tamales 0.80
6 Eggs
bogo
Transcribed Image Text:sales.txt 8 1 Mountain Dew 2 Cereal bogo 0.20 0.30 3 Bread 4 Hamburgers 2.00 5 Tamales 0.80 6 Eggs bogo
items.txt 3
sales.txt
1 Eggs
1.09
2 Roast Beef 3.49
3 Ground Beef 2.49
4 Milk
2.39
5 Cereal 4.19
6 Bread
1.99
7 Apples 0.99
8 Blueberries 1.29
9 Sausage 2.99
10 Mountain Dew
5.99
11 Frozen Pizza
6.59
12 Tamales 7.19
13 String Cheese
14 Hamburgers 12.99
1.29
15 Peanut Butter
3.99
illi
Transcribed Image Text:items.txt 3 sales.txt 1 Eggs 1.09 2 Roast Beef 3.49 3 Ground Beef 2.49 4 Milk 2.39 5 Cereal 4.19 6 Bread 1.99 7 Apples 0.99 8 Blueberries 1.29 9 Sausage 2.99 10 Mountain Dew 5.99 11 Frozen Pizza 6.59 12 Tamales 7.19 13 String Cheese 14 Hamburgers 12.99 1.29 15 Peanut Butter 3.99 illi
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY