Assignment 103; KeychainRelease
Code
// Donovan Rich
// Period 6
// Keychains for Sale, real ultimate power
// KeychainRelease.java
// 4/1/2016
import java.util.Scanner;
public class KeychainRelease
{
public static void main (String [] args)
{
System.out.println("Get yer keychains here, bruv.");
Scanner keyboard = new Scanner(System.in);
int choice, keyNum=0, keyPrice=5;
double tax=0.0825, shipFlat=5.0, shipPer=1.0;
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.println("Please enter a choice");
choice = keyboard.nextInt();
if (choice == 1)
{
keyNum = addKeychains(keyNum);
}
else if (choice == 2)
{
keyNum = removeKeychains(keyNum);
}
else if (choice == 3)
{
viewOrder(keyNum,keyPrice,shipFlat,shipPer,tax);
}
else if (choice == 4)
{
checkout(keyNum,keyPrice,shipFlat,shipPer,tax);
}
else
System.out.println("ERROR: invalid menu choice. Please check your input and try again.");
}while (choice != 4);
}
public static int addKeychains(int current)
{
Scanner keyboard = new Scanner(System.in);
int add=0;
System.out.println("You have " + current + " keychains." );
System.out.println("How many keychains would you like to add to the cart?");
do
{
add = keyboard.nextInt();
if ( add < 0 )
System.out.println( "ERROR: negative values are UNACCEPTABLE." );
} while ( add < 0 );
int keyNum = current + add;
System.out.println("You now have " + keyNum + " keychains." );
return keyNum;
}
public static int removeKeychains(int current)
{
Scanner keyboard = new Scanner(System.in);
int rem = 0;
System.out.println("You have " + current + " keychains." );
System.out.println("How many keychains would you like to add to remove from the cart?");
do
{
rem = keyboard.nextInt();
if ( rem < 0 )
System.out.println( "ERROR: negative values are UNACCEPTABLE." );
} while ( rem < 0 );
int keyNum = current - rem;
System.out.println("You now have " + keyNum + " keychains." );
return keyNum;
}
public static void viewOrder(int num,int price,double shipFlat, double shipPer, double tax)
{
System.out.println( "You have " + num + " keychains." );
System.out.println( "Keychains cost $" + price + " each." );
System.out.println( "There is a tax of 8.25% and a shipping cost of $5.00 plus $1.00 per keychain.");
System.out.println( "Subtotal (before tax and shipping): " + num*price );
double net = num*price*tax+num*price+shipFlat+shipPer*num;
System.out.println( "Total cost of your order: $" + net + "." );
}
public static void checkout(int num,int price,double shipFlat, double shipPer, double tax)
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.print("Please enter your name: ");
String name;
name = keyboard.next();
System.out.println( "You have " + num + " keychains." );
System.out.println( "Keychains cost $" + price + " each." );
System.out.println( "There is a tax of 8.25% and a shipping cost of $5.00 plus $1.00 per keychain.");
System.out.println( "Subtotal (before tax and shipping): " + num*price );
double net = num*price*tax+num*price+shipFlat+shipPer*num;
System.out.println( "Total cost of your order: $" + net + "." );
System.out.println("Thanks for your order, " + name + ".");
}
}
Picture of the output