- Engineering
- Computer Science
- add constructors to program listed compile a java run the...
Question: add constructors to program listed compile a java run the...
Question details
add constructors to program listed. Compile a java run the program. The program should contain constructors, inheritance of class, appropriate variable, type and methods.
Please include a picture of output and code.
class TwoDShape {
double width;
double length;
void showDim() {
System.out.println("Width and Length are " + width + "and" +
length);
}
}
class Rooms extends TwoDShape {
String style;
double area() {
return width * length;
}
}
class House {
public static void main(String args[]) {
Rooms Living = new Rooms();
Rooms Master = new Rooms();
Rooms Kitchen = new Rooms();
Rooms Dining = new Rooms();
Rooms Bath = new Rooms();
Rooms Guest = new Rooms();
Living.width = 18;
Living.length = 20;
System.out.println("Area for Living room is " +
Living.area());
System.out.println();
Master.width = 13;
Master.length = 18;
System.out.println("Area for Master bedroom room is " +
Master.area());
System.out.println();
Kitchen.width = 12;
Kitchen.length = 14;
System.out.println("Area for Kitchen room is " +
Kitchen.area());
System.out.println();
Dining.width = 14;
Dining.length = 16;
System.out.println("Area for Dining room is " +
Dining.area());
System.out.println();
Bath.width = 10;
Bath.length = 13;
System.out.println("Area for bath room is " + Bath.area());
System.out.println();
Guest.width = 15;
Guest.height = 17;
System.out.println("Area for Guest room is " + Guest.area());
System.out.println();
}
}
Solution by an expert tutor
