Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

PROGRAM - 13

Program -
Shapearea file -

//Abstract class

abstract class Shapearea

abstract void getarea();

abstract void getperimeter(); }

Circle file -

class Circle extends Shapearea

int radius;

public Circle(int r){

this.radius = r;}

public void getarea(){

float area = 3.14f*radius*radius;

System.out.println("Radius:- "+radius);

System.out.println("Area:- "+area);}

public void getperimeter(){

float p = 2*3.14f*radius;

System.out.println("Perimeter:- "+p);}

public static void main(String args[]){

Circle c = new Circle(10);

c.getarea();

c.getperimeter();}

Rectangle file -

class Rectangle extends Shapearea

int length;int breadth;

public Rectangle(int l,int b)

{
this.length = l;

this.breadth = b;

public void getarea()

float area = length*breadth;

System.out.println("Length:- "+length);

System.out.println("Breadth:- "+breadth);

System.out.println("Area:- "+area);

public void getperimeter()

float p = 2*(length+breadth);

System.out.println("Perimeter:- "+p);

public static void main(String args[])

Rectangle r = new Rectangle(10,5);

r.getarea();

r.getperimeter();

Square file -

class Square extends Shapearea

int side;

public Square(int s)

this.side = s;

public void getarea()

float area = side*side;

System.out.println("Side:- "+side);
System.out.println("Area:- "+area);

public void getperimeter()

float p = 4*(side);

System.out.println("Perimeter:- "+p);

public static void main(String args[])

Square s = new Square(10);

s.getarea();

s.getperimeter();

Output -
Radius:- 10

Area:- 314.0

Perimeter:- 62.800003

Length:- 10

Breadth:- 5

Area:- 50.0

Perimeter:- 30.0

Side:- 10

Area:- 100.0

Perimeter:- 40.0
PROGRAM - 14
Program -
Account file -

//abstract class

abstract class Account

abstract void deposit();

abstract void withdraw();

Savings file -

class Savings extends Account

int balance;

public Savings(int s)

this.balance = s;

public void deposit()

System.out.println("Deposit Successful!!" );

public void withdraw()

if(this.balance<100)

System.out.println("Balance is low :: "+this.balance+"\nTherefore Withdrawal failed!!" );

else

System.out.println("Balance is :: "+this.balance+"\n Withdrawal Successful!!" );

public static void main(String args[])

Savings s = new Savings(10);


s.withdraw();

Current file -

class Current extends Account

int no_of_transaction;

public Current(int s)

this.no_of_transaction = s;

public void deposit(){

if(this.no_of_transaction<2)

System.out.println("Deposit failed!!\nDue to more no. of Transactions" );

else

System.out.println("Deposit Successful!!" );

}}

public void withdraw(){

System.out.println("Withdrawal Successful!!" );}

public static void main(String args[]){

Current c = new Current(1);

c.deposit();}

OUTPUT-
Balance is low :: 10

Therefore Withdrawal failed!!

Deposit failed!!

Due to more no. of Transactions

You might also like