Question: Need help with my JAVA homework, please read carefully about what the question ask and do it exactly the question want. Thank you. Exercise 1

Need help with my JAVA homework, please read carefully about what the question ask and do it exactly the question want. Thank you.

Exercise 1

Sarah owns several ice-cream trucks in Toronto. You will help Sarah track the number of ice-creams sold by each of the trucks and the total number of ice-creams sold by all the trucks in the city. For this, define a class named IceCreamTruck. Each IceCreamTruck has a truckID (an instance variable) and an instance variable for ice-creams sold that day by that truck. IceCreamTruck also has two static variables. One static variable tracks the total number of ice-creams sold by all the trucks. The other static variable specifies the price of ice-cream, which Sarah will only update once per year.

Add the following methods:

A constructor that sets the truckID number to some value and the number of ice-creams sold by that cart to 0.

An instance method named sale that increments the number of ice-creams sold by that truck by 1.

A toString method that returns the number of ice-creams sold by the truck, that truck's total sales, and labels this using the trucks ID number.

A static method to set the cost per ice-cream.

A static method that returns the total number of ice-creams sold by all the trucks.

A static method that returns the average number of ice-creams sold by all the trucks.

A static method to return the revenue (total value of all sales) from all the trucks.

Test the class with at least five ice-cream trucks that each sells a different number of ice-creams during the day.

A sample screen dialog output is given below - your output does not have to match exactly. The cost of one ice-cream is set to $2.00 in this example.

Ice-cream Sales by Truck:

Ice-creams sold by truck1: 2 Total Sales for truck1: $4.00

Ice-creams sold by truck2: 1 Total Sales for truck2: $2.00

Ice-creams sold by truck3: 1 Total Sales for truck3: $2.00

Ice-creams sold by truck4: 1 Total Sales for truck4: $2.00

Ice-creams sold by truck5: 1 Total Sales for truck5: $2.00

Total Ice-cream sold by all trucks: 6

Total sales: $12.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!