Methods #102 (Again with the Memechains)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name: KeyChains for Sale FRTT
/// File Name:KeyChainsforSaleFRTT.java
/// Date Finished: 4/9/2016
import java.util.Scanner;
public class KeyChainsforSaleFRTT
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.println( "KEYCHAIN SHOP" );
System.out.println();
int choice, number, price;
number = 0;
price = 10;
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();
System.out.print( "Please enter your choice: " );
choice = keyboard.nextInt();
System.out.println();
if ( choice == 1 )
number = addKeychains(number);
else if ( choice == 2 )
number = removeKeychains(number);
else if ( choice == 3 )
viewOrder(number, price);
else if ( choice == 4 )
checkout(number, price);
}while ( choice != 4 );
}
public static int addKeychains(int number)
{
Scanner keyboard = new Scanner(System.in);
int add, total;
System.out.println( "You have " + number + " keychains at the moment." );
System.out.print( "How many would you like to add? " );
add = keyboard.nextInt();
total = number + add;
System.out.println( "You now have " + total + " keychains." );
System.out.println();
return total;
}
public static int removeKeychains(int number)
{
Scanner keyboard = new Scanner(System.in);
int remove, total;
System.out.println( "You have " + number + " keychains at the moment." );
System.out.print( "How many would you like to remove? " );
remove = keyboard.nextInt();
total = number - remove;
System.out.println( "You now have " + total + " keychains." );
System.out.println();
return total;
}
public static void viewOrder(int number, int price)
{
price = number * 10;
System.out.println( "You have " + number + " keychains." );
System.out.println( "Keychains cost $10 each." );
System.out.println( "The total is " + price + "." );
System.out.println();
}
public static void checkout(int number, int price)
{
Scanner keyboard = new Scanner(System.in);
String name;
System.out.println( "CHECKOUT" );
System.out.println();
System.out.print( "What is your name? " );
name = keyboard.next();
System.out.println( "You have " + number + " keychains." );
System.out.println( "Keychains cost $10 each." );
System.out.println( "The total is " + price + "." );
System.out.println( "Thanks for your order, " + name + "!" );
System.out.println();
}
}
Picture(s) of the output