Recently I had an assignment in a computer science course to create a class with two objects built from said class.
The professor's criticism through email was the following: "sysouts in constructor, getters, and setters these should be in the main method."
He doesn't speak English very well so that doesn't help much. Does anybody know what exactly he's talking about in reference to my code? This is the code I submitted:
public class Book {
int currentPage;
int nextPage;
int lastPage;
public Book(int pageNumber) {
currentPage = pageNumber;
System.out.println("You've opened the book to page " + currentPage + ".");
}
public void turnForward(int numTurned) {
nextPage = numTurned + currentPage;
System.out.println("You've turned forward to page " + nextPage + ".");
}
public void turnBack(int numTurned) {
lastPage = nextPage - numTurned;
if (lastPage <= 1) {
lastPage = 1;
System.out.println("You've turned back to the first page.");
}else {
System.out.println("You've turned back to page " + lastPage + ".");
}
}
public static void main(String[] args) {
Book bigJava = new Book(5);
bigJava.turnForward(2);
bigJava.turnBack(8);
Book earlyObjects = new Book(22);
earlyObjects.turnForward(12);
earlyObjects.turnBack(17);
}
}
Is it mandatory to put getters/setters in the main method? The code doesn't actually run if I do.