1. Create a new project in BlueJ. 2. Create a class named LemonadeStand. 3. Create all methods and fields as defined in the UML diagram shown at the end of this document. create the following elds in your LemonadeStand class: lemons the number of lemons you have to make lemonade. gallonsOfWater the number of gallons of water you have to make lemonade. cupsOfSugar the number of cups of sugar you have to make lemonade. emptyGlasses the number of empty glasses you have. price the price you are charging for one glass of lemonade. glassesOfLemonade the number of full glasses of lemonade that are ready to sell. income the amount of income earned since starting to sell lemonade. 7. Make your accessors return eld values. Make your mutators set the eld values from their parameter variables. 8. Make the no-arg constructor set all elds to 0. 9. Make the constructor with parameter variables do the following: set each eld using its corresponding parameter variable. set glassesOfLemonade to 0. set income to 0. (Hint: How many parameter variables does your constructor need?) 10. Modify makeLemonade to make one batch of lemonade according to the following recipe: Squeeze 6 lemons (decrease lemons) Mix with 1 gallon of water (decrease gallonsOfWater) Stir in 1 cup of sugar (decrease cupsOfSugar) Makes 8 glasses of lemonade (decrease emptyGlasses, increase glassesOfLemonade) Return the number of glasses made. (Simply return 0 for now. Don't worry about running out of ingredients for now.) 11. Make sellLemonade do the following: Sell 1 glass of lemonade (decrease glassesOfLemonade by 1) Take in money (increase income by the price of 1 glass of lemonade) Return the number of glasses sold (Simply return 0 for now. Don't worry about running out of glasses of lemonade for now.) 12. Modify sellMoreLemonade: Don't worry about this method for now; it is completed in later activities. 13. Now, how can you test your lemonade stand? What would happen if a main method containing the following code were executed? LemonadeStand lemonadeStand = new LemonadeStand(15, 3, 4, 20, 1.5); What does the 15 mean? What about 3? 4? 20? 1.5? If you followed the above code with the following, what would be printed? lemonadeStand.makeLemonade(); System.out.println(lemonadeStand.getLemons()); Try it. That is, create a main method containing the above code and run it. Then print gallonsOfWater, cupsOfSugar, and glassesOfLemonade. 15. Put three calls to lemonadeStand.sellLemonade(); in your main method below the code you added above. What elds do you expect to change? Did they change correctly? Use println to make sure the values are exactly what you expected.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
1. Create a new project in BlueJ.
2. Create a class named LemonadeStand.
3. Create all methods and fields as defined in the UML diagram shown at the end of this document.
create the following elds in your LemonadeStand class:
lemons the number of lemons you have to make lemonade.
gallonsOfWater the number of gallons of water you have to make lemonade.
cupsOfSugar the number of cups of sugar you have to make lemonade.
emptyGlasses the number of empty glasses you have.
price the price you are charging for one glass of lemonade.
glassesOfLemonade the number of full glasses of lemonade that are ready to sell.
income the amount of income earned since starting to sell lemonade.
7. Make your accessors return eld values. Make your mutators set the eld values from their parameter
variables.
8. Make the no-arg constructor set all elds to 0.
9. Make the constructor with parameter variables do the following:
set each eld using its corresponding parameter variable.
set glassesOfLemonade to 0.
set income to 0.
(Hint: How many parameter variables does your constructor need?)
10. Modify makeLemonade to make one batch of lemonade according to the following recipe:
Squeeze 6 lemons (decrease lemons)
Mix with 1 gallon of water (decrease gallonsOfWater)
Stir in 1 cup of sugar (decrease cupsOfSugar)
Makes 8 glasses of lemonade (decrease emptyGlasses, increase glassesOfLemonade)
Return the number of glasses made. (Simply return 0 for now. Don't worry about running out of
ingredients for now.)
11. Make sellLemonade do the following:
Sell 1 glass of lemonade (decrease glassesOfLemonade by 1)
Take in money (increase income by the price of 1 glass of lemonade)
Return the number of glasses sold (Simply return 0 for now. Don't worry about running out of
glasses of lemonade for now.)
12. Modify sellMoreLemonade: Don't worry about this method for now; it is completed in later activities.
13. Now, how can you test your lemonade stand? What would happen if a main method containing the
following code were executed?
LemonadeStand lemonadeStand = new LemonadeStand(15, 3, 4, 20, 1.5);
What does the 15 mean? What about 3? 4? 20? 1.5?
If you followed the above code with the following, what would be printed?
lemonadeStand.makeLemonade();
System.out.println(lemonadeStand.getLemons());
Try it. That is, create a main method containing the above code and run it. Then print gallonsOfWater,
cupsOfSugar, and glassesOfLemonade.
15. Put three calls to
lemonadeStand.sellLemonade();
in your main method below the code you added above. What elds do you expect to change? Did they
change correctly? Use println to make sure the values are exactly what you expected.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps