Comment this code using javadoc. package.bcs345.hwk.schedule.presentation; impor
ID: 3698107 • Letter: C
Question
Comment this code using javadoc.
package.bcs345.hwk.schedule.presentation;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import javax.swing.JFileChooser;
import desroches.bcs345.hwk.schedule.business.Appointment;
public class AppointmentConsoleUI {
@SuppressWarnings("resource")
public void ShowUI() {
Appointment appt = new Appointment();
Scanner scan = new Scanner(System.in);
char option;
while (true) {
System.out.println(" Appointment UI");
System.out.println("----------------");
System.out.println("1 - Read appt from file");
System.out.println("2 - Write appt to file");
System.out.println("3 - Show appt date on screen");
System.out.println("4 - Show appt time on screen");
System.out.println("5 - Show appt JSON string on screen");
System.out.println("6 - Show all appt data on screen");
System.out.println("7 - Exit");
System.out.print(" Enter choice: ");
option = scan.nextLine().charAt(0);
switch (option) {
case '1':
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Load which file?");
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
Scanner s;
try {
s = new Scanner(chooser.getSelectedFile());
appt.Read(s);
s.close();
} catch (FileNotFoundException e) {
System.err.println("File not found. ");
break;
}
} else
System.out.println("File selection canceled. ");
break;
case '2':
chooser = new JFileChooser();
chooser.setDialogTitle("Save to file?");
result = chooser.showSaveDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
try {
PrintStream ps = new PrintStream(chooser.getSelectedFile());
appt.Write(ps);
ps.close();
} catch (FileNotFoundException e) {
System.err.println("File not found. ");
break;
}
} else
System.out.println("File selection canceled. ");
break;
case '3':
System.out.println(appt.getDate());
break;
case '4':
System.out.println(appt.getTime());
break;
case '5':
System.out.println(appt.GetJSON());
break;
case '6':
System.out.println(appt);
break;
case '7':
return;
default:
System.err.println("Invalid option.");
}
}
}
}
Explanation / Answer
/* comments are added to this java program
using javadoc*/
package.bcs345.hwk.schedule.presentation;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import javax.swing.JFileChooser;
import desroches.bcs345.hwk.schedule.business.Appointment;
public class AppointmentConsoleUI {
@SuppressWarnings("resource")
/* this method is used to show the user interface
@param
@return no value */
public void ShowUI() {
Appointment appt = new Appointment();
Scanner scan = new Scanner(System.in);
char option;
while (true) {
System.out.println(" Appointment UI");
System.out.println("----------------");
System.out.println("1 - Read appt from file");
System.out.println("2 - Write appt to file");
System.out.println("3 - Show appt date on screen");
System.out.println("4 - Show appt time on screen");
System.out.println("5 - Show appt JSON string on screen");
System.out.println("6 - Show all appt data on screen");
System.out.println("7 - Exit");
System.out.print(" Enter choice: ");
option = scan.nextLine().charAt(0);
switch (option) {
case '1':
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Load which file?");
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
Scanner s;
try {
s = new Scanner(chooser.getSelectedFile());
appt.Read(s);
s.close();
}@throws
catch (FileNotFoundException e) {
System.err.println("File not found. ");
break;
}
} else
System.out.println("File selection canceled. ");
break;
case '2':
chooser = new JFileChooser();
chooser.setDialogTitle("Save to file?");
result = chooser.showSaveDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
try {
PrintStream ps = new PrintStream(chooser.getSelectedFile());
appt.Write(ps);
ps.close();
} @throws
catch (FileNotFoundException e) {
System.err.println("File not found. ");
break;
}
} else
System.out.println("File selection canceled. ");
break;
case '3':
System.out.println(appt.getDate());
break;
case '4':
System.out.println(appt.getTime());
break;
case '5':
System.out.println(appt.GetJSON());
break;
case '6':
System.out.println(appt);
break;
case '7':
return;
default:
System.err.println("Invalid option.");
}
}
}