>Pcog uam to calculate the compond interest
Pogpublie class Compound. IntenestË
publie atatie void main (Stoung a){
tloat A;
ploat P= l000;
float z 6;
gloat n- 5:
A=P
for (int i-l; i<-n ; i4+)$
A- A(1+ (/100 ));
System. oud.psuntln (Final amount = "4 A):
Output-
E'mol amount 1338. 2253
Puoqam b calculate the depaecition,
Popublie class Depse ciadion
publie stabic vaid main (Stingl arg)
float fc = 5000;
float sv = 200)
ploat s =5;
phoat dep - (fe- sv)/sy
System. out pintdn ('Depgeáaton "* dep);
Qulpuk
Debne aaion = 960.0
to cow et Fahenheit to Csius.
public class FtoC 3
publie statie void main(5bungl g)i
ploat f 93.6fi
Loot c - (f -32)* 5/9:
Sytam. out pintin (c);
37
am to CHeote a caluloto and
exlend tota scientinic coloulaton.
class calculaton f
Noid add (in a, int b);
imt c - atb;
Sytem.out.pruntln(te"Sum = "te):
void sb(int a, int b)}
Sytem. out psirtln("Dipekene
void mud (int a, ind b)s
int
5ystem out printn("Mutplicotion - ) ,
oid div (int a, int 6}
Syslemyo painttn (CGuotient " ac);
class scienipie- oporations extends calculato oprotion $
statie void mod (int o,int b)4
int
System. out prirtln(" Remaindex
public class Cal culoton f
publie atatic Notd main( Stringl] oog)i
int a = 22)
int b 7;
System out. prçntdn ('Enter 1 fon addibon ):
System,out.puntln (Enten 2 sor Aubacion);
Syatem out. println( Enter 3fon mutiplicotion);
Suatem ot pnn Enter 4 pon divialon);
System.out poutn Enten 5 oN emoinde\n'):
int chose - 4;
System.oud.println('choise t choise + ln):
i (choise=1)}
scienipic -op ations. add (a, b);
ose if (ohoise - 2)i
Seientigic- operations. Aub(a. b);
else iç (choise 3)}
scieniçic-opotiona mul (a,b);
else Tf(choise
sieniçie -rnations. div (a,b),
5){
Acienigic operatiors. mod (a, b);
Oubut:
Ente 1 rot addition
Entor 2 fox subbaction
Entor 3 pon mutiplicotion
Ent 4 for diviíon
Enter for emandeL
Cholse 4
Suotient -3.14351
5> Wue o constuucto9L in the
Cou cla given balow
that iritiaize the bsond doss pield th the sbung
Ford'.
statie stsing bund
bnand"Fond';
halje void diaplay
Syotem. out psúntn CThe band mame of the cax ja'*
+bnand );
public ass Car Brandimg i
publie stotie void moin(Sbing] g)i
camew Can);
e. duply
Output
The band mame o the caÚL is Ford
6Wute piogianm tQ caate a doss mamed hape.
In this lass we hawe thee ubclasses - ciele,
tsiangle nd 8quose. Each dases hawe two member
fumction named daaw) and ease (). Cyeate thi
using polymonphism concept.
Pheg
abAtoact class Shape
abatact 0id daw ();
albstact oid erase;
dass cinde extend& Shape
void doouo()i
sydem odprntln'Drauing
void ense)
Sytem out.pointn ('Enauinga chce):
class Triangle extends shape {
void daww ()
Sytem.out. printn ('Daawing a tbiomgle );
void easec)}
Syderod pmintln (Enaing
class Squae extends Shape i
void daaw()
System out. println (Druing a squana "),
Systemovin-paittasing
stem pruirtln(Eroaing qua ");
public dos Shape Test
publie statie void main (Stnimg L] ags) 1
Cicle Cince():
C- daal0;
C. erase C);
Trionge
t. dotaw();
t.dora );
Squane
5. dow
S. AseO;
3
Ouput
Drawing a cicle
Exasing
Drouing a tiangle
Exasing biangle
Dxauing
Exasing
wite print the name of sudents
Student name s paMed
by crenting then the
object f Student clas,
while eteaing the mame shoul
mame hould be Unknown', Othewise
be ezual to the soing value passec.
Proa'
class student
Stbing mame
Student(S ibing )i
mame = n;
Student (Stbing n)i
name "Unknown';
public clau Student Name 5
public static vaàd main (Sting l] aagi
Studont sl new Student"Ankan "):
Student sl = new Stude nt ():
Sydem. out pintin('Name 1st Atudent is "+ sl. Ta me);
System out prinln("Name op 2nd sdent is ’ s2. mame):
Output:
me fop Iat student
Name u Amkam
Name of 2nd stud ent
8> W.AP in jowo to implement the mltilavol inheutan e
in jawa and
and mplemend Jhe concept off udime ,
alymosphism.
Pob:
class Test i
void shouo ()3
System. out. prüntln (Fyom tost class):
class A extends Test 3
Void show()
System. out. println (Enom Aclaks "):
class B extends S
System. out prirtln (" Fnom 8 claw "):
class RunbimaPlymohum
publie tatic void maln (stringl] y l
Test t = mew Test () ;
t. Ahow);
A a a: mew AO;
A a-hoo ():
b.show(
Output:
Fnom text class
From A class
From B clas
progom to maintain he opgicial dotabose
ing single inheütance. Supe elos is Employe that
condains rollouing into Emp- codo, Emp. Name ,Emp-Add,
Emp. PhNo, DA - 30% HRA -207. . Cneote 3 saodasse
Maaget, Typut and ogicet, aach clas hauing
thei basie amd DA, HRA nemain
Praa
class Employee i
int Emp Code;
ft Nama,
Emt- Name,
ind stung Emt
Stung Emp- Add;
Sing Emp_PhNo,
Aouble Basic
Apuble DA,
doulola HRA;
Employee (int Emp. Coda, Stbçng Emp.Name stsing
Emp-Add, sbing emp-Philo) i
ths.Emp-Code = Emp- Code :
this. Enp- Name - Emp- Name;
Add Emp-Add;
his.Emp-Add
PhNo Emp-hNo;
this. Bo/e 0. o)
this. DA 0.3;
this HRA = 0.2;
Void Cale- Sal()3
doulble Saauy - Basie +(Basie DA)+ (BasicY HRA):
Syatem.out println(Employee Code : "+ Emp- Code):
Syetem. oud pruntlm (Employee Name : "+ Emp- Nam);
Sytem.out pintln (Employee Addess : 4 Emp. Add);
Sytem.out pountln("Emplogee Phone No:'4Emp.PhNo);
System. out puntln(E Basic Payment :"+ Bosic):
System. out.println DA:+DAl00 +"z")
System. out pountln( HRA : "+ HRAB*100 t"%):
Syatem. out. printn"Total Salary :"+salooy):
Syotem. out.prünttn("
closs Moanagex extends Emplayee i
Momagen (int Emp Coda, stoung Emp.Name, Strüng
Emp. Add, string Cmp. fANo);
upe (Ermp. lode, Emp-Name, Emp Add, Emp_ PhNo
this, Basic 50000,o,
class Typit extends Eneloye
yput (int Emp.Coda, sbing Emp- Name, Stung Enp. Add
Sung mp. PhNo )i
upo (Emp- Code, Emp- Nama,Emp Add, Emp.PhN);
this. Baslc = 25000. 0)
Salauyy50o0. o Total
20.0% HRA
faymuat30.0A :o6 DA
:S0D00.o Basic
5555566666 : NoPhone Employee
Agc Addess: Employee
Ram Name:
Employee
1001 Code: Employee
Output:
Sal); Calc. 0.
Sal(); Cale- t.
Sal(); m.Calc-
ishna (3001,GHI"Opicen
"); DEF Ogficer
"Shyam (a0l, ypit
new -Typust
t
);6 6 55555
66 "ABC",
"Ram' new Manage
main(Stungl1
ogi (1601, Manager m
void slali pubtic
Databasei Opice class publue
.035000
; Basic this.
Emp. Add, Emp. Nama, Emp. Codo, (Emp- Aupen
PhNo)i Enp. stbingEmp.Add,
p-Name, Stbing code, Emp. (int opricc
Employeei extends Omico class
Employce Codo : 20ol
Emplogee Namo : Shyom
Employe Aduss : DEF
Employe Phone Noi Il22222
Basic Pa ert : 25000,0
DA : 30.07
BHRA 20. 07%
Total solay : 34 500.o
Employee Code: 30o
Employe Name i küshna
Employee Address : GHL
Employee Phone No : 33333 44944
Base Payment 35600, O
DA: 30.0
HRA : 20.0/.
lay:
Total Salo 525 00.o
proqam toto ceate intenpace A. Tn this
intepace we hove methods - meth 1 and meth 2.
this noace in another class mamed My Clas.
Tmslement
void methi ():
void meth a();
class MyCLoss implements Aj
public void moth(0
Sytem out. println(");
vold
public void methe ()3
Sytem out pirtln(2):
þuilic static void main ( Sbing[] oq)}
MyClas Mydas);
m. methi():
m. meth 2);
1
2
1 Bina Seanch
clas BinaySemch i
pablie atatie void mam (stbing l] ang
inll a-2,5,7,9, 12,14,1 6,13,19, 20, 2b, 28j;
int taonact =16)
int lo = 0;
int hi - a.length -;
while (Io < hi)
int mid =(Lo+ti)/2:
== a[md ])
Sykem oat. prüntn (Toget is found t
"4 mid
index):
bcak;
else i (taget <a [mid]) {
Lo -mid +i;
Toget is found ot 6 mdex