Assignment 103 , Keychains 3
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Keychains3
///File Name: Keychains3.java
///Date Finshed: 4/19/16
import java.util.Scanner;
public class Keychains3
{
public static void main( String[] args )
{
Scanner siri = new Scanner(System.in);
int Choice, total = 0, remove, add, name, x;
double tax = 8.25, shipping = 5, keychainshipping = 1, cost;
System.out.println("Keychain shop");
do
{
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.print("> ");
Choice = siri.nextInt();
System.out.println( " ");
{
if (Choice == 1 && total >= 0)
total+= addKey(total);
else if (Choice == 2 && total >= 0)
total-= removeKey(total);
else if (Choice == 3 && total >= 0)
viewOrder(total, tax, shipping, keychainshipping );
else if (Choice == 4 && total >= 0)
checkout(total,tax, shipping, keychainshipping);
else
{
System.out.println("ERROR: You did not pick a proper choice or you have a negative amount of keychains");
total+= addKey(total);
}
}
}while (Choice != 4);
}
public static int addKey(int total )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("ADD KEYCHAINS");
System.out.println(" ");
System.out.println("You have "+total+ " keychains. How many do you want to add?");
System.out.print("> ");
int add = siri.nextInt();
System.out.println("You now have "+ (total+add) +" keychains.");
return add;
}
public static int removeKey(int total )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("REMOVE KEYCHAIN");
System.out.println(" ");
System.out.println("You have "+ total + " keychains. How many do you want to remove?");
System.out.print("> ");
int remove = siri.nextInt();
System.out.println("You now have "+ (total-remove) +" keychains.");
return remove;
}
public static double viewOrder(int total, double tax, double shipping, double keychainshipping )
// No parameters.
{
System.out.println("VIEW ORDER");
System.out.println(" ");
System.out.println("You have "+total+ " keychains.");
System.out.println("Keychains are $10 each. ");
double cost = total * 10;
double taxcost = (shipping + (total*keychainshipping));
System.out.println("You owe "+(shipping + (total*keychainshipping)) +" in shipping fees.");
System.out.println("Total cost before tax: "+ cost + "" );
System.out.println("Tax: "+ taxcost + "" );
cost = cost + (taxcost);
System.out.println("Total cost all together: "+ cost + "" );
return cost;
}
public static void checkout(int total, double tax, double shipping, double keychainshipping )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("CHECK OUT");
System.out.println(" ");
System.out.print("What's your name? ");
String name = siri.next();
viewOrder(total, tax, shipping, keychainshipping);
System.out.println("Thanks for your order " + name +"!");
}
}
Picture of the output