I dont understand what they want me to do Download the class Time.java -Create a
ID: 638474 • Letter: I
Question
I dont understand what they want me to do
Download the class Time.java
-Create a new class called Concert.java based on the class diagram below
Concert
_________________
-name: String
-startTime:Time
-endTime:Time
_____________________
+<<constructor>> Concert (n:String,start: Time, end:Time)
+toString():String
Create a class called ConcertApp.java .
- This class includes the main method.
-Inside the main method create an instance of Concert. Initialize it with values of your choice.
-Print the newly created concert
public class Time
{
private int hours;
private int minutes;
private int seconds;
public Time(int h, int m, int s)
{
setTime(h, m, s);
}
public Time()
{
}
public void setHours(int h)
{
hours = ((h >= 0 && h < 24) ? h : 0);
}
public void setMinutes(int m)
{
minutes = ((m >= 0 && m < 60) ? m : 0);
}
public void setSeconds(int s)
{
seconds = ((s >= 0 && s < 60) ? s : 0);
}
public void setTime(int h, int m, int s)
{
setHours(h);
setMinutes(m);
setSeconds(s);
}
public String toMilitary()
{
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
@Override
public String toString()
{
return String.format("%d:%02d:%02d %s",
(hours == 0 || hours == 12) ? 12 : hours % 12, minutes,
seconds, (hours < 12) ? "AM" : "PM");
}
}
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Time
{
private int hours;
private int minutes;
private int seconds;
public Time(int h, int m, int s)
{
setTime(h, m, s);
}
public Time()
{
}
public void setHours(int h)
{
hours = ((h >= 0 && h < 24) ? h : 0);
}
public void setMinutes(int m)
{
minutes = ((m >= 0 && m < 60) ? m : 0);
}
public void setSeconds(int s)
{
seconds = ((s >= 0 && s < 60) ? s : 0);
}
public void setTime(int h, int m, int s)
{
setHours(h);
setMinutes(m);
setSeconds(s);
}
public String toMilitary()
{
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
@Override
public String toString()
{
return String.format("%d:%02d:%02d %s",
(hours == 0 || hours == 12) ? 12 : hours % 12, minutes,
seconds, (hours < 12) ? "AM" : "PM");
}
}
public class Concert extends Time{
public void Concert(String name, String startTime, String endTime){
System.out.println("Name of the concert: " + name);
System.out.println("Start time is :" + startTime);
System.out.println("End time is :" + endTime);
}
public static void main(String args[]){
String name="Linkin Park";
Time Start_time=new Time(10,30,00);
Time End_time=new Time(11,30,00);
Concert c=new Concert(name, Start_time.toString(), end_Time.toString());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.