Assignment #103 and Keychains for sale, real ultimate power
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Keychains for sale 3
///File Name: Keychains3.java
///Date Finished: 11/20/15
import java.util.Scanner;
public class Keychains3
{
public static void main ( String[] args )
{
Scanner kb = new Scanner(System.in);
System.out.println( "Keychain Shop" );
int choice, kChains, price, shipping, addShipping;
kChains = 0;
price = 10;
double tax = .0825;
shipping = 5;
addShipping = 1;
do
{
System.out.print( "\n1. Add Keychains to Order \n2. Remove Keychains from Order \n3. View Current Order \n4. Checkout \n\nPlease Enter your choice: " );
choice = kb.nextInt();
System.out.println();
if ( choice == 1 && kChains >= 0 )
kChains = addKeychains(kChains);
else if ( choice == 2 && kChains >= 0 )
kChains = removeKeychains(kChains);
else if ( choice == 3 && kChains >= 0)
viewOrder(kChains,price,tax,shipping,addShipping);
else if ( choice == 4 && kChains >= 0 )
checkout(kChains,price,tax,shipping,addShipping);
else if ( kChains < 0 )
System.out.println( "You have less than one keychain. Please leae the shop becuase that is not allowed.");
else
System.out.print( "Error" );
} while ( choice != 4 && kChains >= 0 );
}
public static int addKeychains( int kChains )
{
Scanner kb = new Scanner(System.in);
int add;
System.out.print( "You have " + kChains + " keychains. How many to add? " );
add = kb.nextInt();
kChains += add;
System.out.println( "You now have " + kChains + " keychains.\n" );
return kChains;
}
public static int removeKeychains(int kChains)
{
Scanner kb = new Scanner(System.in);
int remove;
System.out.print( "You have " + kChains + " keychains. How many would you like to remove. " );
remove = kb.nextInt();
kChains -= remove;
System.out.println( "You now have " + kChains + " keychains.\n" );
return kChains;
}
public static void viewOrder(int kChains, int price, double tax, int shipping, int addShipping)
{
int shipTotal = shipping + ( kChains * addShipping );
int subTotal = shipTotal + ( price * kChains );
double total = subTotal + ( tax * subTotal );
System.out.println( "You have " + kChains + " keychains. \nKechains cost $" + price + " each. \nShipping total is $" + shipTotal + ". \nSubtotal is $" + subTotal + "\nTotal cost is $" + total + ".\n" );
}
public static void checkout( int kChains, int price, double tax, int shipping, int addShipping )
{
Scanner kb = new Scanner(System.in);
String name;
System.out.print( "What is your name? " );
name = kb.next();
viewOrder(kChains,price,tax,shipping,addShipping);
System.out.println("Thanks for shopping " + name + "." );
}
}
Picture of the output