If you would like to look up the answers for the following quiz questions, you can check our discussion forum. If you don't find an answer in the forum, you may create a post asking for an answer to a particular question.
Consider the simple information design model shown in the class diagram.
Which of the following methods have to be added to the
Publisher
class in a corresponding JS class model? Select
one or many:
☐ checkName( n: String): ConstraintViolation
☐ getName(): String
☐ setName( n:
String)
☐ checkNameAsId( n: String):
ConstraintViolation
☐ checkNameAsId( n: String):
ConstraintViolation
☐ checkName( n: String):
ConstraintViolation
☐ setName( n: String)
Notice that an underlined method name denotes a class-level ("static") method.
Consider the constraints specified for the object type
Person
in the class diagram.
Which of the following JavaScript code fragments implements these constraints? Select one:
O
if (name === undefined) { return "A name is required!"; } else if (typeof name !== "string" || name.trim() === "") { return "Name must be a non-empty string!"; } else if (age !== undefined) { if (!Number.isInteger( age) || age < 0) { return "Age must be a non-negative integer!" } } else return ""; // no error
O
if (name === undefined) { return "A name is required!"; } else if (typeof name !== "string") { return "Name must be a string!"; } else if (age !== undefined) { if (!Number.isInteger( age) || age < 0) { return "Age must be a non-negative integer!" } } else return ""; // no error
O
if (name === undefined) { return "A name is required!"; } else if (typeof name !== "string" || name.trim() === "") { return "Name must be a non-empty string!"; } else if (age < 0) { return "Age must be a non-negative integer!" } else return ""; // no error
O
if (name === undefined) { return "A name is required!"; } else if (typeof name !== "string" || name.trim() === "") { return "Name must be a non-empty string!"; } else if (age === undefined || !Number.isInteger( age) || age < 0) { return "Age must be a non-negative integer!" } else return ""; // no error
Which of the following code fragments represents a correct setter
method for an ID attribute isbn
? Select one or more:
O
Book.prototype.setIsbn = function (i) { const validationResult = this.checkIsbn(i); if (validationResult instanceof NoConstraintViolation) { this.isbn = i; } else { throw validationResult; } };
O
Book.prototype.setIsbn = function (i) { if (Book.checkIsbn(i)) { this.isbn = i; } else { console.log(`${i} is not a valid ISBN!`); } };
O
Book.prototype.setIsbn = function (i) { const validationResult = this.checkIsbnAsId(i); if (validationResult instanceof NoConstraintViolation) { this.isbn = i; } else { throw validationResult; } };