Question: Write a program that uses the Purchase class in Listing 5.13 to set the following prices: Oranges: 10 for $2.99 Eggs: 12 for $1.69 Apples:

Write a program that uses the Purchase class in Listing 5.13 to set the following prices:

Oranges: 10 for $2.99

Eggs: 12 for $1.69

Apples: 3 for $1.00

Watermelons: $4.39 each

Bagels: 6 for $3.50

Then calculate the cost of each of the following five items and the total bill:

2 dozen oranges

3 dozen eggs

20 apples

2 watermelons

1 dozen bagels


Listing 5.13

import java.util.Scanner; /** Class for the purchase of one kind of item, such as 3 oranges. Prices are set supermarket style, such as 5 for $1.25. */ public olass Purchase private String nam private int groupCount; e; //Part of a price, like the 2 in //2 for $1.99. //Part ofimport java.util.Scanner; /** Class for the purchase of one kind of item,such as 3 oranges. Prices are set supermarket style, such as 5

import java.util.Scanner; /** Class for the purchase of one kind of item, such as 3 oranges. Prices are set supermarket style, such as 5 for $1.25. */ public olass Purchase private String nam private int groupCount; e; //Part of a price, like the 2 in //2 for $1.99. //Part of a price, like the $1.99 // in 2 for $1.99. //Number of items bought. private double groupPrice; private int numberBought; public void setName (String newName) = newName; name /** Sets price to count pieces for $costForCount.

Step by Step Solution

3.35 Rating (173 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public class Purchase private String name private int groupCountPart of price like the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java An Introduction to Problem Solving and Progra Questions!