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

  Invoice application that validates the data

Code to the Invoice application that validates the data the user enters. That includes exception handling code as well as specific data validation methods

  Add a button that will read the text fields

Create a GUI with two text fields for inputting the dimensions of a rectangle. Identify these two text fields as Length and Width with labels. Add a button that will read the text fields and cause the GUI to display the area and perimeter of the r..

  Convert the while loop

Convert the while loop in the following code segment to a do-while loop

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Concepts of interfaces and inheritance

In this assignment we will work with the concepts of interfaces and inheritance. We will make use of a extends to create an inheritance hierarchy, and use implements to implement an interface that allows properties to be added to objects at run-ti..

  Design and implement an applet called circles

Design and implement an applet called Circles that draws 50 circles of random diameter in random locations. If the diameter of a circle is less than a certain value, the circle is ?lled with the color yellow.

  Role of object oriented programming in modern programming

the role of Object Oriented programming in modern programming solutions

  What is the purpose of the pivot value in quicksort

What is the purpose of the pivot value in quicksort and How did we first select it in the text, and what is wrong with that approach for choosing a pivot value?

  Consider the game matrix

Consider the following game in matrix form with two players. Payoffs for the row player Izzy are indicated first in each cell, and payoffs for the column player Jack are second.

  Write a java statement to create an arraylist

Write a java statement to create an ArrayList called list to hold 25 integers - What is the type of the ArrayList defined in question number 1.

  Create an array to hold four account objects

Write Mybank class in Mybank.java. Create an array to hold four Account objects. For each account, randomly set the balance in the range of $0-$1000.00; print out the balance of each account

  How are servlets and jsps deployed inside weblogic

How are Servlets and JSP's deployed inside WebLogic? In a Weblogic CMP EJB, how to obtain the maximum value in the specified database column? In WLQL is there something similar to MAX() function in SQL?

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