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

In Java All displayed prompts and results should be well formatted. The assignme

ID: 3849718 • Letter: I

Question

In Java

All displayed prompts and results should be well formatted.

The assignment is based on the following Programming Exercise in the book: Programming Projects

Chapter 5 Defining Classes II Programming Exercises
Page 339

-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.
-Create a method called 'justSold' that increments by 1 the number of hot dogs the stand has sold. This method will be invoked each time the stand sells a hot dog
-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.

1. Hot Dog Stands

This assignment requires the following enhancements: There must be at least 2 java source code files:

· HotDogStandMainClass.java
Contains the main HotDogStandMainClass.

· HotDogStandClass.java Contains the HotDogStandClass.

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.

Accounting

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

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

Hi,

Please find the program below. Program itself detailed explination is avaiable. If you have further concerns on the same, please comment.

package com.praveen.hotdog;

public class HotDogStand {

private String hotDogStandsID = ""; //Name of the HotDogStand

private static int noOfHotDogsSold = 0; //No of HotDogs Sold by specific stand

private int inventoryHotDogs = 0; //Default HotDogs count available in each stand to buyers

private static int totalHotDogsSoldByAllStands = 0; //Track all the HotDogs sold by stands

/**

* Returning the Total HotDogs sold by all Stands

* @return

*/

public static int getTotalHotDogsSoldByAllStands() {

return totalHotDogsSoldByAllStands;

}

/**

* Getting the Inventory HotDogs count wrt to each Stand, after sold to buyer

* @return

*/

public int getInventoryHotDogs() {

return inventoryHotDogs;

}

/**

* Setting the inventory count

* @param inventoryHotDogs

*/

public void setInventoryHotDogs(int inventoryHotDogs) {

this.inventoryHotDogs = inventoryHotDogs;

}

@SuppressWarnings("static-access")

public HotDogStand(String hotDogStandsID, int noOfHotDogsSold) {

super();

this.hotDogStandsID = hotDogStandsID;

this.noOfHotDogsSold = noOfHotDogsSold;

}

/**

* Track the individual HotDog Stand wise and if InventoryHotDog > 0 : sold

* the hotdog and decrement the inventory count

* else No Hotdogs avaiable to buyer

*

* @param obj

*/

private void justSold(HotDogStand obj) {

if (obj.getInventoryHotDogs() > 0) {

noOfHotDogsSold += 1;

obj.setInventoryHotDogs(obj.getInventoryHotDogs() - 1);

totalHotDogsSoldByAllStands += 1;

} else {

System.out.println("No HotDogs are avaiable to buyer from Stand Name : " + obj.hotDogStandsID);

}

}

/**

* Provide the total no of hotDogs Sold by specfic stand

* @return

*/

public int hotDogsSoldCount() {

return noOfHotDogsSold;

}

public static void main(String args[]) {

//HotDog stand _01

HotDogStand hotDogStand_01 = new HotDogStand("HOTDOGSTAND_01", 0);

hotDogStand_01.setInventoryHotDogs(25);

hotDogStand_01.justSold(hotDogStand_01);

hotDogStand_01.justSold(hotDogStand_01);

hotDogStand_01.justSold(hotDogStand_01);

System.out.println("No of HotDogs Sold by HOTDOGSTAND_01 => " + hotDogStand_01.hotDogsSoldCount() + " Total Remaining in Inventory => " + hotDogStand_01.getInventoryHotDogs());

//HotDog stand_02

HotDogStand hotDogStand_02 = new HotDogStand("HOTDOGSTAND_02", 0);

hotDogStand_02.setInventoryHotDogs(25);

hotDogStand_02.justSold(hotDogStand_02);

hotDogStand_02.justSold(hotDogStand_02);

hotDogStand_02.justSold(hotDogStand_02);

System.out.println("No of HotDogs Sold by HOTDOGSTAND_02 => " + hotDogStand_02.hotDogsSoldCount()+ " Total Remaining in Inventory => " + hotDogStand_02.getInventoryHotDogs());

//HotDog stand_03

HotDogStand hotDogStand_03 = new HotDogStand("HOTDOGSTAND_03", 0);

hotDogStand_03.setInventoryHotDogs(25);

hotDogStand_03.justSold(hotDogStand_03);

hotDogStand_03.justSold(hotDogStand_03);

hotDogStand_03.justSold(hotDogStand_03);

hotDogStand_03.justSold(hotDogStand_03);

System.out.println("No of HotDogs Sold by HOTDOGSTAND_03 => " + hotDogStand_03.hotDogsSoldCount()+ " Total Remaining in Inventory => " + hotDogStand_03.getInventoryHotDogs());

System.out.println("Total No of HptDogs Sold By All Stands => " + HotDogStand.getTotalHotDogsSoldByAllStands());

}

@Override

public String toString() {

return "HotDogStand [hotDogStandsID=" + hotDogStandsID + ", inventoryHotDogs=" + inventoryHotDogs + "]";

}

}

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