Practice What You Learned

Create a JavaScript REPL from repl.it -- you can name it "JavaScript Classes HW 2".`

Complete all work in your REPL.it

Static Methods and Properties

class Governor {

}
  • There is only one Governor in the state, add static methods and properties you'd expect a Governor to have.
  • log the properties and test the methods (don't instantiate)

Inheritance

Your base class

Person{
    constructor(){

    }
}
  • Think of three properties all people share, set them with the constructor
  • Think of three methods all people share
  • Create a PostalWorker class that inherits from person, add some methods
  • Create a Chef class that inherits from person, add some methods
  • Create 2 PostalWorkers and 2 Chefs, log them and test all their methods

Hungry for More

Hungry For More (Only do this if all your hw above is done)

Bank Accounts take it a step further

BankAccount class:

Derived From Properties Methods
n/a ownerName, balance, acctNum (generated in constructor - not passed in) deposit, withdraw

CheckingAccount class:

Derived From Additional Properties Additional Methods
BankAccount overdraftEnabled Override withdraw to implement overdraft feature

SavingsAccount class:

Derived From Additional Properties Additional Methods
BankAccount None Override withdraw to disallow withdrawals completely :)

Copyright © Per Scholas 2023