Assignemnt #102 and Keychains for Sale, for real this time
Code
/// Name: Raff Lisbona
/// Period: 6
/// Program Name: Keychains For Sale For Real This Time
/// File Name: ForRealThisTime.java
/// Date Finished: 3/28/2016
import java.util.Scanner;
public class ForRealThisTime
{
public static void main ( String[] args )
{
int choice, number = 0, price = 10, 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);
else if ( choice == 4 )
checkout(number, totalCost);
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;
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;
System.out.println("You now hava " + total + " keychains.");
return total;
}
public static int viewOrder(int number, int price)
{
System.out.println("\nYou have " + number + " keychains.");
System.out.println("Keychains cost $" + price + " each.");
int totalCost = price * number;
System.out.println("Total cost is $" + totalCost + ".");
return totalCost;
}
public static void checkout(int number, int totalCost)
{
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();
System.out.println("You have " + number + " keychains.");
System.out.println("Keychains cost $" + cost + " each.");
System.out.println("Total cost is $" + totalCost + ".");
System.out.println("Thanks for your order, " + name + "!");
}
}
Picture of the output