Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package clock;
  2. public class clock {
  3.     private int hour;
  4.     private int minute;
  5.     private final int MAX_HOUER = 24;
  6.     private final int MAXMINUTE = 60;
  7.     public clock(int hour, int minute) throws Exception {
  8.         hour(hour);
  9.         minute(minute);
  10.     }
  11.  
  12.     public   void hour(int hour) throws Exception {
  13.         if (hour < 0 || hour > MAX_HOUER) {
  14.             throw new Exception("PLESE HOUERS HAVE TO BE BETWEEN 0-23");
  15.         }
  16.         this.hour = hour;
  17.     }
  18.  
  19.  
  20.     public  void minute(int minute) throws Exception {
  21.         if (minute < 0 || minute > MAXMINUTE) {
  22.             throw new Exception("PLESE minute HAVE TO BE BETWEEN 0-23");
  23.         }
  24.         this.minute = minute;
  25.     }
  26.  
  27.     public int getHour() {
  28.         return hour;
  29.     }
  30.  
  31.     public int getMinute() {
  32.         return minute;
  33.     }
  34.  
  35.     @Override
  36.     public String toString() {
  37.         return "the time is    "+
  38.                 + hour +"" +
  39.                 ":"
  40.                 + this.minute;
  41.     }
  42. }
  43.  
  44.  
  45.  
  46. package main;
  47. import clock.clock;
  48.  
  49. import java.util.Scanner;
  50.  
  51. public class test {
  52.     public static void main(String[] args) {
  53.         Scanner s= new Scanner(System.in);
  54.         clock c;
  55.         boolean check=false;
  56.  
  57.         while (!check){
  58.             try{
  59.                 System.out.println("please enter houers and minuts");
  60.                 c = new clock(s.nextInt(), s.nextInt());
  61.                 System.out.println(c);
  62.                 check=true;
  63.             }
  64.  
  65.             catch  (Exception e) {
  66.                 System.out.println(e.getMessage());
  67.             }
  68.         }
  69.  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement