3import java.util.ArrayList;
4
5
6public class ProjectBook { 7 private String title; 8 private String description; 9 private Entry entry = new Entry();10 private ArrayList<Entry> entries = new ArrayList<Entry>();111213 public ProjectBook() {14 title = "unnamed";15 description = "No description";1617 entry = new Entry();18 entries.add(entry);19 }20 21 public ProjectBook(String name, String desc) {22 title = name;23 description = desc;24 }2526 // GETTERS27 public String getTitle() {28 return title;29 }3031 public String getDescription() {32 return description;33 }3435 // SETTERS36 public void setTitle(String name) {37 title = name;38 }39 40 public void SetDescription(String desc) {41 description = desc;42 }434445 46}
1import java.util.ArrayList;
2
3public class Entries { 4 ArrayList<Entry> entries = new ArrayList<Entry>(); 5 public Entries() { 6 for(int i = 0; i < 0; i++) { 7 } 8 9 }10}
1public class Entry { 2 private String entryName; 3 private String entryMain; 4 5 6 public Entry() { 7 entryName = "unnamed"; 8 entryMain = "no information"; 9 // date10 }1112 public Entry(String name, String main) {13 entryName = name;14 entryMain = main;15 }1617 public String getEntryName() {18 return entryName;19 }20 21 public String getEntryMain() {22 return entryMain;23 }2425 public void setEntryName(String name) {26 entryName = name;27 }2829 public void setEntryMain(String main) {30 entryMain = main;31 }32}
6
7import java.util.Scanner;
8
9class Main{1011 private static Scanner input = new Scanner(System.in);12 private static ProjectBook test = new ProjectBook();13 private static int result = -1;14 public static void main(String[] args) {1516 do{17 System.out.println("What would you like to do? \n 0: View Basic Notebook info \n 1: Create notebook \n 4: exit");18 System.out.println("input: ");19 result = Integer.parseInt(input.nextLine());20 mainOptionSelection();21 System.out.println("\n\n");2223 journalFormatter(10);24 } while(result != 4);25 clearScreen();26 }2728 private static void clearScreen() { 29 System.out.println("\033c");30 System.out.flush(); 31 }3233 private static void mainOptionSelection() {34 switch(result) {35 case 0:36 System.out.println("notebooks: \n" + test.getTitle() + ": " + test.getDescription());37 case 1: 38 }39 }40 public static void journalFormatter(int entryID) {41 System.out.println(test.getTitle());42 System.out.println("-----------------------------------------------------");43 System.out.println(test.getDescription());44 System.out.println("\n\n");45 }46}
This class does not have any documentation.
Consider adding a documentation comment to explain its use.
While it may seem like the functionality of a class is perfectly obvious, any consumers of your API may not be able to pick up on certain details.
Consider a case where the class given below can be instantiated and provides certain functionalities within each instance in a thread-safe manner, perhaps it is a rest API client.
If there is no documentation comment on the class, it is not immediately obvious that the class is thread safe. Thus, multiple instances of the class may be created to perform operations concurrently, using up both memory as well as OS resources like sockets. If it were known from the beginning that the class were thread safe, the user would not need to create unnecessary extra instances of SomeClass
.
class SomeClass {
// ...
}
Make sure to add useful information regarding the usage or implementation of a particular declaration, so that anything about it which can't be understood from the name or some other cue is correctly conveyed.
/**
* Instances of this class are used to perform xyz action.
*
* This class is thread safe and the same instance can be used over multiple threads.
*/
class SomeClass {
// ...
}
This issue will not be reported for model entity classes. If there is any non-obvious behavior associated with a particular class however, do consider documenting it.