Assignemnt #103 Keychains for Sale, real ultimate power
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Keychains for Sale, real ultimate power
///File Name: KfS3.java
///Date: 3/31/2016
import java.util.Scanner;
public class KfS3
{
public static void main( String[] args)
{
Scanner kb = new Scanner(System.in);
double tax = 8.25;
int ship = 5;
int addship = 1;
int cost = 20;
int keys = 0;
System.out.println("Keychain Store");
System.out.println("");
int answer = 0;
do
{
System.out.println("1. Add keychains");
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("Please enter your choice: ");
answer = kb.nextInt();
if (answer == 1) keys = AddKeychain(keys);
if (answer == 2) keys = RemoveKeychain(keys);
if (answer == 3) ViewOrder(keys, cost, tax, ship, addship);
if (answer == 4) Checkout(keys, cost, tax, ship, addship);
if (answer <1 || answer > 4)
{
System.out.println("Wrong Input!");
answer = kb.nextInt();
}
}while(answer!=4);
}
public static int AddKeychain(int key)
{
Scanner kb = new Scanner(System.in);
System.out.print("You have " + key + " keychains. How many to add? ");
int add = kb.nextInt();
if(add<0)
{
System.out.println("Wrong Input!");
add = kb.nextInt();
}
key = add + key;
System.out.println("You now have " + key + " keys.");
return key;
}
public static int RemoveKeychain(int key)
{
Scanner kb = new Scanner(System.in);
System.out.print("You have " + key + " keychains. How many to remove? ");
int remove = kb.nextInt();
if(remove<0)
{
System.out.println("Wrong Input!");
remove = kb.nextInt();
}
key = key - remove;
System.out.println("You now have " + key + " keys.");
return key;
}
public static void ViewOrder(int key, int cost, double tax, int ship, int addship)
{
System.out.println("You have " + key + " keychains.");
System.out.println("They each cost $" + cost + ".");
int shipcharge = ship + (key - 1) * addship;
System.out.println("The shipping charge is $" + shipcharge + ".");
int SubtotalCost = key * cost + shipcharge;
System.out.println("Subtotal cost is $" + SubtotalCost + ".");
double taxed = tax / 100 * (SubtotalCost - shipcharge);
System.out.println("The tax on the item(s) is $" + taxed + ".");
double total = SubtotalCost + taxed;
System.out.println("The total price is $" + total + ".");
}
public static void Checkout(int key, int cost, double tax, int ship, int addship)
{
Scanner kb = new Scanner(System.in);
System.out.print("What is your name? ");
String name = kb.next();
System.out.println("You have " + key + " keychains.");
System.out.println("They each cost $" + cost + ".");
int shipcharge = ship + (key - 1) * addship;
System.out.println("The shipping charge is $" + shipcharge + ".");
int SubtotalCost = key * cost + shipcharge;
System.out.println("Subtotal cost is $" + SubtotalCost + ".");
double taxed = tax / 100 * (SubtotalCost - shipcharge);
System.out.println("The tax on the item(s) is $" + taxed + ".");
double total = SubtotalCost + taxed;
System.out.println("The total price is $" + total + ".");
System.out.println("Thanks for your order, " + name + "!");
}
}
Picture of the output