Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clock;
- public class clock {
- private int hour;
- private int minute;
- private final int MAX_HOUER = 24;
- private final int MAXMINUTE = 60;
- public clock(int hour, int minute) throws Exception {
- hour(hour);
- minute(minute);
- }
- public void hour(int hour) throws Exception {
- if (hour < 0 || hour > MAX_HOUER) {
- throw new Exception("PLESE HOUERS HAVE TO BE BETWEEN 0-23");
- }
- this.hour = hour;
- }
- public void minute(int minute) throws Exception {
- if (minute < 0 || minute > MAXMINUTE) {
- throw new Exception("PLESE minute HAVE TO BE BETWEEN 0-23");
- }
- this.minute = minute;
- }
- public int getHour() {
- return hour;
- }
- public int getMinute() {
- return minute;
- }
- @Override
- public String toString() {
- return "the time is "+
- + hour +"" +
- ":"
- + this.minute;
- }
- }
- package main;
- import clock.clock;
- import java.util.Scanner;
- public class test {
- public static void main(String[] args) {
- Scanner s= new Scanner(System.in);
- clock c;
- boolean check=false;
- while (!check){
- try{
- System.out.println("please enter houers and minuts");
- c = new clock(s.nextInt(), s.nextInt());
- System.out.println(c);
- check=true;
- }
- catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement