Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your job is to complete the Evaluation.js and Question.js files that are enclosed so that conform to the below UML diagrams. Helpful Hints: An array

Your job is to complete the Evaluation.js and Question.js files that are enclosed so that conform to the below UML diagrams.

Helpful Hints:

An array list in JavaScript is simply a regular array

To declare an array: arrayName = [];

To add an item to an array: arrayName.push(value);

To remove item from array by index: arrayName.splice(index, 1);

The ES6+ for-of loop may be useful in this assignment

Evaluation.js

/* Recall: JavaScript does not have true support for abstract classes; therefore, an error should be thrown if there is an attempt to instantiate the class */ class abstractEvaluation {

//Default constructor constructor() { if (this.constructor === abstractEvalaution) { throw new TypeError('Abstract class "abstractEvaluation" cannot be instantiated directly.'); } } /* IMPORTNAT: In JavaScript there are the set and get keywords to denote getter and * setter methods. I have completed an example of each to help assist you. */ //NOTE: start is a Date object set startDate(start){ if(this.startDate >= this.endDate){ throw new Error('start date of an evaluation cannot be greater than or equal to the end date of the evaluation.') } this.startDate = start; } get startDate(){ return this.startDate; } /* TODO: Define the remaining getters and setters as shown in the UML diagram */ //NOTE: Ensure the end date is valid relative to the start date set endDate(end){} get endDate(){} //Note: Weight should be a float greater than 0 and less than or equal to 100 set weight(w){} get weight(){} //Note: total marks is updated in the addQuestion and RemoveQuestion methods get totalMarks(){} //TODO: Implement addQuestion which adds a question to the ArrayList //NOTE: When a Question is added the totalMarks field should be updated addQuestion(q){} //TODO: Implement removeQuestion which removes a question to the ArrayList //NOTE: When a Question is removed the totalMarks field should be updated removeQuestion(){} /*TODO: Implement grade function which iterates over each question in the evaluation and compares the answer array passed in to each question. If correct, add question marks to an accumulator variable. Return marks correct divided total marks. */ grade(answer){} [Symbol.Iterator](){ return this.questions } //ITERATOR }

/* TODO: Implement the below subclasses as defined in the UML diagram*/ export class Quiz extends abstractEvaluation{

}

export class Assignment extends abstractEvaluation{ }

export class Test extends abstractEvaluation{ }

Question.js

class abstractQuestion{ constructor(){ this.question="" this.marks=1 //by default questions are worth 1 mark if (this.constructor === abstractQuestion) { throw new TypeError('Abstract class "abstractQuestion" cannot be instantiated directly.'); } /* NOTE: This defines grade as an abstract class that must be implemented by subclasses */ if (this.grade === undefined) { throw new TypeError('Classes extending abstractQuestion must implement grade()'); } } //TODO: Implement below setters and getters set marks(m){} get marks(){} set question(q){} get question(){} }

export class MultipleChoice extends abstractQuestion{

//TODO: Implement setters and getters from UML diagram

//NOTE: answer in a multiple choice question should be the index of the correct response. // If answer is the correct index return "marks" the question is 0, return 0 otherwise grade(answer){}

}

export class ShortAnswer extends abstractQuestion{

//TODO: Implement setters and getters from UML diagram

//NOTE: answer in a short answer question should be a string. // If answer is the correct index return "marks" the question is 0, return 0 otherwise grade(answer){}

}

export class Ordering extends abstractQuestion{

//TODO: Implement setters and getters from UML diagram

//NOTE: answer in a ordering question should be an array of ints representing the "options" // correctly ordered from start to finish. //EXAMPLE: options = ["Turn on the stove", "Turn off the stove", "Boil water"] // answer = [0,2,1] // If answer is the correct index return "marks" the question is 0, return 0 otherwise grade(answer){}

}

UML diagrams

image text in transcribed

Design: Evaluation startDate:Date .endDate:Date totalMarks: int -weight: float questions ArrayList + set startDate(Date: start):void + get startDate:Date + set endDate(Date: end):void + get endDate:Date + set weight(int: w) void + get weight():int + get totalMarks():int + addQuestion(Question: a):void + removeQuestion(Question: q):void + grade() float + (Symbol.Iterator]0: ArrayList Quiz Assignment Test timed:boolean = False - minutesAllowed 1 -timed:boolean = False - minutesAllowed= .1 + Assignment + Assignment(ArrayList: questions) + setMinutes(): void + getMinutes: void + is Timedo: boolean Testo + Test(ArrayList answerindex: int = -1 answer: String = options: ArrayList answer: ArrayListint> + ShortAnswer + get answer: String + set answer(String: answer): void + Multiple Choice + get answerindex(): int + set answerindex(int: i): void + get options(): ArrayList + set options(ArrayList: 0); void + Ordering + get answer(): ArrayListsint> + set answer(ArrayList + set options(ArrayList: 0); void

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions