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

public class MyDateTime { static int hr,min,sec,year,day,month; public MyDateTim

ID: 3848656 • Letter: P

Question

public class MyDateTime {

static int hr,min,sec,year,day,month;

public MyDateTime()
{
hr=0;
min=0;
sec=0;
year=0;
day=0;
month=0;
}

public MyDateTime(int m,int d,int y,int h,int mn,int s)
{
hr=h;
min=m;
sec=s;
year=y;
day=d;
month=mn;
}
public void setMonth(int a) {
month = a;
}
public int getMonth() {
return month;
}
public void setDay(int b) {
day = b;
}
public int getDay() {
return day;
}
  
public void setYear(int c) {
year = c;
}
public int getYear() {
return year;
}
  
  
public void setHour(int d) {
hr = d;
}
public int getHour() {
return hr;
}
  
public void setMinute(int e) {
min = e;
}
public int getMinute() {
return min;
}
public void setSecond(int f) {
sec = f;
}
public int getSecound() {
return sec;
}
public static String toString(int i)
{
return " "+i;
}

public static void display()
{
System.out.println("Month:"+toString(month));
System.out.println("Day:"+toString(day));
System.out.println("Year:"+toString(year));
System.out.println("Hour:"+toString(hr));
System.out.println("Minute:"+toString(min));
System.out.println("Second:"+toString(sec));
}
}

Need some help with containment, the question reads as follows. Build a class called Appointment.java. This class should have the following properties: patientId, dentistId, datetime, and procCode. The datetime property should use the MyDateTime class (I have the code above) that you built. Also add appropriate set and get methods, display method, toString method and mainmethod. Main() should be used to test this class. Also, add 2 constructors that take all arguments. Lastly, in the main() method, instantiate an Appointment object by calling the constructor that takes all 4 arguments, then call the display method to display the data.

Main Testing Code =

Appointment a1;

a1 = newAppointment("A901","D201", new MyDateTime(7, 1, 2017, 9, 0, 0), "P114");

a1.display();

Explanation / Answer

below is your program. I have to change the constructor of MyDateTime a little, as minute was assigned to month and viceversa. Please note that.

Below are your classes.

MyDateTime.java


public class MyDateTime {
   static int hr, min, sec, year, day, month;

   public MyDateTime() {
       hr = 0;
       min = 0;
       sec = 0;
       year = 0;
       day = 0;
       month = 0;
   }

   public MyDateTime(int m, int d, int y, int h, int mn, int s) {
       hr = h;
       min = mn;
       sec = s;
       year = y;
       day = d;
       month = m;
   }

   public void setMonth(int a) {
       month = a;
   }

   public int getMonth() {
       return month;
   }

   public void setDay(int b) {
       day = b;
   }

   public int getDay() {
       return day;
   }

   public void setYear(int c) {
       year = c;
   }

   public int getYear() {
       return year;
   }

   public void setHour(int d) {
       hr = d;
   }

   public int getHour() {
       return hr;
   }

   public void setMinute(int e) {
       min = e;
   }

   public int getMinute() {
       return min;
   }

   public void setSecond(int f) {
       sec = f;
   }

   public int getSecound() {
       return sec;
   }

   public static String toString(int i) {
       return " " + i;
   }

   public static void display() {
       System.out.println("Month:" + toString(month));
       System.out.println("Day:" + toString(day));
       System.out.println("Year:" + toString(year));
       System.out.println("Hour:" + toString(hr));
       System.out.println("Minute:" + toString(min));
       System.out.println("Second:" + toString(sec));
   }
}

Appointment.java


public class Appointment {
   private String patientId;
   private String dentistId;
   private MyDateTime datetime;
   private String procCode;

   public Appointment(String patientId, String dentistId, MyDateTime datetime, String procCode) {
       this.patientId = patientId;
       this.dentistId = dentistId;
       this.datetime = datetime;
       this.procCode = procCode;
   }

   public Appointment() {
       this.datetime = new MyDateTime();
       this.procCode = "";
   }

   public String getPatientId() {
       return patientId;
   }

   public void setPatientId(String patientId) {
       this.patientId = patientId;
   }

   public String getDentistId() {
       return dentistId;
   }

   public void setDentistId(String dentistId) {
       this.dentistId = dentistId;
   }

   public MyDateTime getDatetime() {
       return datetime;
   }

   public void setDatetime(MyDateTime datetime) {
       this.datetime = datetime;
   }

   public String getProcCode() {
       return procCode;
   }

   public void setProcCode(String procCode) {
       this.procCode = procCode;
   }

   @Override
   public String toString() {
       return "Appointment [patientId=" + patientId + ", dentistId=" + dentistId + ", procCode=" + procCode + "]";
   }

   @SuppressWarnings("static-access")
   public void display() {
       System.out.println(this);
       System.out.println("Date and Time of Appointment: ");
       this.datetime.display();
   }
  
   public static void main(String[] args) {
       Appointment a1;
       a1 = new Appointment("A901","D201", new MyDateTime(7, 1, 2017, 9, 0, 0), "P114");
       a1.display();
   }

}

Sample Run

Appointment [patientId=A901, dentistId=D201, procCode=P114]
Date and Time of Appointment:
Month: 7
Day: 1
Year: 2017
Hour: 9
Minute: 0
Second: 0