Question

In: Computer Science

Create a Java application for Real Estates including Apartment and Homes. First, have a look at...

Create a Java application for Real Estates including Apartment and Homes. First, have a look at the class diagram that you will implement, and then read the explanation of these classes below.

RealEstate (interface)

+ setId (String s)

Apartment

- id: String

- surface: double

+ full argument constructor

+ getters and setters

+ setId (String s)

+ toString(): String

Home

- id: String

- hasGarage: boolean

+ full argument constructor

+ getters and setters

+ setId (String s)

+ toString(): String

Class RealEstate

  • Real estate is an interface with two abstract methods.

There are two types of real estates: Apartment and Home.

Class Apartment   

  • The class Apartment has three attributes: id and surface.

Class Home

  • The class Home has three attributes: id and hasGarage.

Test Class

  

  • Create an ArrayList called homes that contains two Home objects    
  • Remove the home doesn’t have a Garage.
  • Display the homes.

Information about objects are presented in what follows.

Home Objects

ID

hasGarage

H1234

No

H1235

Yes

  • Create an LinkedList called apart that contains three Apartment objects
  • Display the apart LinkedList

Information about objects are presented in what follows.

Apartment Objects

ID

Surface

A1234

125

A1235

205

A1236

200

  • Create a TreeSet called treeSurface that contains the surfaces of all the apartments.

Recall that: SortedSet <Double> treeSurface = new TreeSet<Double> ();

  • Display treeSurface
  • Display the smallest and largest surfaces.

Solutions

Expert Solution

java code

import java.util.*;
interface RealEstate
{
public void setId(String s);
}

class Apartment implements RealEstate
{
String id;
double surface;
public Apartment(String id, double surface)
{
this.id = id;
this.surface = surface;
}
public String getId()
{
return this.id;
}
public void setId(String s)
{
this.id = s;
}
public double getSurface()
{
return this.surface;
}
public void setSurface(double s)
{
this.surface = s;
}
public String toString()
{
return getId()+" "+getSurface()+"\n";
}
}

class Home implements RealEstate
{
String id;
boolean hasGarage;
public Home(String id, boolean hasGarage)
{
this.id = id;
this.hasGarage= hasGarage;
}
public String getId()
{
return this.id;
}
public void setId(String s)
{
this.id = s;
}
  
public boolean getHasGarage()
{
return this.hasGarage;
}
  
public void setHasGarage(boolean hasGarage)
{
this.hasGarage = hasGarage;
}
public String toString()
{
if (getHasGarage()==true)
return getId() +" Yes\n";
else
return getId() + " No\n";
}
}

public class Main
{
   public static void main(String[] args) {
   //Test part
       ArrayList<Home> homes = new ArrayList<Home>();
       homes.add(new Home("H1234",false));
       homes.add(new Home("H1235",true));
       System.out.println("Id hasGarage");
       System.out.println(homes.toString());
       for (int i = 0; i < homes.size(); i++)
       {
       if (homes.get(i).getHasGarage()==false)
       homes.remove(i);
       }
       System.out.println("Id hasGarage");
       System.out.println(homes.toString());
      
       LinkedList<Apartment> apart = new LinkedList<Apartment>();
       apart.add(new Apartment("A1234",125));
       apart.add(new Apartment("A1235",205));
       apart.add(new Apartment("A1236",200));
       System.out.println("Id Surface");
       System.out.println(apart.toString());
       SortedSet<Double> treeSurface = new TreeSet<Double>();
       for (int i = 0; i < apart.size(); i++)
       {
       treeSurface.add(apart.get(i).getSurface());
       }
       System.out.println(treeSurface.first());
       System.out.println(treeSurface.last());
   }
}

Output

Id hasGarage                                                       

[H1234 No                                                          

, H1235 Yes                                                        

]                                                                  

Id hasGarage                                                       

[H1235 Yes                                                         

]                                                                  

Id Surface                                                         

[A1234 125.0                                                       

, A1235 205.0                                                      

, A1236 200.0                                                      

]                                                                  

125.0                                                              

205.0  


Related Solutions

Create a Java application that will prompt the user for the first name of 6 friends...
Create a Java application that will prompt the user for the first name of 6 friends in any order and store them in an array. First, output the array unsorted. Next, sort the array of friends and then output the sorted array to the screen. Be sure to clearly label the output. See the example program input and output shown below. It does not have to be exactly as shown in the example, however it gives you an idea of...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Create a Java Swing form that will have two Buttons: (1) the first linked to an...
Create a Java Swing form that will have two Buttons: (1) the first linked to an event handler to write data from two TextFields on the form to an output file; and (2) the other with an event handler to read data from the same file as input and write output to a binary ObjectOutputStream file.
Create a PowersTable application that displays a table of of powers. ( Java Programing )
Create a PowersTable application that displays a table of of powers. ( Java Programing )
Create an application that uses a constructor and two different methods. JAVA
Create an application that uses a constructor and two different methods. JAVA
This is to done in Java: create the infrastructure for building a word cloud application. We...
This is to done in Java: create the infrastructure for building a word cloud application. We will do so by 1) Reading the content of a text file and creating a binary tree of words in that file. When a duplicate word is encountered. we simply increase the frequency count of that word in its corresponding node. In other words, the nodes in the tree have two parts. One part maintains the word, and the other maintains the frequency count....
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT