Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 else 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 something similar to the example at the very bottom when you choose the option sorted with COTTAGES.

[The Task]

image text in transcribed

[Class Apartment]

image text in transcribed

[Interface CityProperty]

image text in transcribed

[Class Building]

image text in transcribed

[ Class Cottage]

image text in transcribed

[Class Villa]

image text in transcribed

[Class Lab5]

image text in transcribed

[Class EstateAgent]

image text in transcribed

[Result example if sorted with COTTAGES]

image text in transcribed

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); Sorted by price Estate agont: Watson Property All buildings Address: Kungsgatan 7, Living anes: 115, Price:2500009, 69, Maintenance (per month):640e,60 Preperty tax: 1306,6 Mddress: Villavgen 13, Living arwa: 180, Price:67eee0e,e0, Ma1ntenance (per month):350e,00 Property tax: 4808.8 Address: flydgatan 4, Living area: 8e, Price: 500000,60 , Maintenance (per month): 260, 60 Mddress: Ektorpgatan 28, Living area: 92, Price:20ee009, 69, Maintenkne (per month):5360,60 Property tax: 1e7e.0 Address: Hagavgen, Living arsa: 62, Price:16eee0e,e0, Maintenance (per month):45ee,e0 Property tax: 670.0 Address: Kneippgatan 3, Living area: 210, Price:7900000, 69, Maintensnce (per month):3600, 69 Preperty tax: 4760,0 Address: VItterngatan 18, Living arwa: 198, Price:90eeee0,e0, Maintenance (per month):31ee,e0 Property tax: 4586.8 Address: 5jdvgen 22, Living areat 70, Price: 620000,69, Maintenance (per month) : 4e0, 00 Mddress: Vildmarkugen 1, Living area: 100, Price: 850000260, Maintenwnce (per month): 100,69 Mddress: Lindvgen 18, Living arwa: 98, Price: 958e00,e0, Maintenance (per month): 28e,e0 Cottages Mddress: Rydgatan 4, Living arwa: 80, Price: 50ee00,60, Maintenance (per month): 20e,e0 Address: 5jdvgen 22, Living areat 78, Price: 62ee00,00, Maintenance (per month): 480 , 00 Address: Vildmarkugen 1, tiving ares: 100, Price: 850000269, Maintenunce (per month): 100,60 Mddress: Lindvgen 18, Living arwa: 98, Price: 958ee0,e0, Maintenance (per month): 28e,e0 Vi11as and apartments Address: Kungsgatan 7, Living area: 115, Price:25eee00,60, Maintenkce (per month):646e, 60 Property tax: 1308.8 Mddress: Villavgen 13, Living arsa: 180, Price:67beee0,e0, Maintenance (per month):358e,e0 Property tax: 4800,0 Address: Ektorpgatan 28, Living anea: 92, Price:200e000, 60, Maintensnce (per month):5300,69 Preperty tax: 1070, Mddress: Hagavgen, Living arwa: 62, Price:160ee0,e0, Maintenance (per month):458e,e0 Property tax: 678. Address: Kneippgatan 3, Living areat 210, Price:79eee0e,69, Maintenance (per month) r 36ee, 00 Property tsx: 4700, Mddress: Vitterngatan 18, Living area: 196, Price:90ee000,60, Maintenance (per month):316e, 60 Property tax: 450e.8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

The heart and soul of the Toyota Way is:

Answered: 1 week ago

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago