Create a class named Appointment that contains instance variables startTime, endTime, dayOfWeek (valid values are Sunday through Saturday), and a date which consists of a month, day and year. All times should be in military time, therefore it is appropriate to use integers to represent the time. Create the appropriate accessor and mutator methods.
What will be an ideal response?
```
public class Appointment
{
private int startTime;
private int endTime;
private String dayOfWeek;
private String month;
private int day;
private int year;
/** Mutator methods */
public void setStartTime(int st)
{
/** valid range for military time is 0-2400 */
if((st >= 0) && (st <= 2400))
startTime = st;
}
public void setEndTime(int et)
{
/** valid range for military time is 0-2400 */
if((et >= 0) && (et <= 2400))
endTime = et;
}
public void setDayOfWeek(String dow)
{
/** Valid values are the strings Sunday – Saturday */
if(checkDayOfWeek(dow))
dayOfWeek = dow;
else
System.out.println("Fatal error....invalid day of week value!");
}
public void setMonth(String m)
{
/** Valid values are strings January – December */
if(checkMonth(m))
month = m;
else
System.out.println("Fatal error...invalid month value!");
}
public void setDay(int d)
{
/** Valid days in a date are the integers 1 – 31 */
if((d >= 1) && (d <= 31))
day = d;
}
public void setYear(int y)
{
if(y >= 0)
year = y;
}
/** Accessor methods */
public int getStartTime()
{
return startTime;
}
public int getEndTime()
{
return endTime;
}
public String getDayOfWeek()
{
return dayOfWeek;
}
public String getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
/** Facilitator methods */
private boolean checkDayOfWeek(String d)
{
if(d.equalsIgnoreCase("Sunday") || d.equalsIgnoreCase("Monday") ||
d.equalsIgnoreCase("Tuesday") || d.equalsIgnoreCase("Wednesday") ||
d.equalsIgnoreCase("Thursday") || d.equalsIgnoreCase("Friday") ||
d.equalsIgnoreCase("Saturday") || d.equalsIgnoreCase("Sunday"))
return true;
else
return false;
}
private boolean checkMonth(String month)
{
if(month.equalsIgnoreCase("January") || month.equalsIgnoreCase("February") ||
month.equalsIgnoreCase("March") || month.equalsIgnoreCase("April") ||
month.equalsIgnoreCase("May") || month.equalsIgnoreCase("June") ||
month.equalsIgnoreCase("July") || month.equalsIgnoreCase("August") ||
month.equalsIgnoreCase("September") ||
month.equalsIgnoreCase("October") ||
month.equalsIgnoreCase("November") || month.equalsIgnoreCase("December"))
return true;
else
return false;
}
}
```
You might also like to view...
In a dual axis chart, a secondary horizontal axis is used to reflect the value series
Indicate whether the statement is true or false.
Compromised computers attached to the Internet, which are often used to remotely perform malicious or criminal tasks, are called ________
Fill in the blank(s) with the appropriate word(s).