diff --git a/app.js b/app.js index 29c0766..90622eb 100644 --- a/app.js +++ b/app.js @@ -1,38 +1,39 @@ -class Person { - //creates instance of Person with properties name, age, and numBooksRead - constructor(name, age, numBooksRead) { + +class Country { + //creates instance of Country with properties name, population, and numPopulation + constructor(name, population, numPopulation) { this.name = name; - this.age = age; - this.numBooksRead = numBooksRead; + this.population = population; + this.numPopulation = numPopulation; } - //increments numBooksRead by 1 - readNewBook() { - this.numBooksRead++; + //increments numPopulation by 1 + countNewPop() { + this.numPopulation++; } } -class Electrician extends Person { - //creates instance of Electrician with Person properites plus certifications, an array of strings - constructor(name, age, numBooksRead, certifications) { - super(name, age, numBooksRead); - this.certifications = certifications; +class City extends Country { + //creates instance of City with Country properites plus size, an array of strings + constructor(name, population, numPopulation, size) { + super(name, population, numPopulation); + this.size = size; } } -class Teenager extends Person { - //creates instance of Teenager with Person properties plus isHungry, a boolean value - constructor(name, age, numBooksRead, isHungry = true) { - super(name, age, numBooksRead); - this.isHungry = isHungry; +class County extends Country { + //creates instance of County with Country properties plus isRich, a boolean value + constructor(name, size, numPopulation, isRich = true) { + super(name, size, numPopulation); + this.isRich = isRich; } - //feeds the teenager. If they are hungry, changes isHungry to false, if they are not hungry, prints message to console. - eat() { - if(this.isHungry) { - this.isHungry = false; + //County needs fund if they are poor. If they are rich, changes isRich to True, if they are Rich, prints message to console. + rich() { + if(this.isRich) { + this.isRich = true; } else { - console.log('Oh no I think I ate too much') + console.log('County needs fund!') } } } @@ -40,30 +41,30 @@ class Teenager extends Person { //below we will test our classes by instantiating them, calling each method, and verifying output //create instances of each class -let person = new Person('Euthyphro', 35, 0); -let electrician = new Electrician('Zeus', 28, 3, ['Lightning', 'Polymorphism']); -let teen = new Teenager('Persius', 16, 5, true); +let country = new Country('USA', 330, 0); // Population in Millions +let city = new City('Denver', 0.5, 5000, 154); // Population in Millions and size in sq mil +let county = new County('Boulder', 338000, 740, true); // size in sq mil //log each instance -console.log(person); -console.log(electrician); -console.log(teen); +console.log(country); +console.log(city); +console.log(county); //call the method from the parent class to ensure it works as expected -person.readNewBook(); -electrician.readNewBook(); -teen.readNewBook(); +country.countNewPop(); +city.countNewPop(); +county.countNewPop(); -//log the objects after calling .readNewBook() to verify it worked as intended -console.log(person); -console.log(electrician); -console.log(teen); +//log the objects after calling .numPopulation() to verify it worked as intended +console.log(Country); +console.log(City); +console.log(County); -//call .eat() -teen.eat(); +//call .rich() +county.rich(); -//check that .eat() when isHungry == true works as expected -console.log(teen); +//check that .rich() when isRich == true works as expected +console.log(county); -//check that .eat() when isHungry == false works as expected -teen.eat(); \ No newline at end of file +//check that .rich() when isRich == false works as expected +county.rich(); \ No newline at end of file