Build a house

Report a typo

There are three classes: an abstract class House, and two concrete classes, Wooden and Stone.
You must implement the abstract class House with a template method called build() to build a new house using the following algorithm:

  1. Choose a location
  2. Place a foundation
  3. Place walls
  4. Place windows
  5. Place doors
  6. Place roofs
  7. Connect the house to the electrical grid

The Stone class is already provided. Use it to help you write the abstract methods in the abstract House class.
Make the Wooden class inherit from the House class and implement the methods according to the console output.

Sample Input 1:

stone

Sample Output 1:

Choose the best location for the new house
Place a stone foundation
Place stone walls
Place reinforced windows
Place reinforced doors
Place metal sheet roofs
Connect the house to the electrical grid

Sample Input 2:

wooden

Sample Output 2:

Choose the best location for the new house
Place a wooden foundation
Place wooden walls
Place wooden windows
Place wooden doors
Place metal sheet roofs
Connect the house to the electrical grid
Write a program in Java 17
import java.util.Scanner;

abstract class House {

// write your code here ...

// Do not change the code below
public void chooseLocation() {
System.out.println("Choose the best location for the new house");
}

public void placeRoofs() {
System.out.println("Place metal sheet roofs");
}

public void connectElectricity() {
System.out.println("Connect the house to the electrical grid");
}
}

class Wooden {
// write your code here ...
}

// Do not change the code below
class Stone extends House {

@Override
public void placeFoundations() {
System.out.println("Place a stone foundation");
}

@Override
public void placeWalls() {
System.out.println("Place stone walls");
}
___

Create a free account to access the full topic