About Lesson
Assignment 1: Library and Book Classes
- Objective: Create a basic library system using classes.
- Instructions:
- Create a Book class with properties: title, author, and yearPublished.
- Create a Library class that has:
- An array to store multiple Book instances.
- Methods to add a book (addBook), remove a book (removeBook by title), and list all books (listBooks).
- Add books to the library, display the library’s books, and test the add and remove functionalities.
Hint: Use inheritance if you want to create different types of books (e.g., EBook, PrintedBook), each with additional unique properties.
Assignment 2: Animal, Mammal, and Bird Classes
- Objective: Practice creating a class hierarchy for different types of animals.
- Instructions:
- Create an Animal base class with properties like name and age, and a method makeSound() that outputs a generic message (e.g., ${name} makes a sound).
- Create subclasses Mammal and Bird that inherit from Animal.
- Each subclass should override the makeSound() method with a unique sound (e.g., a mammal might “growl,” and a bird might “chirp”).
- Create instances of Mammal and Bird, and call their makeSound method to demonstrate polymorphism.
Hint: Add unique properties to each subclass, such as furColor for mammals and wingSpan for birds.
Assignment 3: Vehicle, Car, and Motorcycle Classes
- Objective: Build a class hierarchy for a vehicle system.
- Instructions:
- Create a Vehicle base class with properties make, model, and year.
- Add a method displayInfo in Vehicle to display these details.
- Create Car and Motorcycle subclasses that inherit from Vehicle.
- Add unique properties: Car should have numDoors, and Motorcycle should have hasSidecar.
- Override displayInfo in each subclass to include these additional properties.
- Create instances of Car and Motorcycle, and display their information.
Hint: Experiment with different car and motorcycle models to see how inheritance affects each instance.
Assignment 4: Account, SavingsAccount, and CheckingAccount Classes
- Objective: Create a bank account system with specialized account types.
- Instructions:
- Create an Account base class with properties accountNumber and balance, and methods deposit and withdraw.
- Create two subclasses, SavingsAccount and CheckingAccount, that inherit from Account.
- In SavingsAccount, add a minimumBalance property and ensure withdraw doesn’t go below this minimum.
- In CheckingAccount, add a overdraftLimit property to allow withdrawals up to a negative limit.
- Test with deposits and withdrawals to observe how each subclass handles balance constraints.
Hint: Use console.log to display warning messages for any violations of minimum balance or overdraft limits.
Assignment 5: Employee, Manager, and Developer Classes
- Objective: Develop an employee hierarchy with unique roles.
- Instructions:
- Create a base Employee class with properties name, position, and salary, and a method getDetails to display these details.
- Create Manager and Developer subclasses.
- Manager should have an additional property department and a method scheduleMeeting.
- Developer should have a programmingLanguages array and a method addLanguage to add new languages.
- Create instances of Manager and Developer, call getDetails, and use each subclass’s unique methods.
Hint: Use arrays for managing teams in Manager and programming languages in Developer.