Question

In java please: You have been given the job of creating a new order processing system...

In java please:

  1. You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing information for the various delicious varieties of fruit stocked by YFC, and then processes invoices from customers, determining the total amount for each invoice based on the type and quantity of fruit for each line item in the invoice. The program input starts with the pricing information. Each fruit price (single quantity) is specified on a single line, with the fruit name followed by the price. You can assume that each fruit name is a single word consisting of alphabetic characters (A–Z and a–z). You can also assume that prices will have exactly two decimal places after the decimal point. Fruit names and prices are separated by a single space character. The list of fruit prices is terminated by a single line consisting of the text END_PRICES. After the fruit prices, there will be one or more invoices. Each invoice consists of a series of line items. A line item is a fruit name followed by an integer quantity, with the fruit name and quantity separated by a single space. You can assume that no line item will specify a fruit name that is not specified in the fruit prices. Each invoice is terminated by a line consisting of the text END_INVOICE. As a special case, if a line with the text QUIT appears instead of the beginning of an invoice, the program should exit immediately. The overall input will always be terminated by a QUIT line. (5 points)

Example input:

orange 0.80

pomegranate 2.50

plum 1.20

peach 1.00

persimmon 1.75

lime 0.60

END_PRICES

persimmon 2

orange 3

peach 1

plum 10

pomegranate 5

END_INVOICE

peach 11

plum 5

orange 1

lime 9

END_INVOICE

QUIT

For each invoice, the program should print a single line of the form Total: X.YY where X.YY is the total cost of the invoice, which is the sum of the costs of all of the line items in the invoice. The cost should be printed with exactly two digits after the decimal point.

Example output (corresponding to the input shown above):

Total: 31.40

Total: 23.20

Homework Answers

Answer #1
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderProcessingSystem {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Map<String, Double> prices = new HashMap<String, Double>();
        String line;
        List<Double> totals = new ArrayList<Double>();
        while (!(line = br.readLine()).equals("END_PRICES")) {
            String words[] = line.split(" ");
            prices.put(words[0], Double.parseDouble(words[1]));
        }
        double total = 0;
        while (!(line = br.readLine()).equals("QUIT")) {
            if (line.equals("END_INVOICE")) {
                totals.add(total);
                total = 0;
                continue;
            }
            String words[] = line.split(" ");
            total += prices.get(words[0]) * Integer.parseInt(words[1]);
        }
        for (int i = 0; i < totals.size(); i++) {
            System.out.println("Total: " + totals.get(i));
        }
        br.close();
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with...
1. Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with the generic type passed to the class. 2. Create a constructor that populate an array list and the LinkedList filled with the generic type through inserting new elements into the specified location index-i in the list. 3. You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing information for the various delicious...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
What role could the governance of ethics have played if it had been in existence in...
What role could the governance of ethics have played if it had been in existence in the organization? Assess the leadership of Enron from an ethical perspective. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among the top Fortune 500 companies, collapsed in 2001 under a mountain of debt...
Discuss how the respective organizations’ relations with stakeholders could have potentially been affected by the events...
Discuss how the respective organizations’ relations with stakeholders could have potentially been affected by the events that took place at Enron and how the situation could have been dealt with differently to prevent further damage? THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among the top Fortune 500 companies,...