SP20 BSE 025 Lab4 Assignments
SP20 BSE 025 Lab4 Assignments
SP20 BSE 025 Lab4 Assignments
Lab 4
Home Activities:
Assignment 1:
Suppose you operate several hot dog stands distributed throughout town. Define an
Encapsulated 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. 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 that you can track the total number of hot dogs
sold by the stand.
Write a main method to test your class with at least three hot dog stands that each
sell a variety of hot dogs. Use get function to display the hot dogs sold for each
object.
Ans: Solution:
package lab_4;
public HotDogStand()
{
standsID = 0;
hotDogsSold = 0;
}
/**
*
* @author Daniyal
*/
public class Runner {
public static void main(String[]args) {
HotDogStand dog1 = new HotDogStand(1111, 20);
HotDogStand dog2 = new HotDogStand(2222, 0);
HotDogStand dog3 = new HotDogStand(3333, 10);
dog1.justSold();
dog1.justSold();
dog1.justSold();
dog2.justSold();
dog2.justSold();
dog2.justSold();
dog2.justSold();
dog2.justSold();
dog3.justSold();
dog3.justSold();
System.out.println("\nTotal number of hot dogs sold by all hot dog stands: "
+ dog1.getTotalHotDogsSold());
}
}
Repository Link:
https://github.com/1234166/SP20-BSE-025/tree/main/Lab4%20OOP
Output: