Lab Assignment3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Name : Laiba Ishtiaq

Reg no : FA21-BSE-047
Subject:OOP
Class : BSE-3B
Submitted to : Mam Samia riaz

Question:
write a program that fulfill Heretical inheritance.?
Answer:
import java.util.*; class
Shapes
{
protected String Color;
protected Boolean Fill;
public void Set_Color (String c)
{
this.Color = c;
}

public void Set_Fil (Boolean b)


{
this.Fill = b;
}
}

class circle extends Shapes


{
private double radius;
private double Area; private
double Perimeter;
private double circumfarance;
public void set_radius()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the raduis of circle = ");
double r = in.nextDouble();
this.radius = r;
}

public void Set_Area()


{
this.Area = 3.14 * (radius*radius);
}

public void Set_perimeter()


{
this.Perimeter = 2* 3.14 *radius;
}
public void Set_circumfarance()
{
this.circumfarance = 2* 3.14 *radius;
}

public void get_info_circle()


{

System.out.println("======================================);
System.out.println(" Circle\n ");
System.out.println("The Area Of Circle is = " + this.Area);
System.out.println("The perimeter of Circle = " + this.Perimeter);
System.out.println("The Circumfarance of Circle = " + this.circumfarance);
System.out.println("The Color of your Circle is = " + this.Color);
System.out.println("Circle is Filled or not = " + this.Fill);
System.out.println("=====================================");
}
}

class square extends Shapes


{
private double length;
private double Area; private double
Perimeter; public void
set_length()
{
System.out.println("");
Scanner in = new Scanner(System.in);
System.out.print("Enter the length of Square = ");
double len = in.nextDouble();
this.length = len; System.out.println("");
}

public void Set_Square_Area()


{
this.Area = length * length;
}

public void Set_Square_perimeter()


{
this.Perimeter = 4*length;
}

public void get_Square_info()


{

System.out.println("======================================");
System.out.println(" Square\n ");
System.out.println("The Area Of Square is = " + this.Area);
System.out.println("The perimeter of Square = " + this.Perimeter);
System.out.println("The Color of your Square is = " + this.Color);
System.out.println("Square is Filled or not = " + this.Fill);
System.out.println("======================================");
}
}

class rectangle extends Shapes


{
private double length;
private double width; private
double R_Area;
private double Perimeter;

public void set_Sides()


{
System.out.println("");
Scanner in = new Scanner(System.in);
System.out.print("Enter the length of Rectangle = ");
double len = in.nextDouble();
this.length = len;
System.out.print("Enter the width of Rectangle = ");
double wed = in.nextDouble();
this.width = wed; System.out.println("");
}

public void Set_Rectangle_Area()


{
this.R_Area = (length * width);
}

public void Set_Rectangle_perimeter()


{
this.Perimeter = 2 *(length + width);
}

public void get_Rectangle_info()


{

System.out.println("=====================================");
System.out.println(" Rectangle\n ");
System.out.println("The Area Of Rectangle is = " + this.R_Area);
System.out.println("The perimeter of Rectangle = " + this.Perimeter);
System.out.println("The Color of your Rectangle is = " + this.Color);
System.out.println("Rectangle is Filled or not = " + this.Fill);
System.out.println("======================================");
}

class triangle extends Shapes


{
private double Base;
private double Prep; private
double Hyp; private double
T_Area;
private double T_Perimeter;

public void set_Sides()


{
System.out.println("");
Scanner in = new Scanner(System.in);

System.out.print("Enter the Base of Triangle = ");


double base = in.nextDouble();
this.Base = base;
System.out.print("Enter the Prep of Triangle = ");
double prep = in.nextDouble(); this.Prep =
prep; System.out.print("Enter the Hyp of
Triangle = ");
double hyp = in.nextDouble();
this.Hyp = hyp;
System.out.println("");
}

public void Set_Triangle_Area()


{
this.T_Area = (Base * Prep);
}

public void Set_Triangle_perimeter()


{
this.T_Perimeter = Base + Prep + Hyp;
}

public void get_Triangle_info()


{

System.out.println("======================================");
System.out.println(" Triangle\n ");
System.out.println("The Area Of Triangle is = " + this.T_Area);
System.out.println("The perimeter of Triangle = " + this.T_Perimeter);
System.out.println("The Color of your Triangle is = " + this.Color);
System.out.println("Triangle is Filled or not = " + this.Fill);
System.out.println("=====================================");
}
} public class
Harerical_inheratince
{
public static void main(String args[])
{
circle c = new circle();
c.set_radius();
c.Set_Color("Red");
c.Set_Fil(Boolean.TRUE);
c.Set_Area();
c.Set_perimeter();
c.Set_circumfarance();
c.get_info_circle();
square s = new square();
s.set_length();
s.Set_Color("Green");
s.Set_Fil(Boolean.FALSE);
s.Set_Square_Area();
s.Set_Square_perimeter();
s.get_Square_info();

rectangle r = new rectangle();


r.set_Sides();
r.Set_Color("Orange");
r.Set_Fil(Boolean.TRUE);
r.Set_Rectangle_Area();
r.Set_Rectangle_perimeter();
r.get_Rectangle_info();

triangle t = new triangle();


t.Set_Color("Black");
t.Set_Fil(Boolean.FALSE);
t.set_Sides();
t.Set_Triangle_Area();
t.Set_Triangle_perimeter();
t.get_Triangle_info();
}
}

You might also like