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

Problem: Complete Programming Project 1. The defined class will contain: · At le

ID: 3929677 • Letter: P

Question

Problem: Complete Programming Project 1. The defined class will contain:

· At least two constructor methods, · Getters and Setters · A ‘copy’ constructor, · A ‘toString’ method, · An ‘equals’ method, · A ‘finalize’ method, · A ‘dispose’ method.

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

named

HotDogStand

that has an instance variable for the hot dog stand’s ID num-

ber and an instance 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 by one the number of hot

dogs the stand has sold. 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.

Finally, 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.

Write a main method to test your class with at least three hot dog stands that each

sell a variety of hot dogs.

Explanation / Answer

Hi, Please find my implementation

Please let me know in case of any issue.

public class HotDogStand {

  

   // instance variables

   private int id;

   private int soldHotDog;

  

   // static variable : holds total number of sold hot dogs

   private static int totalSold = 0;// initializingwith zero

  

   // constructor

   public HotDogStand(int id, int soldHotDog){

       this.id = id;

       //initializing with zero

       this.soldHotDog = soldHotDog;

      

       // also adding in totalSold

       totalSold = totalSold+ soldHotDog;

   }

   // getters and setters

   public int getId() {

       return id;

   }

   public void setId(int id) {

       this.id = id;

   }

   public int getSoldHotDog() {

       return soldHotDog;

   }

   public static int getTotalSold() {

       return totalSold;

   }

  

   // justSold metho

   public void justSold(){

       //increasing soldHotDog

       soldHotDog++;

       // also increasing totalSold

       totalSold++;

   }

  

   @Override

   public String toString() {

       return "ID: "+id+", Sold Hot Dog: "+soldHotDog;

   }

  

   @Override

   public boolean equals(Object obj) {

       if(obj instanceof HotDogStand){

           HotDogStand h = (HotDogStand)obj;

           if(h.id == id)

               return true;

       }

       return false;

   }

  

   // main method

   public static void main(String[] args) {

      

       // creating an Objet og HotDogStand

       HotDogStand stand1 = new HotDogStand(1, 0);

      

       // calling justSold

       stand1.justSold();

       stand1.justSold();

      

       System.out.println("Stand 1 sold: "+stand1.getSoldHotDog());

       System.out.println("Total All stand sold: "+HotDogStand.getTotalSold());

      

       // creating other srand

       HotDogStand stand2 = new HotDogStand(1, 0);

      

       // calling justSold

       stand2.justSold();

       stand2.justSold();

      

       System.out.println("Stand 2 sold: "+stand2.getSoldHotDog());

       System.out.println("Total All stand sold: "+HotDogStand.getTotalSold());

   }

  

}

/*

Sample Run:

Stand 1 sold: 2

Total All stand sold: 2

Stand 2 sold: 2

Total All stand sold: 4

*/

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