Assignment 102 , Keychains 2
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Keychains2
///File Name: Keychain2s.java
///Date Finshed: 4/18/16
import java.util.Scanner;
public class Keychains2
{
public static void main( String[] args )
{
Scanner siri = new Scanner(System.in);
int Choice, total = 0, remove, add, name, cost, x;
System.out.println("Keychain shop");
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.print("> ");
Choice = siri.nextInt();
System.out.println( " ");
{
if (Choice == 1)
total+= addKey(total);
else if (Choice == 2)
total-= removeKey(total);
else if (Choice == 3)
viewOrder(total);
else
checkout(total);
}
}while (Choice != 4);
}
public static int addKey(int total )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("ADD KEYCHAINS");
System.out.println(" ");
System.out.println("You have "+total+ " keychains. How many do you want to add?");
System.out.print("> ");
int add = siri.nextInt();
System.out.println("You now have "+ (total+add) +" keychains.");
return add;
}
public static int removeKey(int total )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("REMOVE KEYCHAIN");
System.out.println(" ");
System.out.println("You have "+ total + " keychains. How many do you want to remove?");
System.out.print("> ");
int remove = siri.nextInt();
System.out.println("You now have "+ (total-remove) +" keychains.");
return remove;
}
public static int viewOrder(int total )
// No parameters.
{
System.out.println("VIEW ORDER");
System.out.println(" ");
System.out.println("You have "+total+ " keychains.");
System.out.println("Keychains are $10 each. ");
int cost = 10*total;
System.out.println("Total cost: "+ cost + "." );
return cost;
}
public static int checkout(int total )
// No parameters.
{
Scanner siri = new Scanner( System.in );
System.out.println("CHECK OUT");
System.out.println(" ");
System.out.print("What's your name? ");
String name = siri.next();
System.out.println("You have "+total+ " keychains.");
System.out.println("Keychains are $10 each. ");
int cost = 10*total;
System.out.println("Total cost: "+ cost + "." );
System.out.println("Thanks for your order " + name +"!");
return cost;
}
}
Picture of the output