Advertisement
MrDoyle

Methods) Ultimate Keychains for sale

Apr 9th, 2021
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         System.out.println("Ye Olde Keychain Shoppe");
  8.  
  9.         int numOfKeychains = 0 ;
  10.         int price = 10 ;
  11.         double salesTax = 8.25 ;
  12.         double shippingCost = 5.00 ;
  13.         double perKeychainShipping = 1.00 ;
  14.  
  15.         while(true) {
  16.             System.out.println("\n1. Add Keychains to Order");
  17.             System.out.println("2. Remove Keychains from Order");
  18.             System.out.println("3. View current Order");
  19.             System.out.println("4. Checkout");
  20.  
  21.             System.out.print("Please enter your choice: ");
  22.             Scanner keyboard = new Scanner(System.in);
  23.             Integer input = keyboard.nextInt();
  24.  
  25.             if (input == 1) {
  26.                 numOfKeychains = add_keychains(numOfKeychains);
  27.                 System.out.println("\nYou now have " + numOfKeychains + " keychains.");
  28.  
  29.             } else if (input == 2) {
  30.                 numOfKeychains = remove_keychains(numOfKeychains);
  31.                 System.out.println("\nYou now have " + numOfKeychains + " keychains.");
  32.  
  33.             } else if (input == 3) {
  34.                 view_order(numOfKeychains, price, salesTax, shippingCost, perKeychainShipping);
  35.             } else  if (input == 4){
  36.                 checkout(numOfKeychains, price, salesTax, shippingCost, perKeychainShipping);
  37.                 break;
  38.             } else {
  39.                 System.out.println("\nIncorrect menu choice, please try again");
  40.             }
  41.         }
  42.     }
  43.  
  44.     public static int add_keychains (int numOfKeychains){
  45.         while (true) {
  46.             System.out.print("\nYou have " + numOfKeychains + " keychains. How many to add? ");
  47.             Scanner keyboard = new Scanner(System.in);
  48.             Integer numToAdd = keyboard.nextInt();
  49.  
  50.             if (numToAdd > 0) {
  51.                 return (numOfKeychains + numToAdd);
  52.             } else {
  53.                 System.out.println("Please enter a positive number of Keychains to add.");
  54.             }
  55.         }
  56.  
  57.     }
  58.  
  59.     public static int remove_keychains (int numOfKeychains){
  60.         while (true) {
  61.             System.out.print("\nYou have " + numOfKeychains + " keychains. How many to remove? ");
  62.             Scanner keyboard = new Scanner(System.in);
  63.             Integer numToRemove = keyboard.nextInt();
  64.  
  65.             int totalKeychains = (numOfKeychains - numToRemove);
  66.             if (totalKeychains > 0) {
  67.                 return totalKeychains;
  68.             } else {
  69.                 System.out.println("You may not have a negative total number of Keychains, please try again.");
  70.             }
  71.         }
  72.     }
  73.  
  74.     public static void view_order (int numOfKeychains, int price, double salesTax , double shippingCost , double perKeychainShipping){
  75.         System.out.println("\nYou have " + numOfKeychains + " keychains.");
  76.         System.out.println("Keychains cost  " + price + " each (without tax).");
  77.         System.out.println("Tax rate is " + salesTax + ".");
  78.         System.out.println("The shipping cost per item is $" + perKeychainShipping + " plus a base rate of $" + shippingCost + ".");
  79.  
  80.         System.out.println("Total cost is $" + ((numOfKeychains * price * (100 + salesTax)/100) + (numOfKeychains * perKeychainShipping) + shippingCost ) + ".");
  81.     }
  82.  
  83.     public static void checkout (int numOfKeychains, int price, double salesTax , double shippingCost , double perKeychainShipping){
  84.         System.out.print("\nWhat is your name?: ");
  85.         Scanner keyboard = new Scanner(System.in);
  86.         String name = keyboard.next();
  87.         view_order(numOfKeychains , price , salesTax , shippingCost , perKeychainShipping);
  88.         System.out.println("Thanks for your order, " + name + ".");
  89.  
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement