CMT653 Assessment 1
This project contains my solution to the first coursework assessment on the MSc Software engineering program's "Programming Principles and Practice" module. The aim is to build a command-line app that lets you read lessons, take a quiz, and record your participation. It also lets you check who has done each lesson.
contents
Documentation
User Class
This class consists of completely static methods and attributes, as ther can only possibly be one user at a time, so therefore we don't need to create instances to keep track of multiple users.
- score:int => keeps track of the user's current score
- getScore():int => returns the user's current score
- setScore():void => increments the user's score by 1
- setScoreToZero():void => sets the user's current score to zero
Question Class
- question:String => a written question
- options:String[] => written options to the answer
- answer:String => a, b or c. The answer key to the question
- askQuestion():void => prints "question" to the terminal, followed by the three possible answers, indexed by consecutive letters (a,b,c...)
- answerQuestion(user:User):void => takes the user object as an argument. It requests an answer to the previous question in the form of a letter (a, b, c...). Incorrect entries are marked as incorrect. If the answer is correct, the user gets a mark added to their score. If the answer is incorrect, the user is notified and the correct answer is given.
Lesson Class
- title:String => the title of the lesson
- content:String => the content of the lesson is stored in a string
- questions:Question[5] => Five questions are stored per lesson to be answered at the end
- completedNames:String[] => an arrayList of the names that have completed a lesson.
- completedScores:int[] => an arrayList of the scores each user got when completing the quiz.
- user:User => the user object where the score is kept track of
- getTitle():String => returns the title of the lesson
- getContent():String => prints the content of the lesson, then returns the value from this.completeQuiz().
- getLessonOrCompletions():String => asks for input (y to complete the lesson, returns getContent(); n to see who has completed this lesson, getComplete() and return an empty string).
- completeQuiz():String => asks if you are ready to complete the quiz (y starts the quiz, returns doQuestions(); n lets the loop in main skip to the next instruction, returns an empty string)
- doQuestions():String => loops through all the questions, asking one (Question.askQuestion()), then waiting for an answer (Question.answerQuestion(), taking this.user as an argument). When the quiz is complete, it prints your score, and takes you to the next stage to mark you completion, returns this.setComplete();
- setComplete():String => asks you to enter your name, which will be added to this.completedNames at the next empty point, and will add your score to this.completedScores. returns the name entered, allowing it to eventually be added to the lesson's .txt file.
- setCompleteFromRaw(data:String):void => it takes a string in the format "Name x" where the name is a name of a user, and x is their score. This is taken from the lessons .txt file, and allows the object to "remember" who has completed the lesson even after closing the program.
- getComplete():void => loops through this.completedNames and this.completedScores, printing each to the terminal
LessonReader Class
- addLessons(lessons File[]): List => given an array of files (lessons), it will extract all the data, and create a list of Lesson objects (including the questions and students who have completed the lesson with their scores). This method is static as there is only one method that needs to be called in the object.
LearningSystem Class
- Reads in all .txt files from the "Lessons" directory, and converts them into Lesson objects using LessonReader.addLessons().
- prints a welcome message
- a while loop asks you to pick a lesson, sets it to this.currentLesson, and calls this.currentLesson.getLessonOrCompletions(). After that lesson is complete, the user is asked if they want to choose another lesson (y continues the loop to the beginning, n prints a leaving message and breaks the while-loop).
Version history
- v0.0.1: A working MVP. All lessons and questions are hardcoded. However, the ability to navigate through lessons and answer questions is working. class size is limited to 10
- v0.0.2: Reads lessons from .txt files.
- v0.0.3: Reads data of those who completed lessons from .txt file. Adds name and score to .txt file when they complete a lesson. (Data persistence).
- Final: Bug fixed where a user's name wouldn't be written to the lesson file. Better wording for some questions. (10/11/2021)
Upcoming plans
- No addition incoming