Sunteți pe pagina 1din 8

Name : M.

Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
TASK 1:
Write a program that creates a calculator using inheritance..

Source Code:
package inheritence;
class Calculator
{ int x,y;
void display()
{System.out.println("calculation:"); }}
class Sum extends Calculator
{ void sum()
{System.out.println("sum of x and y: "+(x+y));
}}class Min extends Calculator
{ void min()
{System.out.println("subtraction of x and y: "+(x-y));
}}class Div extends Calculator
{ void div()
{System.out.println("division of x and y: "+(x/y));
}}class Mul extends Calculator
{ void mul()
{System.out.println("multiplication of x an d y: "+(x*y));
}}
public class Inheritence {
public static void main(String[] args) {
Calculator c=new Calculator();
Sum s=new Sum();// TODO code application logic here
Min mi=new Min();
Div d=new Div();
Mul m=new Mul();
s.x=10;
s.y=20;
mi.x=30;
mi.y=25;
d.x=50;
d.y=25;
m.x=4;

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
m.y=4;
c.display();
s.sum();
mi.min();
d.div();
m.mul();
}}

Output:

TASK 2:
Write a program that calculate area of different shapes using polymorphism.
Source Code:
package shapes_polymorphism;
class Figure {
double no1;
Figure(double n)
{
this.no1=n;
}
void Area()
{System.out.println("use to print area of diffeerent shapes:");
}}

class Circle extends Figure

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
{
Circle(double no)
{super(no);
}
void Area()
{
System.out.println("area of circle is: "+(Math.PI*Math.pow(no1, 2)));
}
}
class Rectangle extends Figure {

double no2;
Rectangle(double x, double y)
{
super(x);
this.no2=y;
}
void Area()
{ System.out.println("area of rectangle is: "+(no1*no2));}
}
class Square extends Figure{
Square(double no3)
{ super(no3);
}
void Area()
{System.out.println("area of square is: "+(Math.pow(no1, 2)));
}}
public class Shapes_polymorphism {
public static void main(String[] args) {
Figure f = new Figure(3);
Circle c = new Circle(21);
Square s = new Square(22);
Rectangle r = new Rectangle(6,7);
f=r;
r.Area();
f=c;
c.Area();
f=s;

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
s.Area();
}}

Output:

TASK 3:
Write a program that creates Greeting card using polymorphism.
Source Code:
package greet_card;

class Cards

String str1,str2;

Cards(String s1,String s2)

{ this.str1=s1;

this.str2=s2;

void cards()

{System.out.println(" "+str1);

System.out.println("MSG=_________________");

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
System.out.println(" "+str2);

class Bdaycard extends Cards

Bdaycard(String s4,String s5)

super(s4,s5);

void bwish()

System.out.println("\n");

System.out.println("************************************");

System.out.println(" "+str1);

System.out.println("HAPPY BIRTHDAY....:)");

System.out.println(" "+str2);

System.out.println("************************************");

System.out.println("\n");

class Eidwishes extends Cards

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
Eidwishes(String s7,String s8)

super(s7,s8);

void ewish()

System.out.println("\n");

System.out.println("************************************");

System.out.println(" "+str1);

System.out.println("EID MUBARAK....:)");

System.out.println(" "+str2);

System.out.println("************************************");

System.out.println("\n");

class Weddingcards extends Cards

Weddingcards(String s10,String s11)

super(s10,s11);

void wwish()

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
System.out.println("\n");

System.out.println("************************************");

System.out.println(" "+str1);

System.out.println("HAPPY WEDDING DAY....:)");

System.out.println(" "+str2);

System.out.println("************************************");

System.out.println("\n");

public class Greet_Card {

public static void main(String[] args) {

Cards c=new Cards("TO= _______________","FROM= _______________");

c=c;

c.cards();

Bdaycard b=new Bdaycard("TO= Hadi Mirza","FROM= Fahad Siddiqui");

c=b;

b.bwish();

Eidwishes e=new Eidwishes("TO= Saima Jamal","FROM= Fahad Siddiqui");

c=e;

e.ewish();

Weddingcards w=new Weddingcards("TO= Mr. & Mrs. Ali Aqdas","FROM= Fahad Siddiqui");// TODO
code application logic here

Submitted to : Miss Fizzah


Name : M. Fahad Siddiqui
Roll #: 206
Section : E

SIR SYED UNIVERSITY OF ENGINEERING AND TECHNOLOGY


SOFTWARE ENGINEERING

LAB # 8 :
c=w;

w.wwish();

}}Output:

Submitted to : Miss Fizzah

S-ar putea să vă placă și