import java.io.*;
import java.util.*;
interface shape
{
void getdata(double i,double j);
void area();
}
class triangle implements shape
{
public double x,y;
public void getdata(double i,double j)
{
x=i;
y=j;
//System.out.println("\n Enter Base and Height of Triangle :"+"\n BAse :");
//Scanner sc=new Scanner(System.in);
//x=sc.nextDouble();
//System.out.println("\n Height :");
//y=sc.nextDouble();
}
public void area()
{
System.out.println("\n Area of Triangle is :"+(0.5*x*y));
}
}
class rectangle implements shape
{
public double x,y;
public void getdata(double i,double j)
{
x=i;
y=j;
/* System.out.println("\n Enter Sides of Rectangle :"+"\n Side 1 :");
Scanner sc=new Scanner(System.in);
x=sc.nextDouble();
System.out.println("\n Side 2 :");
y=sc.nextDouble();
*/
}
public void area()
{
System.out.println("\n Area of Rectangle is :"+(x*y));
}
}
class inherit
{
public static void main(String []std)
{
int ch;
double a,b;
System.out.println("\n Enter two values :"+"\n a :");
Scanner sc=new Scanner(System.in);
a=sc.nextDouble();
System.out.println("\n Height :");
b=sc.nextDouble();
do
{
System.out.println("\n Menu 1.Triangle \n 2.Rectangle \n 3.Exit \n Enter your choice :");
Scanner s=new Scanner(System.in);
ch=s.nextInt();
switch(ch)
{
case 1: triangle t1=new triangle();
t1.getdata(a,b);
t1.area();
break;
case 2: rectangle r=new rectangle();
r.getdata(a,b);
r.area();
break;
case 3: System.exit(1);
}//switch
}while(ch!=3); //do
} //main
}//class
import java.util.*;
interface shape
{
void getdata(double i,double j);
void area();
}
class triangle implements shape
{
public double x,y;
public void getdata(double i,double j)
{
x=i;
y=j;
//System.out.println("\n Enter Base and Height of Triangle :"+"\n BAse :");
//Scanner sc=new Scanner(System.in);
//x=sc.nextDouble();
//System.out.println("\n Height :");
//y=sc.nextDouble();
}
public void area()
{
System.out.println("\n Area of Triangle is :"+(0.5*x*y));
}
}
class rectangle implements shape
{
public double x,y;
public void getdata(double i,double j)
{
x=i;
y=j;
/* System.out.println("\n Enter Sides of Rectangle :"+"\n Side 1 :");
Scanner sc=new Scanner(System.in);
x=sc.nextDouble();
System.out.println("\n Side 2 :");
y=sc.nextDouble();
*/
}
public void area()
{
System.out.println("\n Area of Rectangle is :"+(x*y));
}
}
class inherit
{
public static void main(String []std)
{
int ch;
double a,b;
System.out.println("\n Enter two values :"+"\n a :");
Scanner sc=new Scanner(System.in);
a=sc.nextDouble();
System.out.println("\n Height :");
b=sc.nextDouble();
do
{
System.out.println("\n Menu 1.Triangle \n 2.Rectangle \n 3.Exit \n Enter your choice :");
Scanner s=new Scanner(System.in);
ch=s.nextInt();
switch(ch)
{
case 1: triangle t1=new triangle();
t1.getdata(a,b);
t1.area();
break;
case 2: rectangle r=new rectangle();
r.getdata(a,b);
r.area();
break;
case 3: System.exit(1);
}//switch
}while(ch!=3); //do
} //main
}//class
Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing dude.
ReplyDeleteRegards,
Python Training in Chennai|Python Training