Property Class
class Property {
private String propertyId;
private String location;
private double price;
public Property(String propertyId, String location, double price) {
[Link] = propertyId;
[Link] = location;
[Link] = price;
}
public String getPropertyId() {
return propertyId;
}
public void setPropertyId(String propertyId) {
[Link] = propertyId;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
[Link] = location;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
[Link] = price;
}
public void displayPropertyInfo() {
[Link]("Property ID: " + propertyId);
[Link]("Location: " + location);
[Link]("Price: " + price);
}
}
ResidentialProperty Class
class ResidentialProperty extends Property {
private int numberOfBedrooms;
private double gardenSize;
public ResidentialProperty(String propertyId, String location, double price,
int numberOfBedrooms, double gardenSize) {
super(propertyId, location, price);
[Link] = numberOfBedrooms;
[Link] = gardenSize;
}
public int getNumberOfBedrooms() {
return numberOfBedrooms;
}
public void setNumberOfBedrooms(int numberOfBedrooms) {
[Link] = numberOfBedrooms;
}
public double getGardenSize() {
return gardenSize;
}
public void setGardenSize(double gardenSize) {
[Link] = gardenSize;
}
@Override
public void displayPropertyInfo() {
[Link]();
[Link]("Bedrooms: " + numberOfBedrooms);
[Link]("Garden Size: " + gardenSize);
}
}
CommercialProperty Class
class CommercialProperty extends Property {
private double officeSpace;
private boolean hasParking;
public CommercialProperty(String propertyId, String location, double price,
double officeSpace, boolean hasParking) {
super(propertyId, location, price);
[Link] = officeSpace;
[Link] = hasParking;
}
public double getOfficeSpace() {
return officeSpace;
}
public void setOfficeSpace(double officeSpace) {
[Link] = officeSpace;
}
public boolean isHasParking() {
return hasParking;
}
public void setHasParking(boolean hasParking) {
[Link] = hasParking;
}
@Override
public void displayPropertyInfo() {
[Link]();
[Link]("Office Space: " + officeSpace);
[Link]("Parking Available: " + hasParking);
}
}
TestClass (Main)
public class TestClass {
public static void main(String[] args) {
ResidentialProperty rp = new ResidentialProperty(
"R101", "Hyderabad", 7500000, 3, 500);
CommercialProperty cp = new CommercialProperty(
"C201", "Bangalore", 15000000, 2000, true);
[Link]();
[Link]();
}
}