Hey can anyone help me with this Vending Machine For this pu

Hey can anyone help me with this

Vending Machine

For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price.

For this machine you can put in nickels, dimes, quarters, and dollar bills which increase the balance by .05, .1, .25 and 1.0 respectively.

If enough money is put in, it can dispense the product and return change if needed.

Data Entry:

Money:

B – Bill 1.00

Q – Quarter .25

D – Dime .10

N – Nickel .05

Data Entry:

Commands:

R – Refund – returns “balance”

P – Product – if balance is sufficient, dispenses product, reduces balance by 1.25, and if there is a remaining balance dispenses that too.

– if balance is not sufficient tells user a product can’t be dispensed

X – eXit – terminates program

Solution

ProductDispencedMachine.java

import java.util.Scanner;

public class ProductDispencedMachine {

   public static void main(String[] args) {

       // Declaring variables
       char choice;
       double balance = 0.0;
       Scanner sc = new Scanner(System.in);
       // this loop continue to execute until unser enters \'X\"
       while (true) {
           // Displaying menu
           System.out.println(\"\ Money:\");
           System.out.println(\"B - Bill\");
           System.out.println(\"Q - Quarter\");
           System.out.println(\"D - Dime\");
           System.out.println(\"N - Nickel\");
           System.out.println(\"R - Refund\");
           System.out.println(\"P - Product\");
           System.out.println(\"X - Exit\");

           // Getting the choice entered by the user.
           System.out.print(\"Enter choice :\");
           choice = sc.next(\".\").charAt(0);

           // Based on the users choice the corresponding case will get
           // executed.
           switch (choice) {
           case \'B\':
           case \'b\': {
               // Adding 1.00 to the current balance
               balance = balance + 1.00;

               // Displaying the balance after adding money
               System.out.printf(\"Amount :%.2f\", balance);
               System.out.println(\" \");
               continue;
           }
           case \'Q\':
           case \'q\': {

               // Adding 0.25 to the current balance
               balance = balance + 0.25;

               // Displaying the balance after adding money
               System.out.printf(\"Amount :%.2f\", balance);

               System.out.println(\" \");
               continue;
           }
           case \'D\':
           case \'d\': {

               // Adding 0.10 to the current balance
               balance = balance + 0.10;

               // Displaying the balance after adding money
               System.out.printf(\"Amount :%.2f\", balance);
               System.out.println(\" \");
               continue;
           }
           case \'N\':
           case \'n\': {

               // Adding 0.05 to the current balance
               balance = balance + 0.05;

               // Displaying the balance after adding money
               System.out.printf(\"Amount :%.2f\", balance);
               System.out.println(\" \");
               continue;
           }
           case \'R\':
           case \'r\': {
               // Returned money
               System.out.printf(\"Returned Amount :%.2f\", balance);
               System.out.println(\" \");
               balance = 0;
               continue;
           }
           case \'P\':
           case \'p\': {
               if (balance >= 1.25) {

                   System.out.println(\"Product Dispensed \");

                   // Subtracting 1.25 from balance
                   balance = balance - 1.25;
                   System.out.printf(\"Balance Amount Returned :%.2f\", balance);
                   System.out.println(\" \");
               } else {
                   // If the amount is less than 1.25 then ,it will display
                   // Error message
                   System.out.println(\"Product can\'t be dispensed\");
               }

               continue;
           }
           case \'X\':
           case \'x\':
               break;

           }
           break;
       }

   }

}

___________________________________________________

Output1:


Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :B
Amount :1.00

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :Q
Amount :1.25

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :N
Amount :1.30

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :D
Amount :1.40

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :P
Product Dispensed
Balance Amount Returned :0.15

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :X

________________________________________

Output2:


Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :Q
Amount :0.25

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :D
Amount :0.35

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :N
Amount :0.40

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :Q
Amount :0.65

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :N
Amount :0.70

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :Q
Amount :0.95

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :P
Product can\'t be dispensed

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :B
Amount :1.95

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :P
Product Dispensed
Balance Amount Returned :0.70

Money:
B - Bill
Q - Quarter
D - Dime
N - Nickel
R - Refund
P - Product
X - Exit
Enter choice :X

_________________________________Thank You

Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price
Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price
Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price
Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price
Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price
Hey can anyone help me with this Vending Machine For this purposes of this project, imagine a vending machine that has only one product that costs a fixed price

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site