Assignemnt #102 Keychains for sale part 2
Code
///Name: Morgan Kaplan
///Period: 5
///File Name: Keytwo.java
import java.util.Scanner;
public class Keytwo
{
public static void main( String[] args )
{
int choice;
int n=0,a,s,tn;
do
{
Scanner momo = new Scanner(System.in);
System.out.println("Keychain Shop!");
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("5. Leave the page");
choice=momo.nextInt();
if (choice==1)
n=Add(n);
else if (choice==2)
n=Remove(n);
else if (choice==3)
View(n);
else if (choice==4)
Checkout(n);
else
Bye();
} while( choice!=5);
}
public static int Add(int n)
{
int a;
Scanner momo = new Scanner(System.in);
System.out.println( "How many Keychains would you like to add, you currently have " + n + "?");
a=momo.nextInt();
n=n+a;
return n;
}
public static int Remove(int n)
{
int b;
Scanner momo = new Scanner(System.in);
System.out.println( "How many Keychains would you like to remove?");
b=momo.nextInt();
n=n-b;
return n;
}
public static void View(int n)
{
System.out.println(" You have " + n + " keychains");
}
public static void Checkout(int n)
{
int p=10;
int c= (p*n);
System.out.println( "The total cost is " + c + ".");
}
public static void Bye()
{
System.out.println( "Bye, thank you for shopping!");
}
}
Picture of Output