Public Interface House Interface Public int get Price Publi

Public Interface House Interface} Public int get Price (); Public int get Rooms(); Based on the diagram of the class hierarchy and interfaces above, write class definitions for Dwelling. House and Apartment, House implements House Interface and a Apartment implements Apartment Interface. Only Dwelling should be abstract. Be sure to provide a three argument constructor for each of House and Apartment.

Solution

import java.util.*;
import java.lang.*;
import java.io.*;

interface HouseInterface //interface for House
{
public int getPrice();
public int getRooms();
}

interface ApartmentInterface //interface for Apartment
{
public int getRent();
public int getBedRooms();
}

abstract class Dwelling //abstract class Dwelling
{
   private String Address;
   public Dwelling(String Address)
   {
       this.Address = Address;
   }
   public String toString()
   {
       return \"Address : \"+Address;
   }
}
class House extends Dwelling implements HouseInterface
{
   private int price;
   private int rooms;
  
   public House(String Address,int price,int rooms)
   {
       super(Address);
       this.price = price;
       this.rooms = rooms;
   }
   public int getPrice()
   {
       return price;
   }
   public int getRooms()
   {
       return rooms;
   }
   public String toString()
   {
       System.out.println(super.toString());
       return \"price = \"+getPrice() + \" Number of rooms = \"+getRooms();
   }
  
}
class Apartment extends Dwelling
{
   private int rent;
   private int bedrooms;
   public Apartment(String Address,int rent,int bedrooms)
   {
       super(Address);
       this.rent = rent;
       this.bedrooms = bedrooms;
   }
   public int getRent()
   {
       return rent;
   }
   public int getBedrooms()
   {
       return bedrooms;
   }
   public String toString()
   {
       System.out.println(super.toString());
       return \"price = \"+getRent() + \" Number of bed rooms = \"+getBedrooms();
   }
  
}
class Test
{
   public static void main (String[] args)
   {
       House h = new House(\"567,lane 2,Hillside,NJ\",200000,4);
       System.out.println(\"House Details\");
       System.out.println(h.toString());
      
       Apartment a = new Apartment(\"77 Santa Clara\",2000,3);
       System.out.println(\"Apartment Details\");
       System.out.println(a.toString());
   }
}

output:

 Public Interface House Interface} Public int get Price (); Public int get Rooms(); Based on the diagram of the class hierarchy and interfaces above, write clas
 Public Interface House Interface} Public int get Price (); Public int get Rooms(); Based on the diagram of the class hierarchy and interfaces above, write clas

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site