Time Test java Eclipse Search Project Run Window Help imel java imel Test. This
ID: 3795572 • Letter: T
Question
Time Test java Eclipse Search Project Run Window Help imel java imel Test. This Test,java Time2 java D Time2Test, 'uab4Time2gava java public class Time2T est e public static void main(String[] args) Tine 2 t1 new Time 20 Time t2 new Time2(2) Time2 t3 new Time2(21, 34) Tine 2 t4 new Time2(12, 25, 42) Time2 t5 a new Tine (t4); Systen out.println( Constructed with:"); display Time("t1: all default arguments", t1); display Time ("t2: hour specified default minute and second t2); display Time ("t3: hour and minute specified; default second t3); display Time("t41 hour, minute and second specified t4); display Tine "t5: Times object t4 specified", t5); try Time2 t6 new Time2(27, 74, 99); catch (IllegalArgumentException e) System.out.printf("NnException while initializing te: Ksin", e get Message()); private static void displayTine(string header, Tine2 t) System out. printf("%sin *s%n *sin header t.touniversalstringo, t.tostringo))i Problems D console consoles to display at this
Explanation / Answer
As you have not shared your Time2.java I created mine
public class Time2
{
private int hour;
private int minute;
private int seconds;
public Time2(int hour)
{
this(hour, 0, 0);
}
public Time2(int hour, int minute)
{
this(hour, minute, 0);
}
public Time2(Time2 obj)
{
this(obj.getHour(), obj.getMinute(), obj.getSeconds());
}
public Time2(int hour, int minutes, int seconds)
{
this.hour = hour;
this.minute = minutes;
this.seconds = seconds;
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public int getSeconds() {
return seconds;
}
@Override
public String toString() {
return hour + ":" + minute + ":" + seconds;
}
}
// here is Lab4Time2.java
public class Lab4Time2 {
public static void main(String[] args)
{
Time2 brakfastTime = new Time2(6);
System.out.println("breakfast time is : " + brakfastTime);
Time2 lunchTime = new Time2(12,30);
System.out.println("lunch time is : " + lunchTime);
Time2 xy = new Time2(20, 25, 15);
Time2 dinnerTime = new Time2(xy);
System.out.println("dinner time is : " + dinnerTime);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.