Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. HotDog Class
  2. Instance variables: int hotDogStandID

int numSold

  1. Static variable int totalNumSold=0
  2. 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

  1. Setter getter for all instance variables - note in the setter for numSold also update totalNumSold by the same amount
  2. toString
  3. Equals - if the hotDogStandID is the same return true
  4. Write method justSold - increments numSold, increments totalNumSold

2. Hot Dog tester

  1. Test all the above
  2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Evaluate using Pascal's Triangle. 1. 6C3 2. 4C2 3. 5 1 4. 7 4

Answered: 1 week ago