1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lelu [443]
3 years ago
8

You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing in

formation 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)
Computers and Technology
1 answer:
Dmitriy789 [7]3 years ago
7 0

Answer:

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);

<em>        //HashMap to store fruit name as key and price as value </em>

       Map<String, Float> fruits = new HashMap<>();

<em>        //Loop until input is not "END_PRICES" </em>

       while (true){

           String input = sc.next();

<em>            //Come out of loop if input is "END_PRICES" </em>

           if(input.equals(endPrices))

               break;

           float price = Float.parseFloat(sc.next());

<em>            //add fruit to hash map </em>

           fruits.put(input, price);

       }

<em>        //ArrayList to store total cost of each invoice </em>

       List<Float> totalList = new ArrayList<>();

       Float total = 0f;

<em>        //loop until input becomes "QUIT" </em>

       while (true){

           String input = sc.next();

<em>            //Break out of the loop if input is "QUIT" </em>

           if(input.equals(quit)){

               break;

           }

<em>            //Add total price of the invoice to array list and set total to "0f" to store total of next invoice </em>

           if(input.equals(endInvoice)){

               totalList.add(total);

               total = 0f;

               continue;

           }

           int quantity = sc.nextInt();

           total += (fruits.get(input)*quantity);

       }

<em>        //Iterate through all objects in the total Array List and print them </em>

       Iterator itr = totalList.iterator();

       while (itr.hasNext()){

           System.out.printf("Total: %.2f \n", itr.next());

       }

   }

}

You might be interested in
What is a distinguishing feature of 5G mm Wave?
RoseWind [281]

Answer: 5G high bands (mmWave, also referred to as FR2) are found in the range of 24GHz to 40GHz. They deliver large quantities of spectrum and capacity over the shortest distances

4 0
2 years ago
Polymorphism means ______________.
Westkost [7]

Answer:

Polymorphism means that a variable of supertype can refer to a subtype object.

Explanation:

For example, in Python programming language, a function that accepts an iterable object uses the concept of polymorphism because that function can accept strings, lists, tuples as arguments.

5 0
3 years ago
Read 2 more answers
The Mohs scale is used to express which mineral property?
olchik [2.2K]
Its answer is c. hardness

5 0
2 years ago
Define a pointer variable named daco that can be used for objects of the class Banana.
ozzi

Answer:

c)Banana * daco;

Explanation:

To declare an variable pointer we use * symbol after writing it's type.For example int *.Then we write the name of the variable since the name of the variable is daco.The class is a user defined data type so instead of writing any data type we will write class name then the * then name of the variable.

Banana * daco; which matches the option c Banana* daco;

4 0
3 years ago
Read 2 more answers
A(n) _____ is a Web address that specifies the exact location of a Web page using letters and words
Ahat [919]
A Uniform Resource Locator (URL)
5 0
2 years ago
Other questions:
  • What is ASP.NET ?why is it important?
    6·1 answer
  • ________ is used to store programs and instructions that are automatically loaded when the computer is turned on.
    14·1 answer
  • A security administrator wants to empty the DNS cache after a suspected attack that may have corrupted the DNS server. The serve
    9·2 answers
  • What can I do if my mouse on my laptop keeps freezing on me for 5 minutes
    11·1 answer
  • The head of small organization wants to install a network so that all the employees of different department can share various re
    14·1 answer
  • Which of the following is a table which can be rearranged to analyze data in a variety of ways?
    13·1 answer
  • What is responsible for recording an image of an object with camera <br> Pls I neeed it right know
    8·1 answer
  • Write a program that computes how much each person in a group needs to pay (after tax and tip) when splitting the bill equally.
    5·1 answer
  • Given three packets of size 2,500 Bytes (caution this is Bytes not bits) each are ready inside computer 1 to be transmitted onto
    14·1 answer
  • 1.Which of the serves as the basis for determining whether an object has moved or not?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!