Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("Ye Olde Keychain Shoppe");
- int numOfKeychains = 0 ;
- int price = 10 ;
- double salesTax = 8.25 ;
- double shippingCost = 5.00 ;
- double perKeychainShipping = 1.00 ;
- while(true) {
- System.out.println("\n1. Add Keychains to Order");
- System.out.println("2. Remove Keychains from Order");
- System.out.println("3. View current Order");
- System.out.println("4. Checkout");
- System.out.print("Please enter your choice: ");
- Scanner keyboard = new Scanner(System.in);
- Integer input = keyboard.nextInt();
- if (input == 1) {
- numOfKeychains = add_keychains(numOfKeychains);
- System.out.println("\nYou now have " + numOfKeychains + " keychains.");
- } else if (input == 2) {
- numOfKeychains = remove_keychains(numOfKeychains);
- System.out.println("\nYou now have " + numOfKeychains + " keychains.");
- } else if (input == 3) {
- view_order(numOfKeychains, price, salesTax, shippingCost, perKeychainShipping);
- } else if (input == 4){
- checkout(numOfKeychains, price, salesTax, shippingCost, perKeychainShipping);
- break;
- } else {
- System.out.println("\nIncorrect menu choice, please try again");
- }
- }
- }
- public static int add_keychains (int numOfKeychains){
- while (true) {
- System.out.print("\nYou have " + numOfKeychains + " keychains. How many to add? ");
- Scanner keyboard = new Scanner(System.in);
- Integer numToAdd = keyboard.nextInt();
- if (numToAdd > 0) {
- return (numOfKeychains + numToAdd);
- } else {
- System.out.println("Please enter a positive number of Keychains to add.");
- }
- }
- }
- public static int remove_keychains (int numOfKeychains){
- while (true) {
- System.out.print("\nYou have " + numOfKeychains + " keychains. How many to remove? ");
- Scanner keyboard = new Scanner(System.in);
- Integer numToRemove = keyboard.nextInt();
- int totalKeychains = (numOfKeychains - numToRemove);
- if (totalKeychains > 0) {
- return totalKeychains;
- } else {
- System.out.println("You may not have a negative total number of Keychains, please try again.");
- }
- }
- }
- public static void view_order (int numOfKeychains, int price, double salesTax , double shippingCost , double perKeychainShipping){
- System.out.println("\nYou have " + numOfKeychains + " keychains.");
- System.out.println("Keychains cost " + price + " each (without tax).");
- System.out.println("Tax rate is " + salesTax + ".");
- System.out.println("The shipping cost per item is $" + perKeychainShipping + " plus a base rate of $" + shippingCost + ".");
- System.out.println("Total cost is $" + ((numOfKeychains * price * (100 + salesTax)/100) + (numOfKeychains * perKeychainShipping) + shippingCost ) + ".");
- }
- public static void checkout (int numOfKeychains, int price, double salesTax , double shippingCost , double perKeychainShipping){
- System.out.print("\nWhat is your name?: ");
- Scanner keyboard = new Scanner(System.in);
- String name = keyboard.next();
- view_order(numOfKeychains , price , salesTax , shippingCost , perKeychainShipping);
- System.out.println("Thanks for your order, " + name + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement