Java Assignment Question You operate several hot dog stands
Java Assignment-
Question - You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has an instance variable for the: *Name of each hot dog stand *Stand\'s ID number *How many hot dogs the stand has sold that day. Create a constructor that allows a user of the class to initialize values. Also create a method named SetJustSold()(Hint ++) that increments the number of hot dogs the stand has sold by one and should also increase the TotalSold by one. The idea is that this method will be invoked each time the stand sells a hot dog so that you can track the total number of hot dogs sold by the stand. Add another method that returns the number of hot dogs sold. Add a static variable that tracks the total number of hot dogs sold by all hot dog stands and a static method that returns the value in this variable. Create a toString() method and a copy constructor. The defined class will contain: At least two constructor methods, Getters and Setters A ‘copy’ constructor, A ‘toString’ method, An ‘equals’ method, A ‘finalize’ method, A ‘dispose’ method.
Solution
// HotDogStand.java
import java.util.Scanner;
public class HotDogStand {
// class variables
private String stand_Name; // Name of each hot dog stand
private int stand_ID; // each stand has its own ID
private int hotdog_Sold; // dogs the stand has sold that day
// number of hot dogs sold by all stands
private static int TotalSold = 0;
// Constructor
public HotDogStand(String name, int id, int sold)
{
stand_Name = name;
stand_ID = id;
hotdog_Sold = sold;
TotalSold += hotdog_Sold;
}
// static method that returns the value in TotalSold variable
public static int getTotalSold()
{
return TotalSold;
}
// accessor and mutator methods
public void justSold() {
hotdog_Sold = hotdog_Sold + 1;
TotalSold = TotalSold + 1;
}
public int gethotdogSold()
{
return hotdog_Sold;
}
public int getStandID()
{
return stand_ID;
}
public String getStandName()
{
return stand_Name;
}
@Override
public String toString()
{
return String.format(\"\ Stand name: \" + getStandName() + \"\\tStand ID: \" + getStandID() + \"\\tHot Dog sold: \" + gethotdogSold() );
}
public static void main(String[] args)
{
HotDogStand stand1 = new HotDogStand(\"Talar\",1, 31);
HotDogStand stand2 = new HotDogStand(\"Jamar\", 2, 47);
HotDogStand stand3 = new HotDogStand(\"Kalar\",3, 32);
stand1.justSold();
stand2.justSold();
stand3.justSold();
stand1.justSold();
stand1.justSold();
stand1.justSold();
stand3.justSold();
System.out.println(stand1.toString());
System.out.println(stand2.toString());
System.out.println(stand3.toString());
System.out.println(\"\ Total hotdogs sold by all the stands: \" + HotDogStand.getTotalSold());
}
}
/*
output:
Stand name: Talar Stand ID: 1 Hot Dog sold: 35
Stand name: Jamar Stand ID: 2 Hot Dog sold: 48
Stand name: Kalar Stand ID: 3 Hot Dog sold: 34
Total hotdogs sold by all the stands: 117
*/

