Assignemnt #103 and Keychains for Sale, real ultimate power
Code
///Name: Brian Phillips
///Period:5
///Project Name: Keychains for Sale, real ultimate power
///File Name:Keys3.java
///04/11/16
import java.util.Scanner;
public class Keys3
{
public static void main (String [] args)
{
int choice;
int keys =0, total=0;
System.out.println("Ye New Keychain Shoppe");
do
{
Scanner stuff = new Scanner(System.in);
System.out.println("1. Add Keychains to order");
System.out.println("2. Remove Keychanins from Order");
System.out.println("3. View Current Order");
System.out.println("4. Checkout");
System.out.println("");
System.out.println("Please enter your choice: ");
choice=stuff.nextInt();
while (choice > 4)
{
System.out.println("Please choose a choice with 1-4");
}
if (choice == 1)
keys=Add(keys);
else if (choice == 2)
keys=Rem(keys);
else if (choice == 3)
total=View(keys);
else if (choice == 4)
keys=Check(keys);
}while (choice !=4);
}
public static int Add (int keys1)
{
Scanner stuff = new Scanner(System.in);
System.out.println("You have "+keys1+" keychains. How many to add?");
keys1=keys1+stuff.nextInt();
if (keys1 < 0)
{
System.out.println("You can only add positive numbers.");
System.out.println("You have "+keys1+" keychains. How many to add?");
keys1=keys1+stuff.nextInt();
}
System.out.println("You now have "+keys1+" keychains.");
return keys1;
}
public static int Rem (int keys2)
{
Scanner stuff = new Scanner(System.in);
System.out.println("You have "+keys2+" keychains. How many to remove?");
keys2=keys2-stuff.nextInt();
if (keys2 < 0)
{
System.out.println("You can't have negative keychains");
System.out.println("You have "+keys2+" keychains. How many to remove?");
keys2=keys2-stuff.nextInt();
}
System.out.println("You now have "+keys2+" keychains.");
return keys2;
}
public static int View (int keys3)
{
System.out.println("You now have "+keys3+" keychains.");
System.out.println("Keychains coast $10 dollars each");
int total = 10*keys3;
double tax = total * .0875;
double taxTotal = tax +total;
double totalReal = taxTotal + 5 + keys3;
System.out.println("Total cost is $"+total+".");
System.out.println("There will also be a flat rate of $5 for shipping plus $"+keys3);
System.out.println("The total will be $" + totalReal);
return total;
}
public static int Check (int keys4)
{
Scanner stuff = new Scanner(System.in);
System.out.println("What is your name?");
String name=stuff.next();
View(keys4);
System.out.println("Thanks for your order, "+name+".");
return keys4;
}
}
Picture of the output