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

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!