Assignment-a
Preqam to demonstate the Of mem bersn s
vsbliy shasses
Same and dten packeae
Public class min
Public StohG class Base class
publis Int publicAeld,
Protected nt protecked ielda,
Lnt
d e t held 3,
Publis Basecass co4
oUt pnHo (parent class Conchor"}; }
public Vovd poblic Method (4
Sykm.out prntln ("public 4ethod);
Protected void pvoc Qct ed Netn od co
oUt- printin ("piotscted yetnod")}
Void deyaut yetodco
.out pnntH n( Degaur yehod):y
poblic stato class childctass Same.
-pockage
Orknds Baseclass
public chld clacs Same packagec
Syem out prntln(chid cac n tn a Seme
Censthruto1)
vol publia Nehod (yB
pobllo
Sytem.
out pnntin ( poblic eLho")y
ved protected ethod
Potccted
.out pintlo("protected Hothad"))
d1splayfel dsfAnd Hetheds e o l
C"publtc (ield"4 publle fred:
Suiem ot prntln
Vnokpinilh (upiotecte dfieldt Profected fietd):
degauteld);
publlc Hethod (} Prote ctmHethod (;
deFcuutt 4etn od ()}y
Poblic statie dass hild cag Derent pockeg& etends
Basecloss
public chld classoNberen poctagecl SuperC)}
oOtnntn("child class Lh a diher ent
Gonshocto,
podag
pblis statie void mar(sngt 3o )
chld clars same pacbage child Same pattag =new cheldclas S Same
child Same paekage displayfel do And qetd1(cagec
che ld Breren
Output kpockagedepay fielde And yethodr o;
Pajent class Gon strtor
hild dass in the same padcage
constocto
Public Held :! chid cass ina duhheent
Protec 2d feld: 2
Paccoge conectoy
Deywt Ael dig
Public ethod Pobic feld:
pvotected ffeld:
Dvorecs ed yehod
Oeyawrt public Hethod
Darenk class Constctox moted yethod
Drogu to creave aUrer dayned potb a
publiG void
butprnlo(his e le tord queiton n 7ven
asgment")}
Doblic class 4aln
qublic etahe yoid maun( itng3s 1
"yalaosey
"gslars dieplayece oge))
output
Thic o se cond quert on în gvenastgnent
to fnd the toots of a quadrotic equaton sA
nteface and pacleoes Declare on
fotefaca in patk age
Guad .Dedare onother package uad a and Pmplen ent
the
inteoace.
Ltrfoce Quodrohc equahgn
Vodtndloots Cdouble a,doude bydoube <);
ass Quodvate Solver ?mplem ents Quadrahe
Equahom
poblic oId hnd foots (deuble
aduble b,des ble c)s
double discuminant b
*b-* at c
b(de cenminanto) {
dovbla nOt 1= (-btyath sqvt (derimunant))J
(*a):
doctte lee tdiecmunan)|(1* a))
are feal and
duyent"
m.oot p u n t t o
oot» b/(2 a))
doule
ker)-ot pntnC"Roots ave Teal andthe sane)
oUt puntln(Qoots ae Compler nd dihherent);
purlic casr ain
ottiG St atic vold man
Sngg
Quadratic solver Solver ne ) SUadrate solverc))
dote a ,o9,cza'y
Sclver. C\ndeoots (abic}
6utput
Root are real and dyleren t
9Dene a Inter face polygon in
pockag po ct J. ceoe
range Cyom ën
package pocka, overrid e
to cclcula te
the tmangle and an e1ceptO
6t e an equilatevol tnangle.
Note: £xcephon hoe to
be degunad in
dovble caleuale Area c1 thiows Equil at e
Ercephai,
Cacs Cqulalera angle Encephon etnds' Erceptiam
poblte Cqulateral iangle (zcephm (oing ecge)
svpercmertog
tas s
hiange implement
Pivat e dovble sdei;
Prvate douole sle
pnvatC double
publis Tiange (dooble sde ,double sde a, dovble do
this -sIde t =Sdet)
thit sided :sdeQ
thuc des = s(de3, }
public doubte acvlate fheac tho
SxcepHon (Cannot calcutate aYea for
eqularere
mange ;
+de 2) la;"
pubuc
trorgle (s,313))
trarge calcasetres (3,
tnorg
Otout
Canret colulot reo, at fur an
equslatrd triang
Derdep oprogrom o dermonstrate cephn
CATCH
handlng
Stonnor sconner= neis Scannet (Syoem i0)
Syceroout print (CneeY khe numeraor)!
urnerato - SCanner. nerIntCI
the dem onMOOT )
St prnt ( Cnte
Lnt den Omunator= s canner .nentDnt }
LhCdenominatorz)
A1LhemehcSycephar (enomnatoy
Cannot be
thioto new
tnt reçuIknumerato denomunaoY
ntin ("Qerult :"trewE)i y
cOt ch (Athmehc Excepti on e) {
oolprntin (ithmethc E1cephm."te. get
Herogec)
Syvem o0tpnttn ("An onenpelod eroy o(Uye d
block u com p\et e."y
SCanne clesec)
otpt
Ane the umeraY|o
pet:S
{heuhm o the ty- catth bect u comhete
and corse . Lnitalite Values though pnametemxed Cantrudoy
then
Not cothin
ser deined eAcepth an Ag
Nam e Can kauns nombers or spe uat symbole
the two
t Name Not yaled EXephup. Deyine Cxcepton lacceu,
ctacs
poblic fge Notathinange fzcehen CSng hecge)f
soperCneccagel;
cLors NOme NoE Vald Encept¡n etends Crcepton
pobiG Nome Notvalid ¬xephon CtMng me ecag e{
SuperCmecooge);
clacs student
Prvate lnt ol) No
pwate
prae
Pobic studeCint yol nane,nt
gevot othin
largercephon ,wame Notvalid
tXceo
thnous neo
be between is 11,")
thiiroll d o l o
name)
thù.
Qmyae boolean çvalid Name Citmng ame)B
motche (ta-A-2]+
Sytem - oot-prnt (iQo|l otrollNo),
o. pnttn u Name: l'4name)
("CoUe:+
poblic clace Nan
oy
tudent tnew tuden (4, CJohn oe.
205 Compue uen ce
Jtudent!
botput
Name Johaooe
20
Coote:Comp uto feence
program to thow a uer
detined eephan fo
detals b an name ua nUmber a
emplogee
emplogee nome ercepton
nust be thown- 1b an
e1ceton be tnDn
pcdic orne
ErceptnCtAng mecagei
Super (me stoge,
Supen (neicage)
omej
nye nt
name ,nt
\nt oge) *hnor omeErceghar
Pgee epnn
Lho NUnenc name)
thyo ne Nametncephn (Empyee name cannot be
numher )
o y o w ne Age eycepti n(Cmployee ag cann0+ bea
coAeaey han so. i);
this name=0ame,
bobli clare Maun
oblis statie vo ( mon
Empleee cmployee i new
2melagee
catch (Mame peptin
A £(ephn e)
onpeee ame-ohn ose
|Emeleyee age :jo
to deron state nettd
eception ioyè
tmpt Java. ui\·sCanner ;
public class Nestd E1cepkisnDemo
Doblis statc void maunC Stngt
arg{
Scanner scanner ne scanner
Syctem .bupnt(Entet the frs t
lnt numi
lateger parselnt (scanner. netLine);
-out-pnat (Enter the Secand
Ink nmInt Iateger:);
Integt. parselnt, Scannernetline);
nt re sult= dvde
Numbers (nomi
;num,
Syemout pin("QesutE:"+ re);Y
Catch(Ath emeth c£ception e)
Sycteotprntn(Cannot dinde b zero.*);
tcatch (Numbr Formatf ceptisn )f
Sgaem -oot-nHn (Invald mput- pleare ente valtd
rhinaly
Scannes close c
Public static Lot dvÊde Nombersctnt
numd,nt num
sekum noml/aumas
`utput
Snter the first integer:l
ner Ahe Seccnd
Caannot iride by Zero
Creake an Account clacc otth dato membere accno, narne, bal.
Include meth ods deposLt Cthdyas C.lae an eeepo
when balance, in acco unt u lees th antO00
Publicclass Aecount Demo §
ivate int accno,
Nale sthng namej
Pywat e double bal;
dooble nthat galant.
PobliG Account ORmotnt aeno, Smng nama
his-a moaccno;
4hts- name name)
thic -ba -tnio Balance
public vod depo(it (dooble am Ount) 4
belt >dmoUnti
-outpnt! n("Depoto 0mount;
Sgct.oUt-pnnttn ( e s 8lance ;"4baj),
Ut prn(iopostE amount must be pogve.M,
pObli void thdacdouble amount hrous Acepti an 4
nevs Ecephn(I Inso
ycient balante Minmam
balance
ba amo unt;
but- prnln es Balonce, 4ba',
Poblic double
ger
(etuyn bal;
pubie sA atiG Vold man( stnngt aa
Acco ont Demo account neu Account omo ( 12245, "john Doeso
acccont depont (Soo,
accont Cotndao (Vo060;
Cauch
(E1cepti on e
oot prinln (e-ger
Heeage))
o0t-pntlo (Final Balonce'4accecnt
00tpot
Deposited: \soo.0
Nes Bal ance: 6 50oo
Nes Balance |So
final ealance.1500
rCreate o student clas coEn data membere Rol no, Nae
martr subsets lncude metheds to compute
aveag
Qaise an eceptton b the student hat more than a banlog
class Bockl og¬xception exerds Exephn
Public
ocktcgiscephtan (shing metage
Super Cmeccagej
poblic class Student f
pvvate hhngname,
Int 3 marlcs,
QYvate int tota ubiectsi
pubic Srudent Cent Yol| no,
name Ot tot oJ subec)
this oll noo|lno
thit name name
this tota ubJetS= btalroblets,
thitimarles new ntCtota Sobyect83
Pobic vold set Haylcs (intt markss
LACmark-length tota eubets)j
matk
throuo ne s tlegalAgument¬xeption (" numbeI
Provided does ot match total subjeclCi;
+his.nart -marks,
pblic doubl eomput efnageci
1nt sum o,
Soy (int mark moc) 4
Sum t= mask;
¢etom (douie) sumlto tal ubects
pubie vold check &act og C) throws bacelog xeeptn {
hockegsz o;
fo(int mo :mayk s)
L6Cmosk <yo){
bacttogt+) y
'5Cbactleq2)1
thiow new Bactlog fxceptn (u ttudent hae
more thon Q
poblic St a c vod manC
hodent Student neu
Shingr arge
tudent ( iDI,M Ali ce ",
S))
Int] malks
8S,1030, (o,4St,
Studen t- Set anks (mask)y
double aveage student
om pute fverage c))
verage mar k:laver
rodentcheckBacklog(,
Sgctemoot pnto(stod ent ha no tback
fcach
(Bactlog
Sycem ot"py lnlegt Heaiagee);
Student hal more than Qbactog