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...
To set the stopping point for a radial gradient to the corner closest to the gradient's center, use the keywords ____.
A. closest-side: B. closest-corner: C. farthest-side: D. farthest-corner:
Define a class named Employee whose objects are records for employees. Derive this class from the class Person given in Listing 8.1. An employee record inherits an employee’s name from the class Person. In addition, an employee record contains an annual salary represented as a single value of type double, a hire date that gives the year hired as a single value of type int, and an identification number that is a value of type String. Give your class a reasonable complement of constructors, accessor methods, and mutator methods, as well as an equals method. Write a program to fully test your class definition.
This project should be pretty straightforward. The solution shown here has nine constructors, including a default that specifies nothing. Since it did not seem reasonable to have salary, hire date or social security numbers without a name, the remaining constructors all require at least the name to be specified. Note the use of methods from the base class, Person. For example, super.writeOutput()is used to write just the name (and avoid using the local version in Employee that writes out all the parameters).
You want to scale a graphic frame, maintaining the position of its lower-right corner—that is, that point should remain where it is and the left and top edges should move. What should you do?
What will be an ideal response?
If you manufacture potato chips that are sold by weight, not by volume, would you want a small standard deviation or a large standard deviation in your quality control measurements? Give a reason for your answer.
A. I would want the small standard deviation in my quality control measurements because large deviations of weight of chips are not profitable. B. I would want the small standard deviation in my quality control measurements because for good quality, it is important that the weight of chips not be much smaller from their advertised weight. C. I would want the large standard deviation in my quality control measurements because for good quality, it is important that the weight of chips be smaller or larger than their advertised weight. D. I would want the large standard deviation in my quality control measurements because large deviations of the weight of chips are profitable. E. None of these.