import java.util.Scanner; import java.util.*; public class Grade5{ public static void main(String args[]){ Scanner input=new Scanner(System.in); System.out.print("To run Test i.j, type in the values of i and j: "); int choice=input.nextInt(); int choice2=input.nextInt(); Moment def = new Moment(); Moment am = new Moment(1,1,1943,9,34,32,false); Moment noon = new Moment(3,6,2343,12,0,0,true); Moment pm = new Moment(5,12,2013,4,30,20,true); Moment midnight = new Moment(3,6,1985,12,0,0,false); Moment illegal = new Moment(12, 30, 1800, 4, 44, 60, true); Moment illegal2 = new Moment(2, 29, 2500, 3, 35, 10, false); Moment test = new Moment(); //used for comparison - reset //getHour if (choice==1){ if (choice2==1){//default System.out.println("Test 1.1 - get default hour (2pts)"); System.out.println(def.getHour()); } else if (choice2==2){//AM System.out.println("Test 1.2 - get am hour (2pts)"); System.out.println(am.getHour()); } else if (choice2==3){//PM System.out.println("Test 1.3 - get pm hour (2pts)"); System.out.println(pm.getHour()); } } //getHourMilitary else if (choice==2){ if (choice2==1){//default System.out.println("Test 2.1 - get default military hour (1pt)"); System.out.println(def.getHourMilitary()); } else if (choice2==2){//<12 System.out.println("Test 2.2 - military hour <12 (1pt)"); System.out.println(am.getHourMilitary()); } else if (choice2==3){//12 System.out.println("Test 2.3 - military hour =12 (1pt)"); System.out.println(noon.getHourMilitary()); } else if (choice2==4){//>12 System.out.println("Test 2.4 - military hour >12 (1pt)"); System.out.println(pm.getHourMilitary()); } else if (choice2==5){//24 System.out.println("Test 2.5 - military hour =0 (1pt)"); System.out.println(midnight.getHourMilitary()); } } //getMinute else if (choice==3){ if (choice2==1){//default System.out.println("Test 3.1 - get def minute (2pts)"); System.out.println(def.getMinute()); } else if (choice2==2){//legal System.out.println("Test 3.2 - get am minute (2pts)"); System.out.println(am.getMinute()); } } //getSecond else if (choice==4){ if (choice2==1){//default System.out.println("Test 4.1 - get def second (2pts)"); System.out.println(def.getSecond()); } else if (choice2==2){//legal System.out.println("Test 4.2 - get am second (2pts)"); System.out.println(am.getSecond()); } } //getPM else if (choice==5){ if (choice2==1){//default System.out.println("Test 5.1 - get def pm/am (1pt)"); System.out.println(def.getPM()); } else if (choice2==2){//AM System.out.println("Test 5.2 - get am pm/am (1pt)"); System.out.println(am.getPM()); } else if (choice2==3){//noon System.out.println("Test 5.3 - get noon pm/am (1pt)"); System.out.println(noon.getPM()); } else if (choice2==4){//PM System.out.println("Test 5.4 - get pm pm/am (1pt)"); System.out.println(pm.getPM()); } } //isLegal else if (choice==6){ if (choice2==1){//default System.out.println("Test 6.1 - def isLegal (1pt)"); System.out.println(def.isLegal()); } else if (choice2==2){//2/29/2500 illegal System.out.println("Test 6.2 - 2/29/2500 isLegal (2pts)"); System.out.println(illegal2.isLegal()); } else if (choice2==3){ //second =60 illegal System.out.println("Test 6.3 - second = 60 isLegal (1pt)"); System.out.println(illegal.isLegal()); } else if (choice2==4){//hour =24 illegal illegal = illegal = new Moment(12, 30, 1800, 24, 44, 45, true); System.out.println("Test 6.4 - hour = 24 isLegal (1pt)"); System.out.println(illegal.isLegal()); } else if (choice2==5){//legal System.out.println("Test 6.5 - legal isLegal (4pts)"); System.out.println(noon.isLegal()); } } //secondsUntil else if (choice==7){ if (choice2==1){ //equal dates System.out.println("Test 7.1 - secondsUntil same date (1pt)"); test = new Moment(1,1,1943,9,34,3,false); //comparison date System.out.println(am.secondsUntil(test)); } else if (choice2==2){//seconds < seconds2 System.out.println("Test 7.2 - secondsUntil, first < second (1pt)"); test = new Moment(1,11,1942,8,34,2,false); System.out.println(test.secondsUntil(am)); } else if (choice2==3){//seconds > seconds2 System.out.println("Test 7.3 - secondsUntil, first > second (1pt)"); test = new Moment(1,1,1942,9,39,10,false); System.out.println(am.secondsUntil(test)); } else if (choice2==4){//first date illegal System.out.println("Test 7.4 - first date illegal (2pts)"); System.out.println(illegal.secondsUntil(am)); } } //minutesUntil else if (choice==8){ if (choice2==1){//minutes equal System.out.println("Test 8.1 - minutesUntil same date (1pt)"); test = new Moment(5,12,2013,4,39,20,true); System.out.println(pm.minutesUntil(test)); } else if (choice2==2){//minutes< minutes 2 System.out.println("Test 8.2 - minutesUntil, first < second (1pt)"); test = new Moment(3,12,2013,3,1,20,true); System.out.println(test.minutesUntil(pm)); } else if (choice2==3){//minutes > minutes2 System.out.println("Test 8.3 - minutesUntil, first > second (1pt)"); test = new Moment(3,11,2013,4,58,20,true); System.out.println(pm.minutesUntil(test)); } else if (choice2==4){// 30 seconds between System.out.println("Test 8.4 - minutesUntil, 30 second diff (1pt)"); test = new Moment(5,12,2012,5,29,50,true); System.out.println(test.minutesUntil(pm)); } } //hoursUntil else if (choice==9){ if(choice2==1){//equal dates System.out.println("Test 9.1 - hoursUntil same date (1pt)"); test = new Moment(3,6,2343,5,0,0,true); System.out.println(noon.hoursUntil(test)); } else if (choice2==2){//hourshours2 System.out.println("Test 9.3 - hoursUntil, first > second (1pt)"); test = new Moment(9,2,2343,5,50,20,true); System.out.println(test.hoursUntil(noon)); } else if (choice2==4){//30 minutes between System.out.println("Test 9.4 - hoursUntil, 30 min diff (1pt)"); test = new Moment(7,3,2344,12,30,0,false); System.out.println(noon.hoursUntil(test)); } else if (choice2==5){//second date illegal System.out.println("Test 9.5 - second date illegal (2pts)"); System.out.println(pm.hoursUntil(illegal)); } } //compareTo else if (choice==10){ if (choice2==1){//equal dates System.out.println("Test 10.1 - equal dates compareTo (4pts)"); test = new Moment(5,12,2013,4,30,20,true); System.out.println(test.compareTo(pm)); } else if (choice2==2){//seconds < seconds2 System.out.println("Test 10.2 - compareTo first < second by seconds (1pt)"); test = new Moment(5,12,2013,4,30,47,true); System.out.println(pm.compareTo(test)); } else if (choice2==3){//minutes > minutes2 System.out.println("Test 10.3 - comapreTo first > second by minutes (1pt)"); test = new Moment(5,12,2013,4,2,20,true); System.out.println(pm.compareTo(test)); } else if (choice2==4){//hours > hours2 System.out.println("Test 10.4 - compareTo first > second by hours (1pt)"); test = new Moment(5,12,2013,10,30,20,true); System.out.println(test.compareTo(pm)); } else if (choice2==5){//AM vs PM System.out.println("Test 10.5 - compareTo same date, AM vs PM (1pt)"); test = new Moment(5,12,2013,4,30,20,false); System.out.println(test.compareTo(pm)); } } //toString else if (choice==11){ if (choice2==1){//default System.out.println("Test 11.1 - def toString (1 works - 1 perfect)"); System.out.println(def); } else if (choice2==2){//AM System.out.println("Test 11.2 - am toString (1 works - 1 perfect)"); System.out.println(am); } else if (choice2==3){//PM System.out.println("Test 11.3 - pm toString (1 works - 1 perfect)"); System.out.println(pm); } } else if (choice==12){ //test the Moment(MomentInterface) construtor System.out.println("Test 12 copy constructor (5 pts)"); Moment copy = new Moment(pm); System.out.println(copy); } System.out.println(); } }