Question

In: Computer Science

Write html code: 1. Define constructor functions Faculty and Course. An instance of Course has instance...

Write html code:

1. Define constructor functions Faculty and Course. An instance of Course has instance of Faculty as the value if its instructor instance variable.

Download testProb1.js and testProb1.html

Write two files (faculty.js and course.js)

Constructor function Faculty. Arguments name and dept; Instance variables, name (a string, with default ("name unknown")

Write get_ and set_ methods for both instance variables; toString() return strings of form "<name> of <dept>"

Constructor function Course Arguments name, times, instructorName, and instructorDept, all with string values

Instance variables name (a string, with default “unknown course name”)

                                 times (a string, with default “unknown times”)

instructor (instance of Faculty, with no default), constructed using new and the Faculty constructor

Define get_ and set_ methods for all instance variables

setinstructor() takes an instance of Faculty as its parameter

getinstructor() returns an instance of Faculty

toString() returns the string value of the name instance variable

Solutions

Expert Solution

Please find the code below,

Faculty.js

class Faculty{
    constructor(name = "name unknown", dept){
       this._name = name
       this._dept = dept
    }

    get name() {
        return this._name;
    }
    set name(name) {
        this._name = name;
    }

    get dept() {
        return this._dept;
    }
    set dept(dept) {
        this._dept = dept;
    }
    
    toString(){
        return this._name+" of "+this._dept;
    }
 }

Course.js

class Course{
    constructor(name = "unknown course name", times="unknown times",instructorName, instructorDept){
       this._name = name
       this._times = times
       this._instructor = new Faculty(instructorName, instructorDept)
    }

    get name() {
        return this._name;
    }
    set name(name) {
        this._name = name;
    }

    get times() {
        return this._times;
    }
    set times(times) {
        this._times = times;
    }

    get instructor() {
        return this._instructor;
    }
    set instructor(instructor) {
        this._instructor = instructor;
    }
    
    toString(){
        return this._name;
    }
 }

If you have any doubts feel free to ask in the comments. Also please do upvote the solution.


Related Solutions

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
1. Define HTML and what each letter means. Also, define JavaScript. (Write at least one (1)...
1. Define HTML and what each letter means. Also, define JavaScript. (Write at least one (1) paragraph (one paragraph contains 5 to 7 sentences). 2.Define Excel. What would you use Excel for? (Write at least one (1) paragraph (one paragraph contains 5 to 7 sentences).
Please write code in java and comment . thanksItem classA constructor, with a String...
Please write code in java and comment . thanksItem classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.It must have a default constructor.It must have a constructor which...
modify code to write the output as an HTML table to a file in the output...
modify code to write the output as an HTML table to a file in the output directory. The file that is saying to work at : SOURCE CODE IN PERL: print "Enter principal amount: "; $P=; while($P<=0) { print "Principal must be positive. Try again: "; $P=; } print "Enter number of times interest is applied in a year: "; $n=; while($n!=12 && $n!=4 && $n!=2 && $n!=1) { print "It must be 12, 4, 2 or 1. Try again:...
2. Program containing two modules: a. Create a class Code one programmer-written constructor Create several instance...
2. Program containing two modules: a. Create a class Code one programmer-written constructor Create several instance data attributes Create 3 methods which will each be invoked from the driver program - one method will not receive any parameters, but will return a value to driver program - one method will receive one parameter, and will also return a value to driver program - a display method will receive 2 parameters from driver program Define a constant properly; use the constant...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
Write the code to create a class Square implementing the interface Figure with constructor to initialize...
Write the code to create a class Square implementing the interface Figure with constructor to initialize with a size and toString method. Write another class SquareUser that creates and array of Squares and initializing with sides 1, 2,3, 4 and 5. Also write the code to call the toString method of squares in a loop to print the string for all squares in the array.
Use a style sheet to define the following rules and implement the given HTML code. Please...
Use a style sheet to define the following rules and implement the given HTML code. Please put your style information within the same file as the HTML code. Rules • Hyperlinks using the nodec class should display no decoration. • Hyperlinks should display text in white with a green background color when the mouse pointer is held over the link. (use the hover pseudo-class) • Unordered lists not nested within any other lists should be displayed in blue text and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT