HarrJ

Day 15 2

Aug 16th, 2023
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Day15C {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         JolibeeMenu callJolibee = new JolibeeMenu();
  7.        
  8.         callJolibee.setFood("S1");
  9.         callJolibee.setQuantity(3);
  10.        
  11.         System.out.println("total ordered: " + callJolibee.getTotal());
  12.        
  13.     }
  14. }
  15.  
  16. class JolibeeMenu {
  17.     private String food;
  18.     private int quantity;
  19.     private double total = 0;
  20.  
  21.     public void setFood(String food) {
  22.         this.food = food;
  23.     }
  24.  
  25.     public void setQuantity(int quantity) {
  26.         this.quantity = quantity;
  27.     }
  28.  
  29.     public double getTotal() {
  30.         total += compute();
  31.         return total;
  32.     }
  33.    
  34.     private double compute() {
  35.         double result = 0;
  36.         switch (food.toUpperCase()) {
  37.             case "S1":
  38.                 result += 60 * quantity;
  39.                 break;
  40.             case "S2":
  41.                 result += 122 * quantity;
  42.                 break;
  43.             case "S3":
  44.                 result += 130 * quantity;
  45.                 break;
  46.             default:
  47.                 System.out.println("Food not on menu");
  48.         }
  49.         return result;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment