CSC1110 Exercise 9
Generating Documentation using Chat-GPT
By now we have tried using Chat-GPT for a variety of tasks to assist us in getting our work done. One of the ways Chat-GPT can be especially useful is in writing documentation for our existing code.
We have had you write Javadoc comments for all of your public methods and classes, and IntelliJ does a good job of generating the necessary Javadoc annotations if you have completed the method before writing the docs. But what if you could get Chat-GPT to read your code and fill all of that in for you? Let’s give it a try!
Exercises
- Read through the following interface code and see if you can determine what each method should do. Write your own javadoc comments.
public interface Schedulable {
boolean isBusy(int day, int hour);
boolean add(Schedulable item);
boolean remove(Schedulable item);
String getName();
}
-
Ask Chat-GPT to write javadocs for this interface. Make sure your prompt tells GPT to be specific and gives detailed descriptions of the parameters and return values. Paste this result into your submission.
-
Compare your javadocs with what Chat-GPT generated. What are the differences? Which do you think is better, and why?
-
Now ask Chat-GPT to generate a UML diagram of
Schedulable
. Paste the result into your submission. -
Add the code below for a
Calendar
object into a prompt and ask Chat-GPT to generate a UML class diagram for bothSchedulable
andCalendar
.
public class Calendar implements Schedulable {
public static final int DEFAULT_START_OF_DAY = 8;
public static final int DEFAULT_END_OF_DAY = 17;
private final List<Schedulable> items;
private final String name;
private final int startOfDay;
private final int endOfDay;
public Calendar(String name, int startOfDay, int endOfDay, Schedulable... items) {...}
public Calendar(String name, Schedulable... items) {...}
public boolean isBusy(int day, int hour) {...}
public boolean add(Schedulable item) {...}
public boolean remove(Schedulable item) {...}
public String getName() {...}
public String toString() {...}
private int[][] getScheduleMatrix() {...}
}
Paste the result into your submission.
-
What is the plain text representation of the UML diagram not able to represent? Give examples of what is missing and explain how you would draw it differently.
-
Based on the results from Chat-GPT and your answer to question 6, draw a complete UML diagram of these two classes.
Submission Instructions:
Submit a PDF with your answers into Canvas.