Question

In: Computer Science

Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software...

Model the following in JAVA PROGRAMMING :

In a software engineering project we are developing software for a Real estate agency. The Real Estate Agency has these types of properties: Shops, Apartments and Villas. All properties have: Property Owner, Address, Property Purpose (Sale/Rent), Area (in m^2) and price.

Model these in an inheritance hierarchy considering that:

1. Shops have these fields in addition to properties: Floor (int), Street view (boolean).

2. Apartments have these feilds in addition to properties: Floor, Bedrooms(int), Bathroom (int) and balcony (true/false)

3. Villas have these fields in addition to properties: Count of floors, With/Without parking area (boolean), pool (boolean)

Develop these methods:

1. Two overloaded constructors for all properties, one with just Property Owner and Address and the other with all the fields.

2. toString() method for each class

Write a class to test the program:

1. Create two instances with all the attributes for each type of property by using the appropriate constructors.

2. Put all the created properties in one of data structures of Java that you have learned

3. Calculate and print the total value of all properties

4. Search and print information about the lowest price apartment with 2 Bedrooms.

Solutions

Expert Solution

import java.util.ArrayList;

class Property {

String owner;

String address;

String purpose;

double area;

int price;

};

class Shop extends Property {

int floor;

boolean streetView;

// Constructors

Shop(String own, String adr) {

this.owner = own;

this.address = adr;

}

// Owner, address, pupose, area, cost, floor, streetView

Shop(String own, String adr, String pur, double ar, int cost, int fl, boolean sv) {

this.owner = own;

this.address = adr;

this.purpose = pur;

this.area = ar;

this.price = cost;

this.floor = fl;

this.streetView = sv;

}

// toString() method

public String toString() {

return owner+" "+address+" "+purpose+" "+area+" "+price+" "+floor+" "+streetView;

}

};

class Apartment extends Property {

int floor;

int bedrooms;

int bathrooms;

boolean balcony;

// Constructors

Apartment(String own, String adr) {

this.owner = own;

this.address = adr;

}

// Owner, address, pupose, area, cost, floor, bedrooms, bathrooms, balcony

Apartment(String own, String adr, String pur, double ar, int cost, int fl, int broom, int bath, boolean bal) {

this.owner = own;

this.address = adr;

this.purpose = pur;

this.area = ar;

this.price = cost;

this.floor = fl;

this.bedrooms = broom;

this.bathrooms = bath;

this.balcony = bal;

}

// toString() method

public String toString() {

return owner+" "+address+" "+purpose+" "+area+" "+price+" "+floor+" "+bedrooms+" "+bathrooms+" "+balcony;

}

};

class Villa extends Property {

int floorCount;

boolean parking;

boolean pool;

// Constructors

Villa(String own, String adr) {

this.owner = own;

this.address = adr;

}

// Owner, address, pupose, area, cost, floors, parking, pool

Villa(String own, String adr, String pur, double ar, int cost, int fl, boolean park, boolean pl) {

this.owner = own;

this.address = adr;

this.purpose = pur;

this.area = ar;

this.price = cost;

this.floorCount = fl;

this.parking = park;

this.pool = pl;

}

// toString() method

public String toString() {

return owner+" "+address+" "+purpose+" "+area+" "+price+" "+floorCount+" "+parking+" "+pool;

}

}

public class testp {

public static void main(String[] args) {

// Creating two instances of each class

Shop shop1 = new Shop("Newton", "131 France", "Sell", 2500.32, 100000, 1, false);

Shop shop2 = new Shop("You", "Where", "Rent", 3005.2, 25000, 2, true);

Apartment apartment1 = new Apartment("Euler", "54H Madrid", "Rent", 546, 5200, 3, 2, 1, true);

Apartment apartment2 = new Apartment("Aljabr", "548 Alexandria", "Sell", 250, 1200, 1, 1, 1, false);

Villa villa1 = new Villa("C.V. Raman", "259/78 Chennai", "Sell", 450, 450000, 4, true, true);

Villa villa2 = new Villa("Ramanujan", "54A Madurai", "Rent", 500, 320000, 3, true, false);

// Storing these properties in ArrayList data structure

ArrayList<Property> list = new ArrayList<Property>();

list.add(shop1);

list.add(shop2);

list.add(apartment1);

list.add(apartment2);

list.add(villa1);

list.add(villa2);

// total value of all properties

long totalValue = 0;

for(int i = 0; i < list.size(); i++) {

totalValue += list.get(i).price;

}

// printing totalvalue

System.out.println("Total value of all properties: "+totalValue);

// Creating arraylist of type apartments

ArrayList<Apartment> apartments = new ArrayList<Apartment>();

apartments.add(apartment1);

apartments.add(apartment1);

// Searching and printing lowest valued two bedroom apartment

Apartment lowest = null;

for(int i = 0; i < apartments.size(); i++) {

// if it has two bedrooms

if(apartments.get(i).bedrooms == 2) {

// it it's first apartment with two bedrooms

if(lowest == null) {

lowest = apartments.get(i);

}

else {

if(lowest.price > apartments.get(i).price) {

lowest = apartments.get(i);

}

}

}

}

System.out.println("Lowest priced 2 bedroom apartment is: ");

System.out.println(lowest.toString());

}

}

OUTPUT


Related Solutions

Discuss steps required to manage a software engineering project.
Discuss steps required to manage a software engineering project.
I need some ideas for software engineering project
I need some ideas for software engineering project
**SOFTWARE ENGINEERING** Think about the following, as they pertained to your project: the problems you encountered...
**SOFTWARE ENGINEERING** Think about the following, as they pertained to your project: the problems you encountered during the project the impact those problems had on development what was done to handle those problems what you would do in the future to avoid these problems or minimize their impacts Your analysis should include both technical and non-technical (e.g. , personnel, communication, etc. ) issues.
What are the documentations of an online banking system for a project in software engineering
What are the documentations of an online banking system for a project in software engineering
This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's...
This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's and JSP 3rd Edition. I need help modifying some code. I will post the code I was told to open that needs to be modified below. In this exercise, you'll enhance the Future Value application to store the amount and interest rate in the user's session. That way, the user can experiment with different numbers of years to see the value of his or...
Software Engineering
Software EngineeringA freight forwarding company will develop a tracking system application that can provide convenience for consumers in sending goods to various locations. Some of the conveniences of this application are Consumers can send goods with a home pickup system so that consumers just make an order for delivery of goods, then the goods will be picked up and delivered to the destination location.Consumers can check the position of the goods that are on the way with their smartphone as...
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method from the test class 2/ Create a File, Printwriter for an output file yourlastnameErrorLog.txt 3/ Set your maximum array size for accounts to 10 4/ Catch InputMismatch and ArrayIndexOutOfBounds exceptions when reading data from the file: a. Skip any lines that cause an exception b. Write information about the exception to the log file, yourlastnameError.txt c. Include exception type and line number in exception...
How do we change source code on java programming? Thanks
How do we change source code on java programming? Thanks
Explain the process of “validation”, which is used when developing a model of an engineering system?
Explain the process of “validation”, which is used when developing a model of an engineering system?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT