Write a class called StorageBuilding that is a subclass of Building. In addition
ID: 3622829 • Letter: W
Question
Write a class called StorageBuilding that is a subclass of Building. In addition to name, a StorageBuilding has two other member variables1. length of type double
2. width of type double
Methods
1. A constructor that accepts the name, length, and width of the StorageBuilding. Make sure that the super class handles the name of the Storage Building
2. A findArea method that computes and returns the area of the building (length*width)
3. A toString that produces a String representation of a storage building as illustrated in the
following example:
Building Name : Maintenance Storage
Length :15
Width :20
Storage Area :300sq.ft
Explanation / Answer
please rate - thanks
public class StorageBuilding extends Building
{double length;
double width;
StorageBuilding(String n,double l, double w)
{super(n);
length=l;
width=w;
}
public double findArea()
{return length*width;
}
public String toString()
{String out="Building name : "+name+" ";
out=out+"Length: "+length+" Width: "+width+" ";
out=out+"Storage Area: "+findArea()+"sq.ft";
return out;
}
}
--------------------------------------------
import java.util.*;
public class BuildingDriver {
public static void main (String[] args) {
Building b=new Building("Twin Towers");
System.out.println(b.toString());
Dormitory d=new Dormitory("Twin Towers",15,true);
System.out.println(d.toString());
StorageBuilding s=new StorageBuilding("Maintenance Storage",15,20);
System.out.println(s.toString());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.