0% found this document useful (0 votes)
6 views4 pages

ASGN108

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

ASGN108

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ID: ASGN108:

package AbstarctClasses;

public class Property {


private String propertyName;
private String location;
private String propertyType;
private double price;
private double area;
public Property(String propertyName, String location, String propertyType, double price,
double area) {
this.propertyName = propertyName;
this.location = location;
this.propertyType = propertyType;
setPrice(price);
setArea(area);
}
public String getPropertyName() {
return propertyName;
}

public void setPropertyName(String propertyName) {


this.propertyName = propertyName;
}
public String getLocation() {
return location;
}

public void setLocation(String location) {


this.location = location;
}
public String getPropertyType() {
return propertyType;
}

public void setPropertyType(String propertyType) {


this.propertyType = propertyType;
}
public double getPrice() {
return price;
}

public void setPrice(double price) {


if (price < 0) {
throw new IllegalArgumentException("Price cannot be negative.");
}
this.price = price;
}
public double getArea() {
return area;
}

public void setArea(double area) {


if (area < 0) {
throw new IllegalArgumentException("Area cannot be negative.");
}
this.area = area;
}
public void displayPropertyInfo() {
System.out.println("Property Name: " + propertyName);
System.out.println("Location: " + location);
System.out.println("Property Type: " + propertyType);
System.out.println("Price: $" + price);
System.out.println("Area: " + area + " sq. ft.");
System.out.println("-----------------------------");
}
public static void main(String[] args) {
Property property1 = new Property("Green Villa", "New York", "Residential", 350000,
2400);
Property property2 = new Property("Tech Park", "San Francisco", "Commercial",
1500000, 12000);
Property property3 = new Property("Sunny Apartments", "Miami", "Residential",
500000, 3200);
property1.displayPropertyInfo();
property2.displayPropertyInfo();
property3.displayPropertyInfo();
}
}

OUTPUT:
Property Name: Green Villa
Location: New York
Property Type: Residential
Price: $350000.0
Area: 2400.0 sq. ft.
-----------------------------
Property Name: Tech Park
Location: San Francisco
Property Type: Commercial
Price: $1500000.0
Area: 12000.0 sq. ft.
-----------------------------
Property Name: Sunny Apartments
Location: Miami
Property Type: Residential
Price: $500000.0
Area: 3200.0 sq. ft.
-----------------------------

You might also like