Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Vending Machine Program To begin, create an abstract \"Snack\" class. Then,

ID: 3693246 • Letter: J

Question

Java Vending Machine Program

To begin, create an abstract "Snack" class. Then, create two classes "Salty" and "Sweet" that inherit from the "Snack" class. These 2 classes of Snacks "Sweet" and "Salty" have 2 each... i.e. Sweet Snacks -- M&Ms, Snickers, Salty Snacks -- Popcorn, Chips. The vending machine should hold 100 of each snack.

Once you have your inheritance hierarchy defined, implement the toString method for each class. Each snack also has two additional properties: "calories" and "cost". Calories represents how many calories the snack has, and cost is a floating-point number that represents how much the snack costs to buy. Implement these properties within your hierarchy as appropriate

The program (preferably using JOptionPane as the interface) should begin with a window that asks "Do you want a snack?"... and Yes or No buttons (clickable options)... if you select "No" you get a message that says "Thank you" and then exits the program.

If you select yes, another window pops up that says "Would you like a Sweet or Salty Snack?" ... with buttons Sweet or Salty (clickable options)... If you select Sweet you get the following clickable options "M&Ms, Snickers"... or if you click Salty it will give you the options "Popcorn, Chips". When you click on one of the options, it tells you how many calories the snack has... how much it costs, and then asks you to add your money, and has an input field where you can type your amount of monry into... and then make chage (i.e. if the snack cost is .95... you type in 1.00 in the input field... the message will say "you have .05 change"..... if you don't add enough money, it will tell you... "not enough money, please add more"). Once the correct amount of money is inserted, the window will then say "Vending... please enjoy your snack", and then tell you "There are X # of snacks left in machine... would you like to restock the machine?" and give you the clickable options... Yes or No... If Yes, it says there are 100 snacks in the machine, if no... it exits the program.

Utilize good modularity and object-oriented design/programming in your solution.

Explanation / Answer

import java.util.*; public class VendingMachineAssignement { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double item1 = 1.25; double item2 = .75; double item3 = .90; double item4 = .75; double item5 = 1.50; double item6 = .75; System.out.print("Enter an item number: "); int item = keyboard.nextInt(); System.out.print("Enter the amount paid: "); double paid = keyboard.nextDouble(); if (item == 2 || item == 4 || item == 6) { if (paid >= item2) { System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item2) + ". Please come again!"); } if (paid = item1) { System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item1) + ". Please come again!"); } if (paid = item3) { System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item3) + ". Please come again!"); } if (paid = item5) { System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item5) + ". Please come again!"); } if (paid
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote