Advertisement
Valleri

Melons and Watermelons

Jul 31st, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MelonsWatermelons {
  4.     public enum Days {
  5.         MONDAY (1, 0),
  6.         TUESDAY (0, 2),
  7.         WEDNESDAY (1, 1),
  8.         THURSDAY (2, 0),
  9.         FRIDAY (2, 2),
  10.         SATURDAY (1, 2),
  11.         SUNDAY (0, 0);
  12.        
  13.         private final int waterMelons;
  14.         private final int melons;
  15.        
  16.         Days(int waterMelons, int melons) {
  17.             this.waterMelons = waterMelons;
  18.             this.melons = melons;
  19.         }
  20.     }
  21.     public static void main(String[] args) {
  22.         Scanner input = new Scanner(System.in);
  23.        
  24.         int startDay = input.nextInt();
  25.         int howManyDays = input.nextInt();
  26.        
  27.         int totalWaterMelons = 0;
  28.         int totalMelons = 0;
  29.        
  30.         while (howManyDays > 0) {
  31.             if (startDay > 7) {
  32.                 startDay = 1;
  33.             }
  34.             totalWaterMelons += Days.values()[startDay-1].waterMelons;
  35.             totalMelons += Days.values()[startDay-1].melons;
  36.            
  37.             startDay++;
  38.            
  39.             howManyDays--;
  40.         }
  41.        
  42.         if (totalWaterMelons > totalMelons) {
  43.             System.out.printf("%d more watermelons", totalWaterMelons - totalMelons);
  44.         }
  45.         else if (totalMelons > totalWaterMelons) {
  46.             System.out.printf("%d more melons", totalMelons - totalWaterMelons);
  47.         }
  48.         else {
  49.             System.out.printf("Equal amount: %d", totalWaterMelons);
  50.         }
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement