Checkout
checkout
view
Your Cart Your Cart: item(s)
Add to Shopping Cart
$2.19 Instant Download
Computer Science, Software Design and Architecture
Year 2

Define a class named HotDogStand


You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand's ID number and a member 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 the number of hot dogs the stand has sold by one. The idea is that this method will be invoked each time the stand sells a hot dog so that we 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 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 three hot dog stands that each sell a variety of hot dogs.

In this exercise, you should provide implementations for the following constructor and methods:

    public HotDogStand()
    public HotDogStand(int newID, int newNumSold)
    public int getID()
    public void setID(int newID)
    public void justSold()
    public int getNumSold()
    public static int getTotalSold()

HINT:

getTotalSold() should be declared as a static method.

When a hot dog is sold, both the counter for the stand and the counter for the total number of hot dogs sold (at all stands) should be incremented.




/**
* This program defines a class for tracking hot dog sales. It tracks the
* stand's ID number, hot dogs sold at each stand, and hot dogs sold at
* all stands.
*/

public class HotDogStand {
    /**
     * Total hot dogs sold at all stands
     */
    private static int totalSold = 0;

    /**
     * Number of hot dogs sold at this stand
     */
    private int numSold = 0;

    /**
     * ID number for this stand
     */
    private int id = 0;



// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------


// --------------------------------
// --------- END USER CODE --------
// --------------------------------


    public static void main(String[] args) {
        HotDogStand s1 = new HotDogStand();
        HotDogStand s2 = new HotDogStand(2, 0);
        HotDogStand s3 = new HotDogStand(3, 0);

        s1.setID(1);

        s1.justSold();
        s2.justSold();
        s1.justSold();

        System.out.println("Stand " + s1.getID() + " sold " + s1.getNumSold());
        System.out.println("Stand " + s2.getID() + " sold " + s2.getNumSold());
        System.out.println("Stand " + s3.getID() + " sold " + s3.getNumSold());
        System.out.println("Total sold = " + HotDogStand.getTotalSold());
        System.out.println();

        s3.justSold();
        s1.justSold();

        System.out.println("Stand " + s1.getID() + " sold " + s1.getNumSold());
        System.out.println("Stand " + s2.getID() + " sold " + s2.getNumSold());
        System.out.println("Stand " + s3.getID() + " sold " + s3.getNumSold());
        System.out.println("Total sold = " + HotDogStand.getTotalSold());
        System.out.println();
    }

}

              

By OTA:  Yupei Xiong, PhD

OTA Rating:  4.8/5

Your Price:  $2.19  (original value ~$7.98)

What's included:

  • Plain text response
  • Attachment(s):
    • HotDogStand.java
$2.19 Download Add to Cart

Add to Shopping Cart
$2.19 Instant Download
Give the definition of a class named Doctor whose objects are records for a clinic’s doctors. - Give the definition of a class named Doctor whose objects are records for a clinic’s doctors. This class will be a derived class of the class SalariedEmployee given in Display 7.5. A Doctor record has the doctor’s specialty (such as "Pediatrician", "Obstetrician", "General Practitioner", and so forth; s...
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating point value. - In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating point value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The ...
Java - Write a program that calculates the average of N integers - Please see attached file. When my exception is encountered I can't get the catch to operate correctly.

Page generated in 0.0143 seconds

About Us ·  Contact Us ·  Samples ·  Solutions ·  Legal Terms and Conditions ·  Privacy Policy

©2008 SolutionLibrary.com

Search for Solutions About Us Samples