Assignment #102 Keychains for Sale for real
Code
/// Name: Koosha Kimelman
/// Period: 7
/// Program Name: Keychains for Sale, for real this time
/// File Name: Keychains2.java
/// Date Completed: 3/30/16
import java.util.Scanner;
public class Keychains2 {
public static void main(String[] args) {
Scanner k = new Scanner(System.in);
int n = 0, t = 0;
System.out.println("Keychains for sale.\n");
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\n");
System.out.print("Please enter your choice: ");
n = k.nextInt();
if (n == 1)
t = Add(t);
else if (n == 2)
t = Remove(t);
else if (n == 3)
View(t);
else if (n == 4)
Checkout(t);
else
System.out.println("Error: Try again");
} while (n != 4);
}
public static int Add(int t) {
Scanner k = new Scanner(System.in);
System.out.println("\nHow many keychains do you want to add to your order? You currently have " + t);
int a = k.nextInt();
t = t + a;
System.out.println("You now have " + t + "\n");
return t;
}
public static int Remove(int t) {
Scanner k = new Scanner(System.in);
System.out.println("\nHow many keychains do you want to remove from your order? You currently have " + t);
int a = k.nextInt();
t = t - a;
System.out.println("You now have " + t + "\n");
return t;
}
public static void View(int t) {
System.out.println("\nYou currently have " + t + " keychains in your order.");
System.out.println("Keychains are $10 each.");
int a = (t * 10);
System.out.println("Total cost so far is $" + a + ".");
return;
}
public static void Checkout(int t) {
System.out.println("\nYou have " + t + " keychains in your order.");
System.out.println("Keychains are $10 each.");
int a = (t * 10);
System.out.println("Total cost is $" + a + ".");
System.out.println("Thank you for your order. Bye.");
return;
}
}
Picture of the output