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: 3631024 • Letter: Y

Question

You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand's ID number and a member variable for how many hot dogs the stand has sold that day. Create a constructor that allows a user of the class to initialize both values.
Also create a method named justSold that increments the number of hot dogs the stand has sold by one. The idea is that this method will be invoked each time the stand sells a hot dog so that we can track the total number of hot dogs sold by the stand. Add another method that returns the number of hot dogs sold.

Finally, add a static variable that tracks the total number of hotdogs sold by all hot dog stands and a static method that returns the value in this variable.

Write a main method to test your class with at least three hot dog stands that each sell a variety of hot dogs.

In this CodeMate exercise, you should provide implementations for the following constructor and methods:

public HotDogStand()
public HotDogStand(int newID, int newNumSold)
public int getID()
public void setID(int newID)
public void justSold()
public int getNumSold()
public static int getTotalSold()

Solution thus far

public class HotDogStand {
/**
* Total hot dogs sold at all stands
*/
private static int totalSold = 0;

/**
* Number of hot dogs sold at this stand
*/
private int numSold = 0;

/**
* ID number for this stand
*/
private int id = 0;

Explanation / Answer

Here is a solution to that problem, these two classes should cover it for you. Your hot dog stand class will look like this: --------------------------------------------------------------- public class HotDogStand { /** * Total hot dogs sold at all stands */ private static int totalSold; /** * Number of hot dogs sold at this stand */ private int numSold; /** * ID number for this stand */ private int id; public HotDogStand() { numSold = 0; id = 0; } public HotDogStand(int newID, int newNumSold) { id = newID; numSold = newNumSold; } public int getID() { return id; } public void setID(int newID) { id = newID; } public void justSold() { numSold++; totalSold++; } public int getNumSold() { return numSold; } public static int getTotalSold() { return totalSold; } } --------------------------------------------------------------- Your main class to test this will look something like this --------------------------------------------------------------- public class TestHotDogStands { public static void main(String[] args) { //Create the hot dog stands HotDogStand stand1 = new HotDogStand(1,0); HotDogStand stand2 = new HotDogStand(2,0); HotDogStand stand3 = new HotDogStand(); stand3.setID(3); //Stands sell a various number of hot dogs. stand1.justSold(); stand1.justSold(); stand1.justSold(); stand2.justSold(); stand2.justSold(); stand2.justSold(); stand2.justSold(); stand2.justSold(); stand3.justSold(); //Print out how much each stand did, along with its id. System.out.println("Stand "+stand1.getID()+" sold "+stand1.getNumSold()+" hot dogs."); System.out.println("Stand "+stand2.getID()+" sold "+stand2.getNumSold()+" hot dogs."); System.out.println("Stand "+stand3.getID()+" sold "+stand3.getNumSold()+" hot dogs."); System.out.println("Total that makes "+HotDogStand.totalSold+" hot dogs"); } }

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