Define a class named HotDogStand that has an instance variable for how many hot
ID: 3660202 • Letter: D
Question
Define a class named HotDogStand that has an instance variable for how many hot dogs the stand has sold that day. Create constructor that allows a user of the class to initialize the instance variable value. Include the method justSold given to you (see below) in HotDogStand will increment by one the number of hot dogs the stand sold. The idea is that this method will be invoked each time the stands sells hot dog so that you can track the total number of hot dogs sold by the stand. /* * This stand just sold some hot dogs; add this amount to the day's total * and also to the total for all hot dog stands. */ public void JustSold() { numSold++; // increment number sold at this stand } Add another method that returns the number of hot dogs solid. Write a main method to test your class with its daily sale. Display on screen total hot dogs solidExplanation / Answer
please rate - thanks
import java.util.*;
class HotDogStandTester
{public static void main(String[] args)
{int sold;
Scanner in=new Scanner (System.in);
System.out.print("How many hot dogs were sold? ");
sold=in.nextInt();
HotDogStand nathans = new HotDogStand(sold);
System.out.print("How many more are to be sold? ");
sold=in.nextInt();
for(int i=0;i<sold;i++)
nathans.justSold();
System.out.println("The stand has sold a total of "+nathans.getSold()+" hot dogs");
}
}
--------------------------
public class HotDogStand
{ private int numSold;
public HotDogStand(int s)
{numSold=s;
}
public void justSold()
{numSold++;
}
public int getSold()
{return numSold;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.