Question

In: Computer Science

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

Solutions

Expert Solution

Invoice.java

import java.util.*;

public class Invoice {
    static final String endPrices = "END_PRICES";
    static final String endInvoice = "END_INVOICE";
    static final String quit = "QUIT";
    public static void main(String... args) {

        Scanner sc = new Scanner(System.in);
        //HashMap to store fruit name as key and price as value
        Map<String, Float> fruits = new HashMap<>();

        //Loop until input is not "END_PRICES"
        while (true){
            String input = sc.next();

            //Come out of loop if input is "END_PRICES"
            if(input.equals(endPrices))
                break;

            float price = Float.parseFloat(sc.next());
            //add fruit to hash map
            fruits.put(input, price);
        }

        //ArrayList to store total cost of each invoice
        List<Float> totalList = new ArrayList<>();

        Float total = 0f;
        //loop until input becomes "QUIT"
        while (true){
            String input = sc.next();

            //Break out of the loop if input is "QUIT"
            if(input.equals(quit)){
                break;
            }

            //Add total price of the invoice to array list and set total to "0f" to store total of next invoice
            if(input.equals(endInvoice)){
                totalList.add(total);
                total = 0f;
                continue;
            }

            int quantity = sc.nextInt();
            total += (fruits.get(input)*quantity);
        }

        //Iterate through all objects in the total Array List and print them
        Iterator itr = totalList.iterator();
        while (itr.hasNext()){
            System.out.printf("Total: %.2f \n", itr.next());
        }

    }
}

Sample Output:


Related Solutions

Given the following specification for a Web-based order processing system for a computer store. “A new...
Given the following specification for a Web-based order processing system for a computer store. “A new user can connect to the company’s web page and create a new customer profile by providing personal information. This information will be validated and saved in a customer information file at the company’ s server. The user is then provided with a user id and password via an email sent by the system. Using the provided password, the user can then logon to the...
Suppose that you have been given the job of providing advance transport to a new exhibition...
Suppose that you have been given the job of providing advance transport to a new exhibition hall and it is possible to use existing railway connections and bus routes. Each bus will cost $30000 and carry 40 passengers. Each railway train will cost $45000 and carry 50 passengers. A bus can make 15 trips a day and a railway train 12 trips a day. The system has a number of financial and design constraints. It must carry at least 48000...
You have been given a job analysis for a position of Welder at a factory and...
You have been given a job analysis for a position of Welder at a factory and have been asked to design a new selection instrument, a knowledge-based test. The welder job is an established position with a large number of current incumbents and a large number of unfilled positions. You need to establish the validity of the new knowledge-based test. Describe how you would examine the criterion-related validity of this test. Be as specific as possible.
You have been given the job of evaluating the following merger candidate. You have collected the...
You have been given the job of evaluating the following merger candidate. You have collected the following cash flow for the acquisition candidate for the proposed merger (in millions): Year                                                                1                              2                               3                               4                               5__ Cash flows now for canidate 90                            85                               205                            165                            180 Additional cash flows with merger 60                            90                               100                            225                            250 Total cash flows with synergy 150                            175                            305                            390                            430 Risk free rate of return                                                                                                                 3.0% Beta for this project (the company after merging)                                                        ...
You are working on a postsurgical unit and have been given an order to discharge a...
You are working on a postsurgical unit and have been given an order to discharge a 72-year-old male who has just had a total hip replacement. Per hospital policy, you obtain a set of vital signs before discharging him home and note his temperature to be 100.9˚F. Upon assessing the patient, he tells you that he feels a bit “chilled.” You notify the practitioner of the elevated temperature and the patient’s comments, but you are told to continue with the...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
Azure has a job order and the following data have been recorded on its job cost...
Azure has a job order and the following data have been recorded on its job cost sheet: Direct material                          $50,000 Direct labour hours                   1,000 Direct labour wage rate             $25 Machine hours                          750 hours Number of units completed       800 The company applies manufacturing overhead on the basis of machine hours and the predetermined overhead rate is $20 per machine hour. Management is now considering whether this job order is profitable or not and how does this job order fare compared to the industry benchmark. Required Compute...
Azure has a job order and the following data have been recorded on its job cost...
Azure has a job order and the following data have been recorded on its job cost sheet: Direct material $50,000 Direct labour hours 1,000 Direct labour wage rate $25 Machine hours 750 hours Number of units completed 800 The company applies manufacturing overhead on the basis of machine hours and the predetermined overhead rate is $20 per machine hour. Management is now considering whether this job order is profitable or not and how does this job order fare compared to...
As part of your new job responsibilities as an analyst for Lachute Lumber, you have been...
As part of your new job responsibilities as an analyst for Lachute Lumber, you have been asked to help evaluate a new project. Lachute has a market value debt-to-equity ratio of .6667. The firm's cost of equity is 15% and its pre-tax cost of debt is 4.917%. Flotation costs of debt and equity are 1.71% and 5%, respectively. The firm has a tax rate of 40%. The new project requires purchasing equipment that will cost $2,000,000 plus an additional $200,000...
Suppose you have been assigned to a new job in another nation, and that nation does...
Suppose you have been assigned to a new job in another nation, and that nation does not embrace a Biblical Worldview. What would you need to do to prepare yourself for that assignment in terms of maintaining your Biblical and ethical beliefs?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT