Question: In java programming: Refer to the above example and add constructors to Exercise 9 program. Compile and run the program. The program should contain constructors,

In java programming: Refer to the above example and add constructors to Exercise 9 program. Compile and run the program. The program should contain constructors, inheritance of class, appropriate variable, type and methods. Take a screen capture of program code and output. Here is the exercise 9 program code: class Area
{
double width;
double length;
// print method
void showDim()
{
System.out.println("Room dimension: "+ length +" feet and "+ width +" feet");
}
}
class Home extends Area
{
String room;
double area()
{
return width * length;
}
void showRoom()
{
// print room type method
System.out.println(room);
}
}
class House
{
public static void main(String args[])
{
// create new instances
Home r1= new Home();
Home r2= new Home();
Home r3= new Home();
Home r4= new Home();
// assign values to designated rooms
r1.width =18;
r1.length =20;
r1.room = "Living Room";
r2.width =13;
r2.length =18;
r2.room = "Master Bedroom";
r3.width =12.0;
r3.length =14.0;
r3.room = "Kitchen";
r4.width =14.0;
r4.length =16.0;
r4.room = "Dining Room";
// print info
r1.showRoom();
r1.showDim();
System.out.println("Area is "+ r1.area());
System.out.println();
r2.showRoom();
r2.showDim();
System.out.println("Area is "+ r2.area());
System.out.println();
r3.showRoom();
r3.showDim();
System.out.println("Area is "+ r3.area());
System.out.println();
r4.showRoom();
r4.showDim();
System.out.println("Area is "+ r4.area());
System.out.println();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!