Question
1. Code for the DonutOrder class is given below. Complete the following: (a) Add a private static integer called numOders and give it a default
1. Code for the DonutOrder class is given below. Complete the following:
- (a) Add a private static integer called numOders and give it a default value of zero
- (b) Add a public static method called getNumOrders() that will return the content numOrders static variable
- Modify the DonutOrder constructors that takes value so that it modifies numOrders appropriately
public class DonutOrder{
private int number;
private double price;
// part (a) include the static variable below
//part (c) modify both constructors to update numOrders
public DonutOrder()
{
number = 1;
price = 0.99;
}
public DonutOrder(int amount, double cost)
{
number = amount;
price = cost;
}
public int getNumber()
{return number;}
public double getPrice()
{return price;}
public void setNumber(int num)
{number = num;}
public void setPrice(double cost)
{price = cost;}
public String toString()
{return "The donut order has " + number + "donut(s) for the price of $"+ price;}
// part (b) include the static method below
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started