Question: Hi, I need help with 4 simple and short methods so my JAVA code is finished. Mostly I want to get how to fix the
Hi, I need help with 4 simple and short methods so my JAVA code is finished. Mostly I want to get how to fix the sort method as it uses JOptionPane, which is new to me. So full detail on how to use that import javax.swing.JOptionPane; would be nice. You may import more like import java.util.Arrays; or anything els if need but explain in that case why. I have attached photos of all of the codes and the instruction/task for the 4 methods that needed to be fixed. Also, check that it works correctly by running the class Lab5 so you get the same as the photo Result. You are not allowed to change anything else in any classes or methods or variables Except for the sort method ofc.
[The Task]

[Class Apartment]

[Interface CityProperty]

[Class Building]

[ Class Cottage]

[Class Villa]

[Class Lab5]

[Class EstateAgent]

Make the method public String sort(int arg). It should ask you with a pop-up window if you want to sort by price or area asking "Sorting by price (1) or area (2)?". It should set the value of the class variable of Building to this value (if it is 1 or 2 ). If the value of arg is ALLBUILDINGS, then it should sort theBuildings and call the method updateLists(). 3 If the value of arg is COTTAGES, then sort(arg) should sort theCottages and call updateLists(COTTAGES). If the value of arg is CITYBUILDINGS, then sort(arg) should sort theCityBuildings and call updateLists(CITYBUILDINGS). You will not be able to sort theCityBuildings because you cannot apply Collections sort() to arrays of interfaces. You need to deepcopy it to an array of Building, sort it, and deep-copy it back after that. sort(arg) should return "Sorted by price", "Sorted by area" or "Not sorted" followed by a line break, depending on the value you entered in the pop-up window. updateLists() should update the order of the cottages and city buildings in the arrays theCottages and theCityBuildings such that they match that in theBuildings. update Lists(int arg) changes the ordering of the cottages in theBuildings based on the ordering in theCottages if arg is COTTAGES. If arg is CITYBUILDINGS, then it changes the ordering of the city buildings in theBuildings based on that in theCityBuildings. to String() should return "Estate agent: n followed by the value of NAME and a line break. Then you attach the string "All buildings" followed by a line break followed by the return values of all elements of theBuildings. Note that each of these return strings has two lines. Cottages have a second blank line so that we can distinguish them from villas and apartments. Then you attach "Cottages" preceded and followed by line breaks. This string is followed by the return values of the toString() methods of all elements of theCottages. Finally, you attach the string "Villas and apartments" preceded and followed by a line break and followed by the return values of the toString() methods of all elements of theCityBuildings. [The section in Lab5 labeled "Diagnostics for the estate agent" should give you the output on the next page. The sorting methods (sort by price) should give you the package lab5; public class Apartment extends Building implements CityProperty \{ private double monthlyFee; private int bedrooms; public Apartment(String address, double price, int squareMeters, double monthlyFee, int bedrooms) \{ super(address, price, squareMeters); this.monthlyFee = monthlyFee; this.bedrooms = bedrooms; public int getBedrooms() return bedrooms; \} public double maintenance() \{ return monthlyFee; public double computePropertyTax() \} return 10 squareMeters +50 bedrooms; package lab5; public interface CityProperty \{ abstract double computePropertyTax(); \} package lab5; public class Cottage extends Building \{f private double electricity; public Cottage(String arg1, double arg2, int arg3, double arg4) \{ super(arg1, arg2, arg3); this.electricity = arg4; \} public double maintenance() return electricity; \} ublic class Lab5 \{ public static void main(String[] args) \{. /loiagnostics for buildings Cattage mycattage - new cattage("Vildnarkvajgen 1", 850909.6, 109, 109.6); System.out.println(mycottage); Apartment myApartment - new Apartment("Kungsgatan 7", 250993..e, 115, 6499.e, 3); System.ourt.println(myApartment): villa myvilla - new villa("Villavgen 13", 6709999.6, 189, 2099.6, 1509.e, 4); System.ourt.println(myvilla); /f Diagnastics for the estate agent EstateAgent theEstateAgant - new Estate4gent ("Watsan Property"); theEstatoAgent. gddRhilding(iryApartment); theEstato4gent. gddRhilding(myvilla); theEstatoAgent.gddRhilding(mycottage); 1609993.e, 62, 4509.e, 1)) Systan.ourt.println(theEstatoAgent): Il sarting all buildings System.ourt.println(theEstateAgent); I/ Sorting cattages Systam.ourt.println(theEstateAgent); If Sorting city buildings Systan.out.println(theEstateAgent)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
