Write a method called power the computes x^n where x and n and positive integers
ID: 3805910 • Letter: W
Question
Write a method called power the computes x^n where x and n and positive integers. The method has two integer parameters and returns a value of type long. Create a class named Appointment that contains instance variables startTime, endTime, dayOfWeek (valid values arc 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. Create a Java class named Book with instance variables title, author, ISBN, and yearPublished. Include javadoc style comments to describe your interface. Such a class would normally have methods, but you are not required to supply any methods. Add accessor and mutator methods to the Book class created in question #13. Add a constructor and a copy constructor to the Book class created in question #13.Explanation / Answer
18)
19)
import Date.*;
import Time.*;
public class Appointment
{
private String appointed;
private int year;
private int month;
private int day;
private int hours;
private int minutes;
private int seconds;
public Appointment(int year, int month, int day, int hours, int minutes, String location, String appointed, String purpose) throws Exception
{
Date date = new Date(year, month, day);
Time time = new Time(hours, minutes);
this.year = year;
this.month = month;
this.day = day;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.appointed = appointed;
}
public Appointment() throws Exception
{
Date date = new Date();
Time time = new Time();
this.year = year;
this.month = month;
this.day = day;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.appointed = appointed;
}
public void setDate (int year, int month, int day) throws Exception
{
Date date = new Date(year, month, day);
this.year = year;
this.month = month;
this.day = day;
return;
}
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public String getTime()
{
String result; //String representation of a Date
result = "Hour=" + hours + "minutes=" + minutes;
return result;
}
public void setTime (int hours, int seconds)throws Exception
{
Time time = new Time(hours, minutes);
this.hours = hours;
this.minutes = minutes;
return;
}
public String getAppointed()
{
return appointed;
}
public String toString()
{
return "The appointment is on:" + day + "/" + month + "/" + year + "at " + hours + ":" + minutes + " in: " + location + " with " + appointed + " scheduled for " + purpose;
}
public int compareTo(Date otherDate)
{
if (getYear() != (otherDate.getYear()))
return getYear() - (otherDate.getYear());
else if (getMonth() != (otherDate.getMonth()))
return getMonth() - (otherDate.getMonth());
else
return getDay() - (otherDate.getDay());
}
public static void main (String[]args) throws Exception
{
int comparisonResult;
Appointment aAppt = new Appointment(2017, 5, 2, 11, 40, "Dr Swati");
Appointment bAppt = new Appointment(2017, 3, 3, 12, 42, "Dr Swati");
Appointment cAppt = new Appointment(2017, 7, 2, 1, 42, "Dr Swati");
System.out.println("The appointment info : " + aAppt);
System.out.println("The appointment info : " + bAppt);
comparisonResult = aAppt.compareTo(bAppt);
if (comparisonResult == 0)
System.out.println(aAppt + "is equal to" + bAppt);
else if (comparisonResult < 0)
System.out.println(aAppt + "is less than" + bAppt);
else
System.out.println(aAppt + "is greater than" + bAppt);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.