The following BuildingApplication class is incomplete. You need to complete the
ID: 3846252 • Letter: T
Question
The following BuildingApplication class is incomplete. You need to complete the missing lines of codes in:
inner class- Verification
main method
Note: Assume that the building occupies the middle of the plot horizontally and vertically. To approve a building application, a building needs to provide a minimum clearance of 1m from the edge of the plot. i.e., the difference between plot width and building width should be at least 2m; the difference between the plot length and building length should be at least 2m.
public class BuildingApplication
{ double plotLength;
double plotWidth;
double buildingLength;
double buildingWidth; boolean approved = false;
public BuildingApplication (double plotLength, double plotWidth, double buildingLength, double buildingWidth)
{ this.plotLength = plotLength;
this.plotWidth = plotWidth;
this.buildingLength = buildingLength;
this.buildingWidth = buildingWidth; }
/inner class class Verification
{ boolean objection ;
private static final double MINIMUM_REQUIRED = 2.0;
//constructor
public Verification()
{ objection = false; }
// end of constructor- Verification
boolean check()
{ // to return true if there is a minimum clearance of 1m in all sides of the building //Missing lines of codes have to be completed }
// end of check method }
// end of inner class
public void displayApproval()
{ Verification test = new Verification();
approved = test.check();
if(approved)
System.out.println("Building plan Approved");
else
System.out.println("Building plan Rejected");}
public static void main(String [] args)
{ /* Create two BuildingApplication objects and test whether they are approved or not. * You need to create one Building object that can be approved and the other that *cannot be approved */ //Missing lines of codes have to be completed }
// end of main method }
// end of BuildingApplication clas
Explanation / Answer
// Bean class
package sample1;
public class BuildingApplication
{
double plotLength;
double plotWidth;
double buildingLength;
public double getPlotLength() {
return plotLength;
}
public void setPlotLength(double plotLength) {
this.plotLength = plotLength;
}
public double getPlotWidth() {
return plotWidth;
}
public void setPlotWidth(double plotWidth) {
this.plotWidth = plotWidth;
}
public double getBuildingLength() {
return buildingLength;
}
public void setBuildingLength(double buildingLength) {
this.buildingLength = buildingLength;
}
public double getBuildingWidth() {
return buildingWidth;
}
public void setBuildingWidth(double buildingWidth) {
this.buildingWidth = buildingWidth;
}
double buildingWidth;
boolean approved = false;
public BuildingApplication (double plotLength, double plotWidth, double buildingLength, double buildingWidth)
{
this.plotLength = plotLength;
this.plotWidth = plotWidth;
this.buildingLength = buildingLength;
this.buildingWidth = buildingWidth;
}
class Verification
{
boolean objection ;
private static final double MINIMUM_REQUIRED = 2.0;
//constructor
public Verification()
{ objection = false; }
// end of constructor- Verification
boolean check()
{
if(plotLength-buildingLength>=MINIMUM_REQUIRED&&plotWidth-buildingWidth>=MINIMUM_REQUIRED){
objection= true;
}
else objection=false;
return objection;
}
}
public void displayApproval()
{
Verification test = new Verification();
approved = test.check();
if(approved)
System.out.println("Building plan Approved");
else
System.out.println("Building plan Rejected");
}
}
//Test driver class
package sample1;
public class test{
public static void main(String [] args)
{
BuildingApplication ba1=new BuildingApplication(102.0,52.0,101.0, 51.0);
BuildingApplication ba2=new BuildingApplication(104.0,54.0,102.0, 52.0);
ba1.displayApproval();
ba2.displayApproval();
}
}