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
Difference between if then and if then else statement ​
Troyanec [42]

Answer:

<em>if..then statement is used to make a decision when there is only two options. </em>

<em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em> </em><em>&</em>

<em>you have to write a program that have to choose from three options then we use if..then..else statement.</em>

<h3>I HOPE THIS WILL HELP YOU IF NOT THEN SORRY</h3>

HAVE A GREAT DAY :)

6 0
2 years ago
Java-Script Concept quiz:
In-s [12.5K]

Answer:

Explanation:

1) the versions of JavaScript that are fully supported by all modern browsers ( Except internet explorer 9) are:

C. ECMAScript 3, ECMAScript 5

2) JavaScript is used to implement complex features on a_____

A. web page

3) computer programming tools that are used to store data are called____

C. variables

4) var name = Scott; is the code to create a ____ called "Scott"

D. None of the above

Scott is a variable

5) the key difference between "var" and "let" variables is that____

D. None of the above  

let is used to redefine a variable by using var to redefine may cause problems

6) Hoisting in JavaScript is the process whereby declarations get moved to the____

C. top

7) Im JavaScript, "/ /" is used to code____

A. comments

8) ______ data types have two potential values - true and false.

D. None of the above

Boolean is the data type and null is always false

9) Using ____ gives coders the ability to query data set data to create blueprints.

C. consoles

The Console object provides access to the browser's debugging console.

5 0
3 years ago
Computers are often referred to as _____.
GalinKa [24]
Smart machines I'm pretty sure
4 0
2 years ago
The central processing unit (CPU) processes the data in a computer systenpical data processing includes:
spin [16.1K]
Permoryin to, tho e k k j d
5 0
3 years ago
What is a Forloop and what is it used for?
anastassius [24]
It is used to repeat any block of code multiple times (iteration)
6 0
3 years ago
Read 2 more answers
Other questions:
  • Your company is developing a new marketing campaign and wants to know which customers have never placed an order. You will need
    10·1 answer
  • If your vehicle catches fire while you are driving, you should:
    5·2 answers
  • Discuss why mtv initially had a difficulty securing enough ads
    10·1 answer
  • Write a program "addnumbers.c" where it takes as many arguments as the user includes as command line arguments and calculates th
    11·1 answer
  • Write a Comparator that compares String objects by the number of words they contain. Consider any nonwhitespace string of charac
    15·1 answer
  • Write a C++ program that would take 10 integers and outputs mean, median, and range. Create at least three functions: one for so
    7·1 answer
  • Which of these organs is not found in the excretory system
    7·2 answers
  • How to fix a light blub
    11·2 answers
  • Project manager Kevin has to create a project team organizational chart. Which activity should he perform before creating this c
    9·1 answer
  • This provides an easy method for workers to use their computers. FAT FAT RAM RAM DOS DOS GUI
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!