Assignemnt #106

Code

/// Name: Connor Siri
/// Period: 7
/// Program Name: power
/// File Name: Power.java
/// Date Finished: 2/17/2016


import java.util.Scanner;
        
        public class Power
        {
            public static void main(String[] args)
            {
                Scanner kb = new Scanner(System.in);
                
                int number, price, shippingorder, shippingper;
                double saletax;
                
                number = 0;
                price = 10;
                shippingorder = 5;
                shippingper = 1;
                saletax = 1.0825;
                
                System.out.println("The Kaychain shop");
                System.out.println("");
                System.out.println("1. 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.println("");
                System.out.print("Your Choice: ");
                int choice = kb.nextInt();
                System.out.println("");
                
                while (choice != 4)
                {
                    if ( choice == 1)
                    {
                        number = addKeychains(number);
                    }
                    else if (choice == 2)
                        number = removeKeychains(number);
                    else if (choice == 3)
                        viewOrder(number, price, saletax, shippingorder, shippingper);
                    else
                    {
                        System.out.println("ERROR: Please choose one of the options");
                    }
                    
                    System.out.println("");
                    System.out.println("1. 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.println("");
                    System.out.print("Your Choice: ");
                    choice = kb.nextInt();
                    System.out.println("");
                }
                
                checkout(number, price, saletax, shippingorder, shippingper);
            }
            
            public static int addKeychains(int number)
            {
                Scanner kb = new Scanner(System.in);
                
                int  total, add;
                
                System.out.print("You have " + number + " keychains. Add how many? ");
                add = kb.nextInt();
                
                total = number + add;
                
                System.out.println("You now have " + total + " keychains");
                
                return total;
            }
            
            public static int removeKeychains(int number)
            {
                Scanner kb = new Scanner(System.in);
                
                int total, take;
                
                total = 0;
                
                System.out.print("You have " + number + " keychains. Remove how many? ");
                take = kb.nextInt();
                
                total = number - take;
                
                while ( total < 0 )
                {
                    System.out.println("You can't have less than 0 keychains");
                    System.out.print("You have " + number + " keychains. Remove how many? " );
                    take = kb.nextInt();
                    total = number - take;
                }
                
                System.out.println("You now have " + total + " keychains");
                
                return total;
            }
            
            public static void viewOrder(int number, int price, double saletax, int shippingper, int shippingorder)
            {
                int shiptotal = (number * shippingper) + shippingorder;
                int subtotal = (number * price ) + shiptotal;
                double total = number * price;
                
                System.out.println("You currently have " + number + " keychains.");
                System.out.println("Each keychain is $" + price + ".");
                System.out.println("Your total shipping cost is $"+ shiptotal);
                System.out.println("Your subtotal is $"+subtotal);
                System.out.println("Your total cost is $" + total );
            }
            
            public static void checkout(int number, int price, double saletax, int shippingper, int shippingorder)
            {
                Scanner kb = new Scanner(System.in);
                
                int total = number * price; 
                
                System.out.print("What is you name? ");
                String name = kb.next();
                viewOrder(number, price, saletax, shippingorder, shippingper);
                System.out.println("Thank you for your order, " + name);
            }
        }   
    
    
 

Picture of the output

Assignment14.html