Question
I have done it half way. But when in Tester when I create new obj h2, and type system.out.println(h1.getTotalNumSold()) - the totalNumSold adds value from
I have done it half way. But when in Tester when I create new obj h2, and type system.out.println(h1.getTotalNumSold()) - the totalNumSold adds value from h2 in h1.
- HotDog Class
- Instance variables: int hotDogStandID
int numSold
- Static variable int totalNumSold=0
- Constructor
Default - hotDogStandID=-1, numSold=0,totalNumSold=totalNumSold + numSold
Fully Qualified - in addition to setting instance variables, add the numSold to the totalNumSold
Copy - in addition to setting instance variable, add the numSold to the totalNumSold
- Setter getter for all instance variables - note in the setter for numSold also update totalNumSold by the same amount
- toString
- Equals - if the hotDogStandID is the same return true
- Write method justSold - increments numSold, increments totalNumSold
2. Hot Dog tester
- Test all the above
- Print out the totalNumSold
public class HotDog {
//instance variables
private int hotDogStandID;
private int numSold;
//static varibale
public static int totalNumSold=0;
//default constructor
public HotDog() {
this.hotDogStandID=-1;
this.numSold=0;
totalNumSold=totalNumSold + numSold ;
}
//fully qualified
public HotDog(int ID, int nSold) {
this.hotDogStandID= ID;
this.numSold= nSold;
this.totalNumSold=this.totalNumSold + numSold;
}
// getters
public int getHotDogStand() {
return this.hotDogStandID;
}
public int getNumSold() {
return this.numSold;
}
public static int getTotalNumSold() {
return totalNumSold;
}
//setters
public void setHotDogStand(int ID) {
this.hotDogStandID = ID;
}
public void setNumSold(int nSold) {
this.numSold = nSold;
this.totalNumSold= this.totalNumSold + nSold;
}
//public void setTotalSold(int tSold) {
// totalNumSold = tSold;
//}
//toString
public String toString() {
return "Hot Dog Stand ID is: " + hotDogStandID + " Number Sold is: " + numSold + "Total num Sold: " + totalNumSold;
}
//equals method
public boolean equals(HotDog other) {
if(this.hotDogStandID==other.hotDogStandID)
return true;
else
return false;
}
//justSold method
public void justSold() {
numSold++;
totalNumSold++;
}
}//end class
public class HotDog_Tester {
public static void main(String [] args) {
HotDog h1 = new HotDog();
//HotDog h2 =new HotDog(10,2);
//set h1
h1.setHotDogStand(25);
h1.setNumSold(5);
System.out.println(h1.getNumSold());
System.out.println(h1.getTotalNumSold());
//System.out.println(h2.getTotalNumSold());
}//end method
}//end class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started