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

Java Create a class named Appointment that stores information about appointments

ID: 3827082 • Letter: J

Question

Java

Create a class named Appointment that stores information about appointments. All times are military or 24 hour times. So 1:00 am is 100, and 1:00pm is 1300. The class must ensure that startTime and endTime instance variables are within the valid range of times (0 – 2359). If an invalid time is passed to the object, assign the time to -1 and print the following error message: Invalid time: the time must be between 0 and 2359.

Create a class named AppointmentTester that tests the Appointment class created in the previous question. The code must contain a main method and perform the following.

Create an object using the default constructor.

Create an object using the parameterized constructor.

Call both mutator methods.

Call the accessor method and printout that value.

Call the toString method and printout that value.

Explanation / Answer

Answer:)

programme to appointement to using militaty time:

import java.io.IOException;

public class Appointement

{

   private int hour;

   private int minute;

   public Appointement()

      {

          hour=0;

          minute=0;

      }

public Appointement(int h,int m)

{

     if(h>1&&h<23)

        hour=h;

   else

       hour=0;

      if(m>=0&&m<=59)

        minute=m;

      else

         minute=0;

}

public String toString()

{

   if(hour<10&&minute<10)

     s="0"+hour+"0"+minute;

else if(hour<10&&minute>10)

      s="0"+hour+minute;

   else if(hour>10&&minute<10)

       s=hour+"0"+minute;

    else if(hour>10&&minute>10)

        s=hour+""+minute;

     else if(hour==0)

        s="0"+hour+minute;

     else if(minute==0)

         s=hour+"0"+minute;

      return s;

}

public String convert()

{

   String c="";

    if(hour>11)

     {

        if(hour==12)

         {

            c=hour+":"+minute+"PM";

          }

       if (hour>12)

         {

           c=(hour+12)+":"+minute+"AM";

         }

          else

            c=hour+":"+minute+"AM";

            if(minute<10)

              {

                 c=c.substring(0,c.length()-4)+"0"+minute+" "+c.substring(c.length()-2,c.length());

               }

          return c;

         public void increment()

          {

            if(hour==23&&minute==59)

               {

                  hour=0;

                   minute=0;

               }

               else

                 {

                    minute++;

                    if(minute==60)

                    {

                      hour++;

                      minute=0;

                   }

                  else if (hour==24)

                     hour=0;

               }

}

public static void main(String str[]) throws IOException

{

    Appointement time1=new Appointement(14,56);

    System.out.println("time1:"+time1);

    System.out.println("convert time1 to standard time :"+ time1.convert());

     System.out.println("time1:"+time1);

     System.out.println("increment time1 five times:");

      time1.increment();

       time1.increment();

      time1.increment();

      time1.increment();

      time1.increament();

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

      Appointement time2=new appointement(-7,12);

      System.out.println("time2:"+time2);

      System.out.println("increment time2 67 times:");

      for(int i=0;i<67;i++)

        time2.increment();

       System.out.println(time2);

        System.out.println("Convert to time2 standard time: "+ time2.convert());

        System.out.println("time2:"+time2+" ");

        Appointement time3=new Appointement(5,1);

        System.out.println("time3:"+time3);

       System.out.println("convert time3:");

      System.out.println(time3.convert());

       Appointement time4=new Appointement(12,15);

         System.out.println(" time4:"+time4);

         System.out.println("Convert time4:"+time4.convert());

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote