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

PLEASE FORMAT NICELY IN AN EASY TO READ MANNER AND FOLLOW ALL PARAMETERS! This s

ID: 3849735 • Letter: P

Question

PLEASE FORMAT NICELY IN AN EASY TO READ MANNER AND FOLLOW ALL PARAMETERS!

This should be in java.

-Define a class named HotDogStand that has an instance variable for the hot dog stand's ID number 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.

-Have inventory control (more info below)

-The hot dog class must keep track of the total hotdogs sold since its object instantiation.

-Create a method called buy(int i) (more info below)

-Add a method that returns the number of hot dogs sold

-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 3 hot dog stands that sell a variety of hot dogs.

Inventory Control

-The hotdog stand class will have an inventory of hot dogs that the class must be able to track. The class must have methods to set, access, add to, and subtract sales from the inventory.
-A hot dog stand class constructor must set the default initial inventory to 25 hotdogs.

Buy(int i) method

-Instead of a sold method (as in the book) the hotdog class must have a buy method that has an parameter that indicates the number of dogs that wants to buy.

-The hotdog class should be intelligent enough to sell only hotdogs that are in inventory.

-If the buy is more than the inventory, the class should state the hotdogs in inventory and ask if the remaining (not 0) hotdogs in inventory is sufficient for the buyer.

-If there is a buy when there are 0 hotdogs in invventory, the class should state that it is out of hotdogs to the buyer.

-Develop a method called toString() for the hotdog stands class that displays a String object all the Hotdog stand object member values and states in a well formatted manner.

-The main class must include driver code that tests all the logic paths of the hot stand class.
Do not use JPanel or interactive prompts, unit test the hot class by coding in test scenarios in the main program which will act as a driver.

-You operate several hotdog stands. Define a class named HotDogStand that has an instance variable for the hot dog stand's ID number 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 variables. 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 the total can be tracked. Add another method that returns the number of hot dogs sold.

-Add a static variable that tracks the total number of hot dogs sold by all the stands and a static method that returns the value in this variable.

Explanation / Answer


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Sam
*/
public class HotDogStand {
    private int id;
    private int sold;
    private int inventory;
    private static int totalSold = 0;

    public HotDogStand(int id, int sold) { //constructor
        this.id = id;
        this.sold = sold;
        totalSold += sold;
        inventory = 75;
    }
    public void buy(int i) throws IOException { //sales hotdog
        if (inventory == 0) //if inventory is empty
            System.out.println("We are out of Hotdogs!");
        else if (i <= inventory) { // if buyer buys less hotdogs than inventory
            System.out.println(i + " hotdogs sold."); //print and update all variables
            inventory -= i;
            sold += i;
            totalSold += i;
        }
        else { //if the buyer wants more hotdogs than inventory
            System.out.println("We have only " + inventory + " hotdogs "
                    + "Do you want to buy " + inventory + " hotdogs? (y/n)"); //asks question
            if ((new BufferedReader(new InputStreamReader(System.in))).readLine().equalsIgnoreCase("y")) { //if user agrees
                sold += inventory;
                totalSold += inventory;
                inventory = 0;
            }
        }
    }
    public void justsold() { //sells only one hotdog if and only if the inventory is not empty
        if (inventory > 0){
            sold++;
            totalSold++;
            inventory--;
        }
    }

    public int getSold() { //getter function
        return sold;
    }

    public static int getTotalSold() { //returns total sales stats
        return totalSold;
    }

    @Override
    public String toString() { //print detail of the object
        return "HotDogStand{" + "id=" + id + ", sold=" + sold + ", inventory=" + inventory + '}';
    }
  
    public static void main(String[] args) throws IOException {
        HotDogStand h1 = new HotDogStand(123, 0);
        HotDogStand h2 = new HotDogStand(512, 10);
        System.out.println(h1.toString());
        System.out.println(h2.toString());
        System.out.println("Total sold: " + HotDogStand.getTotalSold());
      
        h1.justsold();
        h2.buy(50);
        System.out.println(h1.toString());
        System.out.println(h2.toString());
        System.out.println("Total sold: " + HotDogStand.getTotalSold());
              
        h1.buy(75);
        h2.buy(75);
        System.out.println(h1.toString());
        System.out.println(h2.toString());
        System.out.println("Total sold: " + HotDogStand.getTotalSold());
      
    }
}

Here you go champ. You have the code now. I have also commented the code where ever nesessary. Pleaase let me know if you need more help on this code. I shall be glad to help you.

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