Assignemnt #103 and Keychains For Sale, real ultimate power
Code
/// Name: Raff Lisbona
/// Period: 6
/// Program Name: Keychains For Sale Real Ultimate Power
/// File Name: RealUltimatePower.java
/// Date Finished: 3/29/2016
import java.util.Scanner;
public class RealUltimatePower
{
public static void main ( String[] args )
{
int choice, number = 0, price = 10;
int shippingCost = 5, perChainCost = 1;
double tax = .0825, totalCost = 0;
System.out.println("Ye Olde Keychain Shoppe");
do
{
Scanner keyboard = new Scanner(System.in);
System.out.println("\n1. 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("\nPlease enter your choice: ");
choice = keyboard.nextInt();
if ( choice == 1 )
number = addKeychains(number);
else if ( choice == 2 )
number = removeKeychains(number);
else if ( choice == 3 )
totalCost = viewOrder(number, price, shippingCost, tax, perChainCost);
else if ( choice == 4 )
checkout(number, price, shippingCost, tax, perChainCost);
else
System.out.println("\nERROR");
}while(choice != 4);
}
public static int addKeychains(int number)
{
Scanner kb = new Scanner(System.in);
int total, add;
System.out.print("\nYou have " + number + " keychains. How many to add? ");
add = kb.nextInt();
total = number + add;
while ( total <= 0 )
{
System.out.print("Error. How many to add?");
add = kb.nextInt();
total = number + add;
}
System.out.println("You now have " + total + " keychains.");
return total;
}
public static int removeKeychains(int number)
{
Scanner kb = new Scanner(System.in);
int total, remove;
System.out.print("\nYou have " + number + " keychains. How many to remove? ");
remove = kb.nextInt();
total = number - remove;
while ( total <= 0 )
{
System.out.print("Error. How many to remove?");
remove = kb.nextInt();
total = number - remove;
}
System.out.println("You now hava " + total + " keychains.");
return total;
}
public static double viewOrder(double number, double price, double shippingCost, double tax, double perChainCost)
{
System.out.println("\nYou have " + number + " keychains.");
System.out.println("Keychains cost $" + price + " each.");
System.out.println("The shipping will cost $" + shippingCost + " for one keychain and $" + perChainCost + " for each additional keychain.");
double shipping = (number - 1) * perChainCost + shippingCost;
double subtotal = price * number + shipping;
System.out.println("The subtotal is $" + subtotal + ".");
double stax = tax * subtotal;
System.out.println("The tax is $" + stax + ".");
double totalCost = subtotal + stax;
System.out.println("Total cost is $" + totalCost + ".");
return totalCost;
}
public static void checkout(int number, int price, int shippingCost, double tax, int perChainCost)
{
Scanner kb = new Scanner(System.in);
String name;
int cost = 10;
System.out.println("\nCHECKOUT");
System.out.print("\nWhat is your name? ");
name = kb.next();
viewOrder(number, price, shippingCost, tax, perChainCost);
System.out.println("Thanks for your order, " + name + "!");
}
}
Picture of the output