Skip to content
Snippets Groups Projects
Commit 08a62f22 authored by Simon Barrett's avatar Simon Barrett
Browse files

Refactored Module

parent b54079b2
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File deleted
No preview for this file type
......@@ -6,15 +6,25 @@ public class Module {
this.lessons = lessons;
}
// User inputs a number and this needs to be translated to the array which starts at base 0
public Lesson getLessons(int choice) {
// GETTER METHODS
/**
* Returns a lesson from the Lesson array depending on User input
* User starts choice at 1 rather than 0 so this needs to be translated to arrays
* @param choice
* @return
*/
public Lesson getLesson(int choice) {
return lessons[choice - 1];
}
// Helper method to get the Array Length
/* This is only called in one place so rather than a getter and then call .length it
has been combined here for readability.
*/
public int getLessonsArrayLength() {
return lessons.length;
}
// END GETTER METHODS
/**
* Loops through the array printing out each lesson
......@@ -22,19 +32,27 @@ public class Module {
*/
public void listAll() {
System.out.println("Please pick from the lessons below: ");
String userInstruction = "By pressing the corresponding number (";
// Empty Strings declared which will be used to build the userInstruction string
String userInstruction = "";
String numberToChooseLesson = "";
/* Loops through the lesson array printing out the titles along with a lesson number
that users can to press to access their chosen lesson
*/
for(int i = 0; i < lessons.length; i++) {
System.out.println("[" + (i + 1) + "] " + lessons[i].getLessonTitle());
// If it is the last lesson to add to the userInstruction String then the String needs to be changed
/* If it is the last lesson to add to the userInstruction String then the String needs to
include the closing bracket
*/
if(i != lessons.length - 1) {
String numberToChooseLesson = (i + 1) + ", ";
userInstruction = userInstruction + numberToChooseLesson;
numberToChooseLesson = (i + 1) + ", ";
} else {
String numberToChooseLesson = (i + 1) + ") :";
userInstruction = userInstruction + numberToChooseLesson;
numberToChooseLesson = (i + 1) + ") :";
}
userInstruction = userInstruction + numberToChooseLesson;
}
System.out.println(userInstruction);
System.out.println("By pressing the corresponding number (" + userInstruction);
};
}
......@@ -19,7 +19,7 @@ public class QuizSystem {
// Getting lesson choice from User
int choice = ScannerExtension.scanForUserIntChoice(myData.cmt652.getLessonsArrayLength());
Lesson chosenLesson = myData.cmt652.getLessons(choice);
Lesson chosenLesson = myData.cmt652.getLesson(choice);
System.out.println("You have chosen lesson: " + chosenLesson.getLessonTitle());
// User takes the LESSON
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment