Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You operate several hot dog stands distributed throughout town. Define a class n

ID: 3624473 • Letter: Y

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.

Write teh main method to test your class. The main method is in a separate class from HotDogStand().

1. You should create three hot dog stands with name, ID number and number hotdogs sold.
2. Uses the toString() to print out all three hotdog stands.
3. Print out total sold for all stands.
4. Initialize SetJustSold(), for each stand. This will add one hot dog sold to each stand and to total sold.
5. Print out results, call the getName() to print out name, call the getID() to print out ID number and getNumberSold() to display number sold for all stands.
6. Print out total sold for all stands.
7. Use the copy constructor to create stand number four with the values of stand one.

Explanation / Answer

public class HotDogStand
{
// 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.
private static int totalSold = 0;

public static int getTotalSold()
{
return totalSold;
}

// *Name of each hot dog stand
private String name;
// *Stand's ID number
private int id;
// *How many hot dogs the stand has sold that day.
private int numSold;

// Create a constructor that allows a user of the class to initialize values.
public HotDogStand(String name, int id)
{
this.name = name;
this.id = id;
}

//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.
public void setJustSold()
{
numSold++;
totalSold++;
}

// Add another method that returns the number of hot dogs sold.
public int getNumSoldToday()
{
return numSold;
}


public int getID()
{
return id;
}


public int getName()
{
return name;
}


// Create a toString() method and a copy constructor.
public String toString()
{
return name+" ("+id+") - "+numSold;
}

public HotDogStand(HotDogStand rhs)
{
id = rhs.id;
name = ""+rhs.name;
numSold = rhs.numSold;
}
}


public class Test
{
// Write the main method to test your class. The main method is in a separate class from HotDogStand().
public static void main(String[] args)
{
// 1. You should create three hot dog stands with name, ID number and number hotdogs sold.
HotDogStand one = new HotDogStand("one", 1);
HotDogStand two = new HotDogStand("two", 2);
HotDogStand three = new HotDogStand("three", 3);
// 2. Uses the toString() to print out all three hotdog stands.
System.out.println(one);
System.out.println(two);
System.out.println(three);
// 3. Print out total sold for all stands.
System.out.println("Total: "+HotDogStand.getTotalSold());
// 4. Initialize SetJustSold(), for each stand. This will add one hot dog sold to each stand and to total sold.
one.setJustSold();
two.setJustSold();
three.setJustSold();
// 5. Print out results, call the getName() to print out name, call the getID() to print out ID number and getNumberSold() to display number sold for all stands.
System.out.println("Name ID Number Sold");
System.out.println("________________________________");
System.out.println(one.getName()+" "+one.getID()+" "+one.getNumSoldToday());
System.out.println(two.getName()+" "+two.getID()+" "+two.getNumSoldToday());
System.out.println(three.getName()+" "+three.getID()+" "+three.getNumSoldToday()+" ");
// 6. Print out total sold for all stands.
System.out.println("Total: "+HotDogStand.getTotalSold());
// 7. Use the copy constructor to create stand number four with the values of stand one.
HotDogStand four = new HotDogStand(one);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote