Skip to content

Instantly share code, notes, and snippets.

@xputerax
Created December 5, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xputerax/d044abbd1f1d4f5925f918f52b522464 to your computer and use it in GitHub Desktop.
Save xputerax/d044abbd1f1d4f5925f918f52b522464 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Shop {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Float total_price = new Float("0.00");
String category = new String("");
String code = new String("");
Integer quantity = new Integer("0");
Float price = new Float("0.00");
System.out.print("Enter a category (F/M): ");
category = input.nextLine();
if (category.equals("M")) {
System.out.println("Available codes:");
System.out.println("M03: RM110.00");
System.out.println("M04: RM99.90\n");
System.out.print("Enter a code: ");
code = input.nextLine();
if (code.equals("M03")) {
price = new Float("110.00");
} else if (code.equals("M04")) {
price = new Float("99.90");
} else {
System.out.println("Incorrect code");
input.close();
return;
}
} else if (category.equals("F")) {
System.out.println("Available codes:");
System.out.println("FM01: RM120.00");
System.out.println("FM02: RM100.00\n");
System.out.print("Enter a code: ");
code = input.nextLine();
if (code.equals("FM01")) {
price = new Float("120.00");
} else if (code.equals("FM02")) {
price = new Float("100.00");
} else {
System.out.println("Incorrect code");
input.close();
return;
}
} else {
System.out.println("You have entered an incorrect category.");
input.close();
return;
}
System.out.print("Enter a quantity: ");
quantity = new Integer(input.nextLine());
total_price = quantity * price;
System.out.println("\n\n");
System.out.println("Code: " + code);
System.out.println("Price per unit: " + price);
System.out.println("Quantity: " + quantity);
System.out.println("Total price: " + total_price);
input.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment