Question: Java program via Jgrasp. The question wants me to make a candy machine. The sample is provided below along with my code that I wrote

Java program via Jgrasp. The question wants me to make a candy machine. The sample is provided below along with my code that I wrote for running this program. Please proofread my code and do all the necessary edits. Please keep the java coding within Chapter 4 of the Building Java book, don't go for advance codings.

PS Please post corrected codes with proper indentation

Thank You

Sample 1

Welcome to Computer Candy Machine!

(All candy provided is virtual.)

How much money do ya got? > $1.00

$1.0, that's all?

Well, lemme tell ya 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'll ya have? > C

Thanks for purchasing candy through us.

Please take your candy and your $0.25 change!

Sample 2

Welcome to Computer Candy Machine!

(All candy provided is virtual.)

How much money do ya got? > $0.50

$0.5, that's all?

Well, lemme tell ya 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'll ya have? > D

You're broke. Take your $0.50 and go elsewhere.

My CODE:

import java.util.*;

public class candyMachine { public static void main(String[] args) { Scanner console = new Scanner(System.in); introduction(); menu(); decider(); } public static void introduction(Scanner console) { System.out.println("Welcome to Computer Candy Machine!"); System.out.println("(All candy provided is virtual.)"); System.out.println("How much money do ya got? >"); double money = console.nextDouble(); System.out.println("$"+money+", that's all?"); } public static void menu(Scanner console) { System.out.println("A $0.65 Twix"); System.out.println("B $0.50 Chips"); System.out.println("C $0.75 Nutter Butter"); System.out.println("D $0.65 Peanut Butter Cup"); System.out.println("E $0.55 Juicy Fruit Gum"); System.out.println(); System.out.println(); System.out.println("So, What'll ya have? >"); String option = console.next(); option1 = decider(money,option); return option1; } public static void decider(double money, String option) { if (char option == 'A') { double total = (money - option); if (money >= option) { System.out.println("Thanks for purchasing candy through us."); System.out.println("Please take your candy and your $"+ total+" change!"); } else { System.out.println("You're broke. Take your $"+money+" and go elsewhere."); } } if (char option == 'B') { double total = (money - option); if (money >= option) { System.out.println("Thanks for purchasing candy through us."); System.out.println("Please take your candy and your $"+ total+" change!"); } else { System.out.println("You're broke. Take your $"+money+" and go elsewhere."); } } if (char option == 'C') { double total = (money - option); if (money >= option) { System.out.println("Thanks for purchasing candy through us."); System.out.println("Please take your candy and your $"+ total+" change!"); } else { System.out.println("You're broke. Take your $"+money+" and go elsewhere."); } } if (char option == 'D') { double total = (money - option); if (money >= option) { System.out.println("Thanks for purchasing candy through us."); System.out.println("Please take your candy and your $"+ total+" change!"); } else { System.out.println("You're broke. Take your $"+money+" and go elsewhere."); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!