Assignment 102; KeychainBeta
Code
// Donovan Rich
// Period 6
// Keychains for Sale, for real this time
// KeychainBeta.java
// 3/30/2016
import java.util.Scanner;
public class KeychainBeta
{
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;
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);
}
else if (choice == 4)
{
checkout(keyNum,keyPrice);
}
}while (choice != 4);
}
public static int addKeychains(int current)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("You have " + current + " keychains." );
System.out.println("How many keychains would you like to add to the cart?");
int add = keyboard.nextInt();
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);
System.out.println("You have " + current + " keychains." );
System.out.println("How many keychains would you like to add to remove from the cart?");
int rem = keyboard.nextInt();
int keyNum = current - rem;
System.out.println("You now have " + keyNum + " keychains." );
return keyNum;
}
public static int viewOrder(int num,int price)
{
System.out.println( "You have " + num + " keychains." );
int net = num * price;
System.out.println( "Keychains cost $" + price + " each." );
System.out.println( "Total cost of your order: $" + net + "." );
return net;
}
public static int checkout(int num,int price)
{
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 $10 dollars each");
System.out.println("Your total cost is $" + (price*num) + ".");
System.out.println("Thanks for your order, " + name + ".");
return price;
}
}
Picture of the output