Chuck owns several pizza stands distributed throughout town. You are the java ex
ID: 3637624 • Letter: C
Question
Chuck owns several pizza stands distributed throughout town. You are the java expert who will help Chuck keep track of the number of pizzas sold by the stand as well as the total number of pizzas sold in all the stands. For this, define a class named PizzaStand that has an instance variable for the Pizza Stand’s ID number and an instance variable for how many pizzas sold in that stand that day. Add a static variable that tracks the total number of pizzas sold by all the stands. Add another static variable that specifies the cost per pizza.Add the following methods:
A constructor that sets the ID number to some value and the number of pizzas sold by that stand to 0.
A method named justSold that increments the number of pizzas sold by that stand by 1.
Another method to return the number of pizzas sold by that stand.
A static method to set the cost per pizza.
A static method that returns the total number of pizzas sold by all stands.
A static method to return the total sales.
Test the class with at least five pizza stands that each sell a number of pizzas during the day.
A sample screen dialog is given below. The cost of the pizza is set to $5.00.
Pizza Sales:
1 2 (means that Pizza Stand 1 sold 2 pizzas)
2 1
3 1
4 1
5 1
Total pizzas sold: 6
Total sales: 30.0
Process completed.
Explanation / Answer
public class Pizzastand { int Idnumber; int pizzasold; static int totalsold = 0; static pizzacost; void Pizzastand(int Id) { pizzasold = 0; Idnumber = Id; } void justsold() { pizzasold++; totalsold++; } int pizza_sold() { return pizzasold; } static void setcost(float cost) { pizzacost = cost; } static int total_sold() { return totalsold; } static float total_sales() { return total*pizzacost; } } public class Demo { public static void main(String args[]) { for(int i=1;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.