You are on page 1of 8

SUBMITTED TO : Samia Raiz

SUBMITTED BY : DANISH EJAZ


REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

Question no 1:
interface Shapes
{
int Number_of_line = 0;
String PenColor = null;
boolean Color_Fill =true;
void Draw();
}
class Circle implements Shapes
{
@Override
public void Draw()
{
System.out.println("The Circle is Drawn");
}
}
class Square implements Shapes
{
@Override
public void Draw()
{
System.out.println("The Square is Drawn");
}
}
class Triangle implements Shapes
{
@Override
public void Draw()
{
System.out.println("The Triangle is Drawn");
}
}

public class Main


{
public static void main(String args [])
{
Circle c = new Circle();
c.Draw();

Square S = new Square();


S.Draw();

1|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

Triangle T = new Triangle();


T.Draw();
}
}

Question no 2:
interface Student
{
public abstract void take_exam();
}
class PhD_Students implements Student
{
public void take_exam()
{
System.out.println("I am PHD student and i give Defense Paper");
}
}
class Graduation_Students implements Student
{
public void take_exam()
{
System.out.println("I am Graduate Student and i give Written papers");
}
}
public class StudentAbstract
{
public static void main(String args [])
{
PhD_Students phS = new PhD_Students();
phS.take_exam();
Graduation_Students gS = new Graduation_Students();
gS.take_exam();
}
}

Question 3:
abstract class shapes
{
private String color;
private boolean filled ;
shapes()

2|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

{
this.color = "Red";
this.filled = true;
}
shapes(String c, boolean b)
{
this.color = c;
this.filled = b;
}
public void set_color()
{
this.color = "Orange";
}
public String get_color()
{
return this.color;
}
public void set_filling()
{
this.filled = true;
}
public boolean get_filling()
{
return this.filled;
}

public abstract double get_Area();


public abstract double get_Parameter();
}

class Circle extends shapes


{
private double radius;

public void set_Radis(double r)


{
this.radius = r;
}
public double get_Radis()
{
return this.radius;
}
public double get_Area()
3|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

{
double Area = (3.14)*this.radius*this.radius;
return Area;
}
public double get_Parameter()
{
double paremeter = 2 * (3.14) * this.radius;
return paremeter;
}
}

class Rectangle extends shapes


{
private double length;
private double width;

public void set_length(double l)


{
this.length = l;
}

public void set_width(double w)


{
this.width = w;
}
public double get_Area()
{
double Area = this.length * this.width;
return Area;
}
public double get_Parameter()
{
double paremeter = 2 * (this.length + this.width);
return paremeter;
}
}

public class Abstraction


{
public static void main(String args [])
{
Circle c1 = new Circle();
c1.set_Radis(3.4);
4|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

System.out.println("The Area of Circle = " + c1.get_Area());


System.out.println("The Circumfarance of Circle = " + c1.get_Parameter());
Rectangle R1 = new Rectangle();
R1.set_length(5);
R1.set_width(8);
System.out.println("\n\nThe Area of Rectangle = " + R1.get_Area());
System.out.println("The Parameter of Rectangle = " + R1.get_Parameter());
}
}

Question 4:
interface Animals
{
void sound();
void food();
}
abstract class Animals_Attributes
{
private String Color;
private String Type;

public void set_Color(String c)


{
this.Color = c;
}
public String get_Color()
{
return this.Color;
}
public void set_Type(String t)
{
this.Type = t;
}
public String get_Type()
{
return this.Type;
}
}

class Cat extends Animals_Attributes implements Animals


{

@Override
5|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

public void sound()


{
System.out.println("The Sound of Cat is meewoun");
}

@Override
public void food()
{
System.out.println("The Food of Cat is milk");
}

public void Display()


{
System.out.println("====================================================");
sound();
food();
set_Color("black");
set_Type("Domestic");
System.out.println("The Color of cat is = " + get_Color());
System.out.println("The Type of cat is = " + get_Type());
System.out.println("====================================================");
}
}
class Dog extends Animals_Attributes implements Animals
{

@Override
public void sound()
{
System.out.println("The Sound of Dog is Boowuuwuw");
}

@Override
public void food()
{
System.out.println("The Food of Dog is Bone");
}

public void Display()


{
System.out.println("====================================================");
sound();
food();
6|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

set_Color("white");
set_Type("Domestic");
System.out.println("The Color of Dog is = " + get_Color());
System.out.println("The Type of Dog is = " + get_Type());
System.out.println("====================================================");
}
}
class Tiger extends Animals_Attributes implements Animals
{

@Override
public void sound()
{
System.out.println("The Sound of Tiger is hakkkaaa");
}

@Override
public void food()
{
System.out.println("The Food of Tiger is Meat");
}

public void Display()


{
System.out.println("====================================================");
sound();
food();
set_Color("Orangish with black Strips");
set_Type("Wild");
System.out.println("The Color of Tiger is = " + get_Color());
System.out.println("The Type of Tiger is = " + get_Type());
System.out.println("====================================================");
}
}
public class NewClass2
{
public static void main(String args [])
{
Cat c = new Cat();
c.Display();

Dog D = new Dog();


D.Display();
7|Page
SUBMITTED TO : Samia Raiz
SUBMITTED BY : DANISH EJAZ
REG NO : FA21-BSE-074
SECTION : BSE-3B
DEPERTMENT : COMPUTER SCIENCE

Tiger T = new Tiger();


T.Display();
}

8|Page

You might also like