Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA second semester course > Create a new class called Concert.java based on th

ID: 3661954 • Letter: J

Question

JAVA second semester course

> Create a new class called Concert.java based on the class diagram below

- 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

******************************************************************************************************

package l02review;

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");
   }

}

Concert

- name : String

- startTime : Time

- endTime : Time

+ <<constructor>> Concert ( n : String, start : Time , end : Time)

+ toString () : String

Explanation / Answer

public class concert extends Time

{      String name; // name

      Time startTime; // start time given here

                Time endTime;// end time given here

   public:

                              concert(String n, Time start,Time end)

{ name=n;

startTime=start;

endTime=end;

}

public String toString

{ return String.format("%02d:%02d:%02d", name, startTime, endTime);

}

}

class ConcertApp

{

public static void main(String args[])

{ concert c= new concert("paul","20","100"); // constructor initiated

                                string p= c.toString();

System.out.println("    " +p);

}

}