Assignemnt #103 ChainzFr2.java

Code

    /// Name: Boris Kazantsev
    /// Period: 6
    /// Program Name: ChainzFr2
    /// File Name: ChainzFr2.java
    /// Date Finished: 3/28/2016
    
    import java.util.Scanner;
import java.util.InputMismatchException;

public class ChainzFr2{
    static Scanner keyboard = new Scanner(System.in);
    static int currentKey = 0;
    static float tax = 0.0825f;
    static int shipping = 5;
    static int shippingperKey = 1;
    static int price = 7;
    public static void main(String[] args){
        System.out.println("WELCOME");
        
        int choice = 0;
        
        do{
            showMenu();
            
            do choice = choice();
            while (choice ==0);
            
            if (choice == 1) addKey();
            if ( choice == 2) removeKey();
            if (choice == 3) viewOrder();
            
        }
        while (choice!=4);
        
        checkOut();
        
        System.out.println();
    }
    
    public static void showMenu(){
        System.out.println("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=");
        System.out.println("1) Add Keychains to Order");
        System.out.println("2) Remove Keycahins from Order");
        System.out.println("3) View Current Order");
        System.out.println("4) Check Out");
        System.out.println("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=");
    }
    
    public static int choice() {
        int choice = 0;
        System.out.print("Choice: ");
        choice = keyboard.nextInt();
                System.out.println();

        
        if (choice < 1 || choice > 4) choice = 0;
        
        return choice;
    }
    
    public static void addKey(){
        System.out.print("How many?: ");
        try{
            int add = keyboard.nextInt();
            if ( add>0)
            {
             currentKey += add;
                System.out.println();
             System.out.println(add + " KEYCHAIN ADDED");
            System.out.println("***********************");
                chainz();
            }
            else System.out.println("ERROR");
        }
        catch (InputMismatchException e)
        {
            System.out.println("ERROR");
        }
        
        
        
        
    }
    
    public static void removeKey(){
        System.out.print("How many?: ");
        try {
            int del = keyboard.nextInt();
            if ( del > 0 && del <= currentKey){
                currentKey -= del;
                System.out.println();
                System.out.println(del + " KEYCHAIN REMOVED");
                System.out.println("***********************");
                chainz();
            }
            else System.out.println("ERROR");
        }
        catch (InputMismatchException e){
            System.out.println("ERROR");
        }

        
    
    }
    public static void viewOrder(){
        System.out.println();
        int cost = (price*currentKey+(shipping + currentKey*shippingperKey));
        chainz();
        System.out.println("$7 per Keychains.");
        System.out.println("*=*=*=*=*=*=*=*=*=*=*=*");
        System.out.println("Price: $"+(price*currentKey)+".");
        System.out.println("Shipping fee: $"+(shipping+currentKey*shippingperKey)+".");
        System.out.println("Price + shipping fee: $"+cost+".");
        double pTax = (0.0825*(price*currentKey+(shipping + currentKey*shippingperKey)));
        System.out.println("Tax: $"+pTax+".");
        System.out.println("***********************");
        System.out.println("TOTAL COST:$"+cost*(1+tax)+".");
    }
    
    
    public static void checkOut(){
        System.out.print("What is your name? ");
        String name = keyboard.next();
        chainz();
        System.out.println("Keychains cost $7 each.");
        int cost = (price*currentKey);
        System.out.println("Total cost is $"+cost);
        System.out.println("Thanks for your order, "+name+" !");
    
        
        
        
    }
    
    public static void chainz() {
        
        System.out.println("YOU HAVE "+currentKey+" KEYCHAINS.");
    }
}

        
        
        
        
        
        
        


   
    

Picture of the output

Assignment 103