Create a method named justsold that increments the hotdogs

Assignment Help JAVA Programming
Reference no: EM13941193

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();
}}

Reference no: EM13941193

Questions Cloud

Financial accounting and management accounting : Explain financial accounting and management accounting, highlighting the differences between the two strands of accounting Explain the sources of finance available to a business owner, making distinctions between internal and external sources, shor..
Evaluate efficiecy of strategy monopolistic market structure : Identify three or more competitive strategies that Starbucks may use to maximize its profits in a monopolistic market. Evaluate the efficacy of these strategies in the monopolistic market structure
Calculate accounting rate of return on investment : Part 1: Prepare a spreadsheet using Excel or a similar program in which you compute the following for each proposed location: Accounting rate of return on investment and Payback
Create a java application that displays the product number : Create a product class that holds the item number, the name of the product, the numberof units in stock, and the price of each unit.
Create a method named justsold that increments the hotdogs : 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.
Calculate percent of sodium carbonate in impure sample : How do you calculate the moles of sulfuric acid that remained in the solution after the reaction with the carbonate? calculate the moles of sulfuric acid that reacted with the carbonate
Ethical problems common to the workplace : Focusing on social media and/or privacy research, discuss one or more ethical problems common to the workplace. Look at ethical decision making in relation to social and business outcomes.
Bunn operates a small family bakery : It has recently moved into new premises and has invested in more advanced equipment, with the aim of making the baking process more automated.
Assuming that purchasing-power parity holds : A McDonald’s Big Mac costs 2.44 yuan in China, but costs $4.20 in the United States. Assuming that purchasing-power parity (PPP) holds, how many Chinese yuan are required to purchase 1 U.S. dollar?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd