Comment this program using Javadoc: import java.io.PrintStream; import java.util
ID: 3674715 • Letter: C
Question
Comment this program using Javadoc:
import java.io.PrintStream;
import java.util.Scanner;
public class ScheduleTime {
private int Hour;
private int Minute;
private String Period;
public ScheduleTime() {
Hour = 0;
Minute = 0;
Period = "AM";
}
public int getHour() {
return Hour;
}
public void setHour(int hour) {
Hour = hour;
}
public int getMinute() {
return Minute;
}
public void setMinute(int minute) {
Minute = minute;
}
public String getPeriod() {
return Period;
}
public void setPeriod(String period) {
Period = period;
}
public void Write(PrintStream ps) {
ps.println(Hour);
ps.println(Minute);
ps.println(Period);
}
public void Read(Scanner s) {
s.useDelimiter("\s+| ");
Hour=Integer.parseInt(s.next());
Minute=Integer.parseInt(s.next());
// s.nextLine();
Period=s.next();
}
public String GetJSON() {
return "{"hour: "" + Hour + ", "minute: "" + Minute + ", "period: "" + Period + ""}";
}
@Override
public String toString() {
if (Minute < 10)
return Hour + ":" + "0" + Minute + Period;
else
return Hour + ":" + Minute + Period;
}
}
Explanation / Answer
1)Java Documentation Comments(Javadoc):This is used to generate API documentation in the HTML format from Java Source code.This will give the information about the class (or) prupose,information about the methods etc.
2)We can represent the Javadoc comments using :
/**
Between this we can write the infomation Regarding the class or methodor variables.
*/
3)we can generate the API documentation in HTML format by using the commnd:
javadoc ScheduleTime.java
----------------------------------------------------------------
ScheduleTime.java
import java.io.PrintStream;
import java.util.Scanner;
/**
* ScheduleTime Model Object. This class is used to read the Hour, Minute and period supplied and prints.
* <P>Various attributes of ScheduleTime, and related behaviour.
* @author name.
* @version 1.0.
*/
public class ScheduleTime {
/**
* Hour in Time.
*/
private int Hour;
/**
* Minute in Time.
*/
private int Minute;
/**
* period in Time.
*/
private String Period;
/**
* Constructor.
* Which is used to set the initial values to instance variables.
*/
public ScheduleTime() {
Hour = 0;
Minute = 0;
Period = "AM";
}
/**
* Hour in time.
*
* @return The hour value.
*/
public int getHour() {
return Hour;
}
/**
* This is a setter which sets the hour.
* @param hour - the hour to be set.
*/
public void setHour(int hour) {
Hour = hour;
}
/**
* Minute in time.
*
* @return The Minute value .
*/
public int getMinute() {
return Minute;
}
/**
* This is a setter which sets the minute.
* @param minute - the minute to be set.
*/
public void setMinute(int minute) {
Minute = minute;
}
/**
* Period in time.
*
* @return The Period value .
*/
public String getPeriod() {
return Period;
}
/**
* This is a setter which sets the period.
* @param period - the period to be set.
*/
public void setPeriod(String period) {
Period = period;
}
/**
* This is a method which is used to Display Hour,Minute,Period.
* @param Print stream ps, Here this print stream contains Hour,Minute,Period.
* @return Nothing.
*/
public void Write(PrintStream ps) {
ps.println(Hour);
ps.println(Minute);
ps.println(Period);
}
/**
* This is a method which is used to Read the inputs values from the keyboard.
* @param Scanner S, This will read the values from KeyBoard.
* @return Nothing.
*/
public void Read(Scanner s) {
s.useDelimiter("\s+| ");
Hour=Integer.parseInt(s.next());
Minute=Integer.parseInt(s.next());
// s.nextLine();
Period=s.next();
}
/**
* @return a JSON object as a string.
*/
public String GetJSON() {
return "{"hour: "" + Hour + ", "minute: "" + Minute + ", "period: "" + Period + ""}";
}
/**
* This is a method Which is used to display the data inside the object.
* <p>
* Implementing toString method in java is done by overriding the Object's toString method.
* The java toString() method is used when we need a string representation of an object.
* This method can be overridden to customize the String representation of the Object.
* </p>
* If the condition satisfies if Minute value<10.
* @return The string representation.
*/
@Override
public String toString() {
if (Minute < 10)
return Hour + ":" + "0" + Minute + Period;
else
return Hour + ":" + Minute + Period;
}
}