Advertisement
psi_mmobile

Untitled

May 9th, 2022
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         String fruit = scanner.nextLine();
  5.         String setSize = scanner.nextLine();
  6.         int numberOfSets = scanner.nextInt();
  7.        
  8.         double watermelonPrice = 0.0;
  9.         double mangoPrice = 0.0;
  10.         double pineapplePrice = 0.0;
  11.         double raspberryPrice = 0.0;
  12.        
  13.         int multiplier = 0;
  14.        
  15.         if (setSize.equals("small")) {
  16.             watermelonPrice = 56.00;
  17.             mangoPrice = 36.66;
  18.             pineapplePrice = 42.10;
  19.             raspberryPrice = 20.00;
  20.             multiplier = 2;
  21.         } else {
  22.             watermelonPrice = 28.70;
  23.             mangoPrice = 19.60;
  24.             pineapplePrice = 24.80;
  25.             raspberryPrice = 15.20;
  26.             multiplier = 5;
  27.         }
  28.         double totalPrice = 0.0;
  29.         switch(fruit) {
  30.             case "Watermelon" : totalPrice = watermelonPrice * numberOfSets * multiplier;
  31.             if (totalPrice >= 400 && totalPrice <= 1000) {
  32.                 totalPrice = totalPrice * 0.85;
  33.             } else if (totalPrice < 400)  {
  34.                 totalPrice = totalPrice;
  35.             } else {
  36.                 totalPrice = totalPrice * 0.5;
  37.             } break;
  38.             case "Mango" : totalPrice = mangoPrice * numberOfSets * multiplier;
  39.             if (totalPrice >= 400 && totalPrice <= 1000) {
  40.                 totalPrice = totalPrice * 0.85;
  41.             } else if (totalPrice < 400)  {
  42.                 totalPrice = totalPrice;
  43.             } else {
  44.                 totalPrice = totalPrice * 0.5;
  45.             } break;
  46.             case "Pineapple" : totalPrice = pineapplePrice * numberOfSets * multiplier;
  47.             if (totalPrice >= 400 && totalPrice <= 1000) {
  48.                 totalPrice = totalPrice * 0.85;
  49.             } else if (totalPrice < 400)  {
  50.                 totalPrice = totalPrice;
  51.             } else {
  52.                 totalPrice = totalPrice * 0.5;
  53.             } break;
  54.             case "Raspberry" : totalPrice = raspberryPrice * numberOfSets * multiplier;
  55.             if (totalPrice >= 400 && totalPrice <= 1000) {
  56.                 totalPrice = totalPrice * 0.85;
  57.             } else if (totalPrice < 400)  {
  58.                 totalPrice = totalPrice;
  59.             } else {
  60.                 totalPrice = totalPrice * 0.5;
  61.             } break;
  62.         }
  63.         System.out.printf("%.2f lv.",totalPrice);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement