0% found this document useful (0 votes)
64 views8 pages

Task 1:: Sir Syed University of Engineering and Technology

This document contains the source code and output for 3 programming tasks: 1) A calculator program using inheritance with classes for addition, subtraction, etc. 2) A shape area calculator using polymorphism with classes for circle, rectangle, square. 3) A greeting card program using polymorphism with classes for birthday, Eid, wedding cards.

Uploaded by

Fahad Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views8 pages

Task 1:: Sir Syed University of Engineering and Technology

This document contains the source code and output for 3 programming tasks: 1) A calculator program using inheritance with classes for addition, subtraction, etc. 2) A shape area calculator using polymorphism with classes for circle, rectangle, square. 3) A greeting card program using polymorphism with classes for birthday, Eid, wedding cards.

Uploaded by

Fahad Siddiqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy