Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Fruit_Vegetable_Shop {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Enter day of the week: ");
- String day = keyboard.next();
- System.out.print("Enter commodity: ");
- String commodity = keyboard.next();
- System.out.print("Enter quantity: ");
- double quantity = keyboard.nextDouble();
- //ΠΏΠ»ΠΎΠ΄ banana apple orange grapefruit kiwi pineapple grapes
- // (Monday / Tuesday / Wednesday / Thursday / Friday
- boolean isWorkDay = "Monday".equalsIgnoreCase(day) ||
- "Tuesday".equalsIgnoreCase(day) ||
- "Wednesday".equalsIgnoreCase(day) ||
- "Thursday".equalsIgnoreCase(day) ||
- "Friday".equalsIgnoreCase(day);
- boolean weekEnd = "Saturday".equalsIgnoreCase(day) || "Sunday".equalsIgnoreCase(day);
- switch (commodity) {
- case "banana":
- if (isWorkDay) {
- System.out.printf("%.2f", quantity *2.50);
- } else if (weekEnd) {
- System.out.printf("%.2f", quantity * 2.70);
- }
- break;
- case "apple":
- if (isWorkDay) {
- System.out.printf("%.2f", quantity * 1.20);
- } else if (weekEnd) {
- System.out.printf("%.2f", quantity * 1,30);
- }
- break;
- case "orange":
- if (isWorkDay) {
- System.out.printf("%.2f", quantity * 0.85);
- } else if (weekEnd) {
- System.out.printf("%.2f", quantity * 0.90);
- }
- break;
- case "grapefruit":
- if (isWorkDay) {
- System.out.printf("%.2f", quantity * 1.45);
- } else if (weekEnd) {
- System.out.printf("%.2f",quantity * 1.60);
- }
- break;
- case "kiwi":
- if (isWorkDay) {
- System.out.printf("%.2f", quantity * 2.70);
- }else if (weekEnd){
- System.out.printf("%.2f",quantity * 3.00);
- }
- break;
- case "pineapple":
- if (isWorkDay) {
- System.out.printf("%.2f",quantity * 5.50);
- } else if (weekEnd) {
- System.out.printf("%.2f", quantity * 5.60);
- }
- break;
- case "grapes":
- if (isWorkDay) {
- System.out.printf("%.2f",quantity * 3.85);
- }else if (weekEnd) {
- System.out.printf("%.2f", quantity * 4.00);
- }
- break;
- default:
- System.out.println("There is not such commodity");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement