0% found this document useful (0 votes)
28 views

Niii

The document contains the code for several Java classes: - Bank class to store customer name, account number, principal amount - Interest class extends Bank to calculate compound interest - Perimeter class calculates perimeter of a rectangle - Area class extends Perimeter to also calculate area of a rectangle - Shelf class implements a shelf data structure to push and pop double values - WordPile class implements a stack data structure to push and pop character values - Demand class stores product information - Supply class extends Demand to also store production quantities and calculate difference between demand and supply

Uploaded by

contactmdasif007
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)
28 views

Niii

The document contains the code for several Java classes: - Bank class to store customer name, account number, principal amount - Interest class extends Bank to calculate compound interest - Perimeter class calculates perimeter of a rectangle - Area class extends Perimeter to also calculate area of a rectangle - Shelf class implements a shelf data structure to push and pop double values - WordPile class implements a stack data structure to push and pop character values - Demand class stores product information - Supply class extends Demand to also store production quantities and calculate difference between demand and supply

Uploaded by

contactmdasif007
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/ 9

import java.util.

*;
class Bank
{
String name;
int acc_no;
double principal;
Bank(String n,int a,double p)
{
name=n;
acc_no=a;
principal=p;
}
void display()
{
System.out.println("Name of customer : "+name);
System.out.println("Account number : "+acc_no);
System.out.println("Principal amount : "+principal);
}
}
import java.util.*;
class Interest extends Bank
{
double rate,time;
Interest(String n,int a,double p,double r,double t)
{
super(n,a,p);
rate=r;
time=t;
}
double calculate()
{
double ci=(principal*(Math.pow((1+rate/100),time)))-principal;
return ci;
}
void display()
{
super.display();
System.out.println("Compound Interest = "+calculate());
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name of customer");
String nm=sc.nextLine();
System.out.println("Enter account number");
int ac=sc.nextInt();
System.out.println("Enter principal amount");
double pr=sc.nextDouble();
System.out.println("Enter rate");
double rt=sc.nextDouble();
System.out.println("Enter time");
double tm=sc.nextDouble();
Interest ob=new Interest(nm,ac,pr,rt,tm);
ob.display();
}
}
import java.util.*;
class Perimeter
{
double a,b;
Perimeter(double x,double y)
{
a=x;
b=y;
}
double calculate()
{
double p=2*(a+b);
return p;
}
void show()
{
System.out.println("Length = "+a);
System.out.println("Breadth = "+b);
System.out.println("Perimeter = "+calculate());
}
}
import java.util.*;
class Area extends Perimeter
{
double h,area;
Area(double x,double y,double z)
{
super(x,y);
h=z;
}
void doarea()
{
area=b*h;
}
void show()
{
super.show();
System.out.println("Height = "+h);
System.out.println("Area = "+area);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length");
double len=sc.nextDouble();
System.out.println("Enter the breadth");
double br=sc.nextDouble();
System.out.println("Enter the height");
double ht=sc.nextDouble();
Area ob=new Area(len,br,ht);
ob.doarea();
ob.show(); } }
import java.util.*;
class Shelf
{
double ele[];
int lim,front,rear;
Shelf(int n)
{
lim=n;
front=0;
rear=0;
ele=new double[lim];
}
void pushVal(double v)
{
if(rear==lim)
System.out.println("SHELF IS FULL");
else
ele[rear++]=v;
}
double popVal()
{
double d;
if(front==-1 && rear==-1)
return -999.99;
else
{
d=ele[front];
front++;
}
return d;
}
void display()
{
for(int i=front;i<=rear;i++)
System.out.print(ele[i]+"\t");
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size");
int s=sc.nextInt();
Shelf ob=new Shelf(s);
double x[]=new double[s],p=0.0;
for(int i=0;i<s;i++)
{
System.out.println("Enter a value");
x[i]=sc.nextDouble();
p=x[i];
ob.pushVal(p);
}
System.out.println("Elements of Shelf");
for(int i=0;i<s;i++)
System.out.print(x[i]+"\t");
System.out.println();
System.out.println("Deleted value = "+ob.popVal());
}
import java.util.*;

class WordPile

char ch[];

int capacity,top;

WordPile(int cap)

capacity=cap;

top=-1;

ch=new char[capacity];

void pushChar(char v)

if(top==capacity-1)

System.out.println("Word Pile is full");

else

top++;

ch[top]=v;

char popChar()

char d;

if(top==-1)

return '\\';

else

d=ch[top];

top--;

return d;

void display()
{

for(int i=capacity-1;i>=0;i--)

System.out.println(ch[i]);

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter the size");

int s=sc.nextInt();

WordPile ob=new WordPile(s);

char val[]=new char[s],x;

for(int i=0;i<s;i++)

System.out.println("Enter a character");

val[i]=sc.next().charAt(0);

for(int i=0;i<s;i++)

x=val[i];

ob.pushChar(x);

ob.display();

System.out.println("Deleted character : "+ob.popChar());

}
import java.util.*;

class Demand

String pid,pname; int pdemand;

Demand(String id,String n,int dmd)

pid=id;

pname=n;

pdemand=dmd;

void display()

System.out.println("Product ID : "+pid);

System.out.println("Product name : "+pname);

System.out.println("Quantity demanded : "+pdemand);

import java.util.*;

class Supply extends Demand

int pproduced;

double prate;

Supply(String id,String n,int dmd,int pp,double pr)

super(id,n,dmd);

pproduced=pp;

prate=pr;

double calculation()

double x=prate*pdemand;

double y=prate*pproduced;

double dif=Math.abs(x-y);
return dif;

void display()

super.display();

System.out.println("Difference = "+calculation());

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter product name");

String nm=sc.nextLine();

System.out.println("Enter quantity demanded");

int pdm=sc.nextInt();

System.out.println("Enter quantity produced");

int ppr=sc.nextInt();

System.out.println("Enter cost of the product");

double rt=sc.nextDouble();

Supply ob=new Supply(i,nm,pdm,ppr,rt);

ob.display();

You might also like