Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM TO FIND VOLUME OF YOUR BEDROOM AND KITCHEN USING INHERITANCE
#1

Code:
import java.io.*;
class Broom
{
int  length,width,height;
Broom(int l,int w,int h)
{
length=l;
width=w;
height=h;
}
int  volume()
{
return(length*width*height);
}
}
class Kroom extends Broom
{
Kroom(int l,int w,int h)
{
super(l,w,h);
}
void display()
{
  System.out.println("Volume is:"+volume());
}
}

class Nbroom1
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter the parametrs of bedroom");
System.out.println("enter length");
int a=Integer.parseInt(dis.readLine());
System.out.println("enter width");
int b=Integer.parseInt(dis.readLine());
System.out.println("enter height");
int c=Integer.parseInt(dis.readLine());
Kroom k=new Kroom(a,b,c);
k.display();
System.out.println("enter the parametrs of kitchen");
System.out.println("enter length");
int g=Integer.parseInt(dis.readLine());
System.out.println("enter width");
int h=Integer.parseInt(dis.readLine());
System.out.println("enter height");
Int i=Integer.parseInt(dis.readLine());
Kroom k1=new Kroom(g,h,i);
k1.display();
}
}

OUTPUT
E:\ 5BCA-B\lijo\java >javac Nbroom1.java
E:\ 5BCA-B\lijo\java >java Nbroom1
enter the parametrs of bedroom
enter length
10
enter width
20
enter height
30
Volume is:6000
enter the parametrs of kitchen
enter length
1
enter width
3
enter height
2
Volume is:6
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.