mstoyanova

Untitled

Mar 2nd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package com.Exam;
  2.  
  3. import java.text.ParseException;
  4.  
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.Scanner;
  8.  
  9. public class BeerTime {
  10.     public static void main(String[] args) throws ParseException {
  11.         Scanner scanner = new Scanner(System.in);
  12.         String input = scanner.nextLine();
  13.         try {
  14.             SimpleDateFormat format = new SimpleDateFormat("hh:mm a");
  15.             Date d1;
  16.             d1 = format.parse(input);
  17.             String start = "1:00 PM ";
  18.             String end = "3:00 AM ";
  19.  
  20.             Date startTime = format.parse(start);
  21.             Date endTime = format.parse(end);
  22.  
  23.             if (d1.after(endTime) && d1.before(startTime)) {
  24.                 System.out.println("non-beer time");
  25.             } else {
  26.                 System.out.println("beer time");
  27.             }
  28.  
  29.         } catch (Exception e) {
  30.             System.out.println("invalid time");
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment