Question
How can help to create this program? PartBDriver public class PartBDriver { public static void main (String[] args) { // create the first SodaMachine Output.showMessage(Creating
How can help to create this program?
PartBDriver
public class PartBDriver { public static void main (String[] args) { // create the first SodaMachine Output.showMessage("Creating default Soda Machine..."); SodaMachine sm1 = new SodaMachine(); Output.showMessage("Machine #1: " + sm1.toString()); // create the second SodaMachine Output.showMessage("Creating second Soda Machine..."); SodaMachine sm2 = new SodaMachine(1.00, 5); Output.showMessage("Machine #2: " + sm2.toString()); // manipulate the first machine Output.showMessage("Buying a soda from Machine #1..."); sm1.buySoda(); Output.showMessage("Machine #1: " + sm1.toString()); Output.showMessage("Changing price and repeating..."); sm1.setPrice(0.50); sm1.buySoda(); Output.showMessage("Machine #1: " + sm1.toString()); // manipulate the second machine Output.showMessage("Trying to buy 7 sodas from Machine #2..."); int count = 0; while (count sm2.getNumSodas()) Output.showMessage("Machine #1 has more sodas."); else Output.showMessage("Machine #2 has more sodas."); if (sm1.getPrice() == sm2.getPrice()) Output.showMessage("Machines have the same price-per-soda."); else if (sm1.getPrice() > sm2.getPrice()) Output.showMessage("Machine #1 has a higher price-per-soda."); else Output.showMessage("Machine #2 has a higher price-per-soda."); } // method main } // class PartBDriver
Purpose: The main purpose of this lab is to give you experience designing and implementing your own object classes in Java. You will write one object class for each part, and you will use the provided Java applications to test your completed object classes. Each of your object classes must be arranged in the following three sections, each marked with a comment: instance variables, constructor(s), and instance methods. Your toString methods should return a String containing all instance variables in a sentence, with any instance variables representing monetary values formatted as money formatted to two decimal places. Hints/Tips: Though the details of each class are different, the steps to take in writing your object classes are the same steps taken in Lecture 23 to write the LightSwitch class. As usual, it is a good idea to write your class one section or method at a time, testing for compilation after each. You can also write short test applications that test the completed methods before all the methods are written and ready for the final test programStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started