Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Restaruant{
- static int budget=100;
- static Scanner sc=new Scanner(System.in);
- public static int Menu(){
- System.out.println("1 - View Item menu");
- System.out.println("2 – Pay total due");
- System.out.println("3 – Add $5 in credit");
- System.out.println("4 – Clear order");
- int f=sc.nextInt();
- if(f==-1||(f>=1&&f<=4)){
- return f;
- }else{
- System.out.println("Please enter a valid option!");
- Menu();
- }
- return 0;
- }
- public static double ViewMenu(double total){
- int op;
- System.out.println("1) Toaster: $19.99\n(2) Coffee maker: $29.49\n(3) Waffle maker: $15.79\n(4) Blender: $24.99\n(5) Kettle: $$24.99\n(6) Go to the main menu");
- op=sc.nextInt();
- switch(op){
- case 6:
- System.out.printf("Your current total is: $%.2f\n",total);
- return total;
- case 1:
- System.out.println("You have added a Toaster maker to your order.");
- total+=19.99;
- break;
- case 2:
- System.out.println("You have added a Coffee maker to your order.");
- total+=29.49;
- break;
- case 3:
- System.out.println("You have added a Waffle maker to your order.");
- total+=15.79;
- break;
- case 4:
- System.out.println("You have added a Blender maker to your order.");
- total+=24.99;
- break;
- case 5:
- System.out.println("You have added a Kettle maker to your order.");
- total+=24.99;
- break;
- default:
- System.out.println("Invalid item number please try again");
- }
- return ViewMenu(total);
- }
- public static boolean PayTotalDue(double total){
- double temp=total;
- if(temp>50){
- temp-=temp*0.2;
- temp+=temp*0.085;
- //System.out.println(temp);
- if(temp<=budget){
- System.out.printf("Thank you! You saved: $%.2f ",(total+(total*0.085)-temp));
- System.out.printf("Your change is: $%.2f\n",(budget-temp));
- System.out.println("Your items will be on their way soon!");
- }else{
- System.out.println("Insufficient funds!");
- return false;
- }
- }else{
- temp+=temp*0.085;
- System.out.printf("Thank you! Your change is: %.2f\n",(budget-temp));
- System.out.println("Your items will be on their way soon!");
- }
- return true;
- }
- public static void main(String args[]){
- double total=0;
- int f;
- while(true){
- f=Menu();
- int end=0;
- switch(f){
- case 1:
- total=ViewMenu(total);
- break;
- case 2:
- if(PayTotalDue(total)){
- total=0;
- end=1;
- }
- break;
- case 3:
- budget+=5;
- System.out.println("Credit available: $ "+budget);
- break;
- case 4:
- System.out.println("Current order balance has been cleared. Current due: $0.00 ");
- total=0;
- break;
- default:
- break;
- }
- if(end==1){
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement