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
Jlenok [28]
2 years ago
11

Write a program that uses the Purchase class in 5.13. Set the prices to the following: Oranges: 10 for $2.99 Eggs: 12 for $1.69

Apples: 3 for $1.00 Watermelons: $4.39 each Bagels: 6 for $3.50 Set the purchased quantity to the following: 2 dozen oranges, 2 dozen eggs, 20 apples, 2 watermelons, 1 dozen bagels Display the total cost of the bill
Computers and Technology
1 answer:
Xelga [282]2 years ago
5 0

Answer:

Explanation:

The following program is written in Java. Using the program code from Purchase class in 5.13 I created each one of the fruit objects. Then I set the price for each object using the setPrice method. Then I set the number of each fruit that I intended on buying with the setNumberBought method. Finally, I called each objects getTotalCost method to get the final price of each object which was all added to the totalCost instance variable. This instance variable was printed as the total cost of the bill at the end of the program. My code HIGHLIGHTED BELOW

//Entire code is in text file attached below.

//MY CODE HERE

       DecimalFormat df = new DecimalFormat("0.00");

       oranges.setPrice(10, 2.99);

       oranges.setNumberBought(2*12);

       eggs.setPrice(12, 1.69);

       eggs.setNumberBought(2*12);

       apples.setPrice(3, 1);

       apples.setNumberBought(20);

       watermelons.setPrice(1, 4.39);

       watermelons.setNumberBought(2);

       bagels.setPrice(6, 3.50);

       bagels.setNumberBought(12);

       totalCost = oranges.getTotalCost() + eggs.getTotalCost() + apples.getTotalCost() + watermelons.getTotalCost() + bagels.getTotalCost();

       System.out.println("Total Cost: $" + df.format(totalCost));

   }

}

You might be interested in
Which of these are examples of a bug?
nadya68 [22]
The answer is b and c
7 0
3 years ago
Is permanent software programmed into read-only memory.<br> Firmware<br> JavaScript<br> PHP<br> o
velikii [3]
Firmware is the software
5 0
2 years ago
IN C++
Natali [406]

Answer:

I only do Design and Technology

sorry don't understand.

4 0
3 years ago
Phân tích cạnh tranh của cocacola và pepsi
Fittoniya [83]
I don’t understand please speak English
7 0
2 years ago
How do we add questions on sam Blockly?​
Blizzard [7]

Answer:

I do not know that answer

5 0
3 years ago
Other questions:
  • Select the correct answer.
    6·1 answer
  • The document responsible for describing the type of data stored in the database is called the:
    5·1 answer
  • Which feature is an interface between the user and the file system of a computer?
    6·2 answers
  • 1.Electromagnetic waves can carry more data at higher frequencies. Why would a scientist opt to transmit data at a lower frequen
    12·1 answer
  • 1. Why do you think coding languages generally include the ability to create comments? What would those comments be used for? In
    10·1 answer
  • I need to write a really simple python program to solve this issue. I have most of the program written but, when I run the secon
    8·1 answer
  • 19. The power supply in your server has just been replaced because of power problems. Your server boots, but now there is a mess
    13·1 answer
  • (1) Output a menu of automotive services and the corresponding cost of each service. (2 pts)Ex:Davy's auto shop servicesOil chan
    9·1 answer
  • How do I get the pictures from my old Samsung phone to put on my iPhone? The Samsung is turned off. Is there a way to transfer i
    8·1 answer
  • Which of the following is the best description of an ip address?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!