Question: Java question. Can someone write this code? Write a class definition for a class named CandyMachine that models a candy machine. You should break this
Java question. Can someone write this code?
Write a class definition for a class named CandyMachine that models a candy machine.
You should break this problem down into multiple methods so that you practice returning information from a method and passing information to a method.
Specifically, you should have a method for each of the following in addition to the main:
a method to print the introductory text
a method that prompts and returns the amount of money that the user has entered
a method that displays all the options in the candy machine
a method that prompts for the chosen candy and returns the cost of the candy chosen
a method that takes the amount of money the user has and the cost of the candy chosen, printing to the screen that the candy is dispensed (or not) and the amount of change given (or money that is required)
Remember that your main should read like an outline to the program (meaning it should primarily being calling other methods)
here are the Example Outputs:
Welcome to My's Computer Candy Machine! (All candy provided is virtual.) How much money do you have? > $1.00 $1.00, that's all? Well, let me tell you what we got here. A $0.65 Twix B $0.50 Chips C $0.75 Nutter Butter D $0.65 Peanut Butter Cup E $0.55 Juicy Fruit Gum So, What do you want? > C Thanks for purchasing candy through us. Please take your candy and your $0.25 change!
or:
Welcome to My's Computer Candy Machine! (All candy provided is virtual.) How much money do you have? > .50 $0.50, that's all? Well, let me tell you what we got here. A $0.65 Twix B $0.50 Chips C $0.75 Nutter Butter D $0.65 Peanut Butter Cup E $0.55 Juicy Fruit Gum So, What do you want? > D You are short $0.15, you are unable to purchase your snack
please help me
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
