Vous êtes sur la page 1sur 71

Keto ushtrime jane zgjidhur gjate lendes Java I Viti II, 2010-2011 Shembuj

public class VleredheniaMeOperatoretAritmetike { public static void main(String[] args) { / !ava mundeson shkurtim te operatoreve aritmetike si dhe te operatorit te vleredhenies " psh# i $ i % &' shkruhet edhe si i%$ (' / int i $ &' int ) $ *+' i %$ &' //ekuivalente ) ,$ -' //ekuivalente S.stem"out"println(/i S.stem"out"println(/) 0 0 /* AFISHIMET i = 10 j=8 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class ShembullOpAritmetik { public static void main(String[] args) { S.stem"out"println(/shembull operatoresh aritmetike 1/)' int i $ &+ % -+' int ) $ i , *+' int k $ ) -' double l $ k / 2' S.stem"out"println(/i $ / % i)' S.stem"out"println(/) $ / % ))' S.stem"out"println(/k $ / % k)' S.stem"out"println(/l $ / % l)' 0 0

me i $ i % & me ) $ ) , $ / % i)' $ / % ))'

/* AFISHIMET shembull operatoresh aritmetike : i= 0 j = !0 k = 1"0 l = "0#0 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class Arithmetic3rog { public static void main(String[] args) { //disa numra int i $ *+' int ) $ -+' double 4 $ *+"&' double . $ -+"&' //mbledhim numra S.stem"out"println(/mbledh)e/)' S.stem"out"println(/ i % ) $ / % (i % )))' S.stem"out"println(/ 4 % . $ / % (4 % .))' //5brit)e numrash S.stem"out"println(/5brit)e/)' S.stem"out"println(/ i , ) $ / % (i , )))' S.stem"out"println(/ 4 , . $ / % (4 , .))' //shume5im numrash S.stem"out"println(/shume5im/)' S.stem"out"println(/ i ) $ / % (i )))' S.stem"out"println(/ 4 . $ / % (4 .))' //p)estim numrash S.stem"out"println(/p)esetim/)' S.stem"out"println(/ i / ) $ / % (i / )))' S.stem"out"println(/ 4 / . $ / % (4 / .))' //llogarit)e te mbet)eve te p)estimeve S.stem"out"println(/Mbet)a/)' S.stem"out"println(/ i 6 ) $ / % (i 6 )))' S.stem"out"println(/ 4 6 . $ / % (4 6 .))' 0 0 /* AFISHIMET mble$hje i % j = &0 ' % ( = &1#0 )britje i * j = *10 ' * ( = *10#0 shume)im i * j = "00 "

' * ( = "1+#"+ pjesetim i/j=0 ' / ( = 0#+1"1,+1"1,+1"1,+ Mbetja i - j = 10 ' - ( = 10#+ */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, class 7ool*{ public static void main(String args[]){ // variabla log)ike boolean A $ true' boolean 7 $ 8alse' S.stem"out"println(/A97 $ /%(A97))' S.stem"out"println(/A:7 $ /%(A:7))' S.stem"out"println(/;A $ /%(;A))' S.stem"out"println(/A<7 $ /%(A<7))' S.stem"out"println(/(A97):A $ /%((A97):A))' 0 0 /* AFISHIMET A./ = true A0/ = 1alse 2A = 1alse A3/ = true 4A./50A = true */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class ShembullOperator=ri)e>he?volg { public static void main(String[] args) { int i $ *+' int ) $ *+' i%%' )%%' S.stem"out"println(/i $ / % i)' S.stem"out"println(/) $ / % ))' int k $ i%%' int l $ %%)' S.stem"out"println(/k $ / % k)' S.stem"out"println(/l $ / % l)' 0 0 /* AFISHIMET $alja $o jete i = 11 j = 11 &

k = 11 l = 1" */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class ShembullModulo { public static void main(String[] args) { S.stem"out"println(/operatori i modulit 1 /)' int i $ &+' double d $ @-' S.stem"out"println(/i mod *+ $ / % i6*+)' S.stem"out"println(/d mod *+ $ / % d6*+)' 0 0 /* AFISHIMET operatori i mo$ulit : i mo$ 10 = 0 $ mo$ 10 = "#0 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class O=>emo { public static void main(String[] args) { int numriA $ *2' int numri7 $ (' int re5ultati $ numriA 9 numri7' S.stem"out"println(numriA % / 9 / % numri7 % / $ / % re5ultati)' S.stem"out"println(Anteger"to7inar.String(numriA) % / 9 / % Anteger"to7inar.String(numri7) % / $ / % Anteger"to7inar.String(re5ultati))' 0 0 /* AFISHIMET 1! . 6 = "0 10000 . 100 = 10100 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class OperatoriModulo { public static void main(String[] args) { int a $ *+' double b $ (B' S.stem"out"println(/=e5ultati i / % a % / 6 & $ / % (a 6 &))' S.stem"out"println(/=e5ultati i / % b % / 6 B"& $ / % (b 6 B"&))' 0 0

/* AFISHIMET 7e)ultati i 10 - + = 0 7e)ultati i 6,#0 - ,#+ = 1#+ */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class CO=>emo { public static void main(String[] args) { int numriA $ *2' int numri7 $ @-' int re5ultati $ numriA < numri7' S.stem"out"println(numriA % / < / % numri7 % / $ / % re5ultati)' S.stem"out"println(Anteger"to7inar.String(numriA) % / < / % Anteger"to7inar.String(numri7) % / $ / % Anteger"to7inar.String(re5ultati))' 0 0 /* AFISHIMET 1! 3 &" = 68 10000 3 100000 = 110000 */ *************************************************************************************************************************** public class !avaDontinueE4ample { public static void main(String[] args) { S.stem"out"println(/numrat Fe a8ishohen )ane 1/)' 8or(int i$+' i G &' i%%) { i8(i $$ @) continue' else S.stem"out"println(i)' 0 0 0 /* AFISHIMET 8umrat 9e a1ishohe8 ja8e : 1 " 6 + */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class !ava7reakE4ample { public static void main(String[] args) { +

S.stem"out"println(/numrat Fe a8ishohen )ane 1 /)' 8or(int i$+' i G &' i %%) { i8(i $$ @) break' else S.stem"out"println(i)' 0 0 0 /* AFISHIMET 8umrat 9e a1ishohe8 ja8e : 1 " */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class Hrahaso>.Iumra { public static void main(String[] args) { int nr* $ @-(' int nr- $ -@(' i8(nr* J nr-){ S.stem"out"println(nr* % / eshte me i madh se / % nr-)' 0 else i8(nr* G nr-){ S.stem"out"println(nr* % / eshte me i vogel se / % nr-)' 0 else{ S.stem"out"println(nr* % / eshte i barabarte me / % nr-)' 0 0 0 /* AFISHIMET &"6 eshte me i ma$h se "&6 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class VitA7rishte { public static void main(String[] args) { int viti $ -++(' i8(viti6 (++ $$ +) 99 ((viti 6 ( $$ +) :: (viti 6 *++ ;$ +)) S.stem"out"println(/viti / % viti % / eshte vit i brishte/)' else S.stem"out"println(/viti / % viti % /sKeshte vit i brishte/)' 0 0 !

/* AFISHIMET :iti "006 eshte :it i brishte */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class ShembullA8 { public static void main(String[] args) { int i $ *+' i8(i J *++) S.stem"out"println(/i eshte me e madhe se *++/)' else i8(i J &+) S.stem"out"println(/i eshte me e madhe se &+/)' else S.stem"out"println(/i eshte me e vogel se &+/)' 0 0 /* AFISHIMET i eshte me e :o;el se +0 */ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public class ShembullDase { / break perdoret per te ndalur ek5ekutimin e rasteve t)era case ne kete shembull ek5ekutohen te g)ithe rastet case / public static void main(String[] args) { int i$+' sLitch(i) { case +1 S.stem"out"println(/i eshte +/)' case *1 S.stem"out"println(/i eshte */)' case -1 S.stem"out"println(/i eshte -/)' de8ault1 S.stem"out"println(/shembull me case;/)' 0 0 0 /* AFISHIMET i eshte 0 i eshte 1 i eshte " shembull me <ase2 */

public class ShembullDaseAIder8utur { public static void main(String[] args) { int i $ +' int ) $ *' sLitch(i) { case +1 sLitch()) { case +1 S.stem"out"println(/i eshte +# ) eshte +/)' break' case *1 S.stem"out"println(/i eshte +# ) eshte */)' break' de8ault1 S.stem"out"println(/rasti de8ault;;/)' 0 break' de8ault1 S.stem"out"println(/Iuk g)endet n)e rast i tille;;/)' 0 0 0 /* AFISHIMET i eshte 0= j eshte 1*/

Seminaret ne Java I
Ushtrim 1: Program ne Java me operatoret logjike public class Mog)ike { static int 4#.#5' static boolean b*#b-#b@#b(#vMog)ik' public static void main(String[] args) { 4$@*' .$*&' 5$*' b*$4J5' S.stem"out"println(/b*$/%b*)' b-$.G5' S.stem"out"println(/b-$/%b-)' b@$.G$5' S.stem"out"println(/b@$/%b@)' b($.;$5' S.stem"out"println(/b($/%b()' vMog)ik$b*::b-'

S.stem"out"println(/variabli vMog)ik$b@99b(' S.stem"out"println(/variabli vMog)ik$;b*' S.stem"out"println(/variabli vMog)ik$;b-' S.stem"out"println(/variabli

log)ik$/%vMog)ik)' log)ik$/%vMog)ik)' log)ik$/%vMog)ik)' log)ik$/%vMog)ik)'

0 0 /* AFISHIMET b1=true b"=1alse b&=1alse b6=true :ariabli lo;jik=1alse :ariabli lo;jik=true :ariabli lo;jik=1alse :ariabli lo;jik=true */ Ushtrim 2 : Program ne Java me operatoret aritmetike, ne postfix dhe prefix public class 3re8i4 { static int a#b#4#.' public static void main(String[] args) { a$N' b$(-' 4$&@' .$O' S.stem"out"println(/para 5voglimit,, 4$/%4%/ .$/%.)' 4$,,.' //.$.,*' //4$.' S.stem"out"println(/pas 5voglimit,, 4$/%4%/ .$/%.)' S.stem"out"println(/para rrit)es %% a$/%a%/ b$/%b)' a$%%b' //b$b%*' //a$b' // ne 8or do te sho8im i%% ekuivalente me i$i%*' S.stem"out"println(/pas rrit)es%% a$/%a%/ b$/%b)' 0 0 /* AFISHIMET para ):o;limit** '=+& (= pas ):o;limit** '=! (=! para rritjes %% a=8 b=6" pas rritjes%% a=6& b=6& */ ,

Ushtrim 3 : Program ne Java me operatoret aritmetike, ne postfix dhe prefix public class 3ost8i4 { static int a#b#4#.' public static void main(String[] args) { a$N' b$(-' 4$&@' .$O' S.stem"out"println(/para 5voglimit,, 4$/%4%/ 4$.,,' //4$.' //.$.,*' S.stem"out"println(/pas 5voglimit,, 4$/%4%/ S.stem"out"println(/para rrit)es %% a$/%a%/ a$b%%'

.$/%.)'

.$/%.)' b$/%b)'

//a$b' //b$b%*' // ne 8or do te sho8im i%% ekuivalente me i$i%*' S.stem"out"println(/pas rrit)es%% a$/%a%/ b$/%b)' 0 0 /* AFISHIMET para ):o;limit** '=+& (= pas ):o;limit** '= (=! para rritjes %% a=8 b=6" pas rritjes%% a=6" b=6& */ Ushtrim 4: Te ndertohet nje program ne Java qe kerkon n mrat n n mrat e pare prim!n mrat e thjeshte qe plotpjestohen ve" me veten dhe me n mrin 1#$ %lera e n mrit n jepet nga perdor esi import )ava"util"Scanner' public class HerkoPprim{ static boolean prim(int a){ boolean re5$true' 8or(int i$-'iGa'i%%) i8(a6i$$+){ re5$8alse' break' 0 return re5' 0

10

public static void main (String args[]){ Scanner input$neL Scanner(S.stem"in)' S.stem"out"println(/)epni numrin n/)' int n$input"ne4tAnt()' int total$+' int i$*' Lhile(totalGn){ i8(prim(i)) { S.stem"out"println(i)' total%%' 0 i%%' 0 0 0 /* AFISHIMET jep8i 8umri8 8 1" 1 " & + 11 1& 1 1, "& ", &1 */ Ushtrim & : Te ndertohet nje program ne Java qe afishon fig ren me 'je si me poshte : /* AFISHIMET /* ********** ********** ********** ********** ********** **********

*/

11

public class Q)e{ public static void main (String args[]){ 8or(int i$*'iG$2'i%%){ 8or(int )$*')G$*+')%%) S.stem"out"print(/ /)' S.stem"out"println(//)' 0 0 0 Ushtrim ( :Te ndertohet nje program ne Java qe afishon fig ren e meposhtme : /* %****% > / / > > / / > > / / > %****% */ public class Rigura { public static void main (String args[]) S.stem"out"println(/%,,,,%/)' 8or(int i$*'iG$@'i%%){ S.stem"out"println(/SS //)' S.stem"out"println(// SS/)' 0 S.stem"out"println(/%,,,,%/)' 0 0 Ushtrim ) : Te ndertohet nje program ne Java qe llogarit n mrin e k ndert te nje n mri te plote$ Psh n mrin 1234 e kthen ne 4321$ public class numriHunderti { public static void main(String[] args) { int nr$*-@(' int kunder$+' int temp$+' Lhile(nrJ+){ temp$nr6*+' kunder$kunder *+%temp' nr$nr/*+' 0 S.stem"out"println(/e kunderta / % kunder)' 0 0

1"

/* AFISHIMET /* e ku8$erta 6&"1 */ Ushtrim *: Te ndertohet nje program ne Java qe merr nga tastjera d' n mra te plote dhe afishon nese keto n mra jane sh mfish te njeri+tjetrit$ import )ava"util"Scanner' public class Shum8ish { static boolean kontroll(int a#int b){ boolean c' c$8alse' i8 (a6b$$+) c$true' return c' 0 public static void main(String[] args) { Scanner input$ neL Scanner(S.stem"in)' int nr*#nr-' S.stem"out"println(/)ep numrin e */)' nr*$input"ne4tAnt()' S.stem"out"println(/)ep numrin e -/)' nr-$input"ne4tAnt()' i8 (kontroll(nr*#nr-)) S.stem"out"println(/nr* $ /%nr*%/ eshte shum8ish i nr- $ /%nr-)' else S.stem"out"println(/nr* $ /%nr*%/ nuk eshte shum8ish i nr- $ /%nr-)' i8 (kontroll(nr-#nr*)) S.stem"out"println(/nr-$ /%nr-%/ eshte shum8ish i nr* $ /%nr*)' else S.stem"out"println(/nr- $ /%nr-%/ nuk eshte shum8ish i nr* $ /%nr*)' 0 0 /* SHEM/?@@ AFISHIMI jep 8umri8 e 1 jep 8umri8 e " "8 8r1 = 8uk eshte shum1ish i 8r" = "8 8r"= "8 eshte shum1ish i 8r1 = */ 1&

Ushtrim , : Te ndertohet nje program qe llogarit siperfaqen dhe perimetrin e rrethit, d ke marre te dhenat nga perdor esi$ import )ava"util"Scanner' public class =rethi { public static void main(String[] args) { 8loat rre5e' 8loat 3i$@"*(8' 8loat Sip#3er' Scanner input $ neL Scanner (S.stem"in)' S.stem"out"println( /!epni rre5en e rrethit1 /)' rre5e$input"ne4tRloat()' Sip$3i rre5e rre5e' 3er$ - 3i rre5e' S.stem"out"println( /Siper8aF)a e rrethit eshte1 /%Sip)' S.stem"out"println( /3erimetri i rrethit eshte1 /%3er)' 0 0 /* AFISHIMET " Siper1a9ja e rrethit eshte: 1"#+! Aerimetri i rrethit eshte: 1"#+! */ Ushtrim 1- : Te ndertohet nje aplika"ion qe lexon 2 nr te plote, dhe vendos nese nr i d'te eshte sh mefish i nr te pare dhe kontrollon nese nr i trete eshte tek apo "ift import )ava"util"Scanner' public class Test { public static void main(String[] args) { int a#b#c' int re5ultati' boolean tekUi8t# plotp)es' Scanner input $ neL Scanner(S.stem"in)' S.stem"out"println (/ !ep n)e numer te plote/)' a$input"ne4tAnt()' S.stem"out"println (/!ep numrin e d.te te plote/)' b$input"ne4tAnt()' re5ultati$(b6a)' plotp)es$re5ultati$$+' S.stem"out"println (/Iumri i d.te eshte shume8ish i nr te pare,J / %plotp)es)' S.stem"out"println (/Mbet)a eshte / %re5ultati)' S.stem"out"println (/ !ep numerin e trete /)' c$input"ne4tAnt()' re5ultati$(c6-)' tekUi8t$re5ultati$$+' 16

S.stem"out"println (/Iumri i dhene# eshte Ui8t,J / %tekUi8t)' tekUi8t$re5ultati$$*' S.stem"out"println (/Iumri i dhene# eshte tek,J / %tekUi8t)' 0 0 /* SHEM/?@@ AFISHIMI Bep 8je 8umer te plote 6+ Bep 8umri8 e $(te te plote &" Cumri i $(te eshte shume1ish i 8r te pare*D 1alse Mbetja eshte &" Bep 8umeri8 e trete 1" Cumri i $he8e= eshte Ei1t*D true Cumri i $he8e= eshte tek*D 1alse */ Ushtrim 11 : Te ndertohet nje aplika"ion qe lexon & nr te plote, dhe afishon se "ili asht nr me i madhe dhe me i vogel ne gr p, d ke perdore operatoret logjike import )ava"util"Scanner' public class Hrahasim { public static void main(String[] args) { int a#b#c#d#e' boolean re5ultati' Scanner input $ neL Scanner(S.stem"in)' S.stem"out"println (/ !ep n)e numer te plote/)' a$input"ne4tAnt()' S.stem"out"println (/!ep numrin e d.te te plote/)' b$input"ne4tAnt()' S.stem"out"println (/!ep numrin e trete te plote/)' c$input"ne4tAnt()' S.stem"out"println (/!ep numrin e katert te plote/)' d$input"ne4tAnt()' S.stem"out"println (/!ep numrin e peste te plote/)' e$input"ne4tAnt()' re5ultati$(aGb)::(aGc)::(aGd)::(aGe)' S.stem"out"println (/Minimumi eshte /%a%/ /% re5ultati)' re5ultati$(bGa)::(bGc)::(bGd)::(bGe)' S.stem"out"println (/Minimumi eshte /%b%/ / % re5ultati)' re5ultati$(cGa)::(cGb)::(cGd)::(cGe)' S.stem"out"println (/Minimumi eshte / %c%/ /% re5ultati)' re5ultati$(dGa)::(dGb)::(dGc)::(dGe)' 1+

S.stem"out"println (/Minimumi eshte /%d%/ /%re5ultati)' re5ultati$(eGa)::(eGb)::(eGc)::(eGd)' S.stem"out"println (/Minimumi eshte /%e%/ /%re5ultati)' re5ultati$(aJb)::(aJc)::(aJd)::(aJe)' S.stem"out"println (/Maksimumi eshte /%a%/ /%re5ultati)' re5ultati$(bJa)::(bJc)::(bJd)::(bJe)' S.stem"out"println (/Maksimumi eshte /%b%/ /%re5ultati)' re5ultati$(cJa)::(cJb)::(cJd)::(cJe)' S.stem"out"println (/Maksimumi eshte /%c%/ /%re5ultati)' re5ultati$(dJa)::(dJb)::(dJc)::(dJe)' S.stem"out"println (/Maksimumi eshte /%d%/ /%re5ultati)' re5ultati$(eJa)::(eJb)::(eJc)::(eJd)' S.stem"out"println (/Maksimumi eshte /%e%/ /%re5ultati)' 0 0 /* SHEM/?@@ AFISHIMI Bep 8je 8umer te plote 1" Bep 8umri8 e $(te te plote ! Bep 8umri8 e trete te plote 6 Bep 8umri8 e katert te plote !+ Bep 8umri8 e peste te plote " Mi8imumi eshte 1" 1alse Mi8imumi eshte ! 1alse Mi8imumi eshte 6 1alse Mi8imumi eshte !+ 1alse Mi8imumi eshte " true Maksimumi eshte 1" 1alse Maksimumi eshte ! 1alse Maksimumi eshte 6 true Maksimumi eshte !+ 1alse Maksimumi eshte " 1alse */ Ushtrim 12 : Te jepen d' n mra te plote, dhe aplika"ioni te krahasoje keto d' n mra$ import )ava"util"Scanner' public class Hrahaso { public static void main(String[] args) { int a# b' boolean re5ultati' Scanner input $ neL Scanner(S.stem"in)' 1!

S.stem"out"println (/ !ep n)e numer te plote/)' a$input"ne4tAnt()' S.stem"out"println (/!ep numrin e d.te te plote/)' b$input"ne4tAnt()' re5ultati$a$$b' S.stem"out"println (/a e barabarte me bVV/%re5ultati)' re5ultati$a;$b' S.stem"out"println (/a e ndr.shme me bVV/%re5ultati)' re5ultati$aGb' S.stem"out"println (/a me e vogel se bVV/%re5ultati)' re5ultati$aJb' S.stem"out"println (/a me e vogel se bVV/%re5ultati)' re5ultati$aG$b' S.stem"out"println (/a eshte me e vogel ose e barabarte me bVV/%re5ultati)' re5ultati$aJ$b' S.stem"out"println (/a eshte me e madhe ose e barabarte me bVV/%re5ultati)' 0 0 /*SHEM/?@@ AFISHIMI Bep 8je 8umer te plote &+ Bep 8umri8 e $(te te plote "& a e barabarte me bFF1alse a e 8$r(shme me bFFtrue a me e :o;el se bFF1alse a me e :o;el se bFFtrue a eshte me e :o;el ose e barabarte me bFF1alse a eshte me e ma$he ose e barabarte me bFFtrue */ Ushtrim 13 : program qe lexon nga perdor esi nje vit, dhe tregon nese eshte viti i .rishte apo jo$ public class VitA7rishte { public static void main(String[] args) { int viti $ -++(' i8((viti6 (++ $$ +) 99 ((viti 6 ( $$ +) :: (viti 6 *++ ;$ +))) S.stem"out"println(/viti / % viti % / eshte vit i brishte/)' else S.stem"out"println(/viti / % viti % /sKeshte vit i brishte/)' 0 0 /* AFISHIMET :iti "006 eshte :it i brishte */ 1

Ushtrim 14 : Te ndertohet nje program k perdor esi jep ngj'ren dhe ne .a/e te saj jepet nje pohim per perdor esin$ import )ava"util"Scanner' public class Ig).ra { public static void main(String[] args) { int ng).ra' Scanner input $ neL Scanner( S.stem"in )' S.stem"out"println(/!epni ng).ren tua) te pre8eruar# * per te kuFen# - per te 5e5en# @ per te bardhen 1/)' ng).ra$ input"ne4tAnt()' sLitch (ng).ra) { case *1 S.stem"out"println( /po shkruan n)e va)5e / )' break' case -1 S.stem"out"println( /mendo) se )u )eni metalar / )' break' case @1 S.stem"out"println( /)u duhet te )eni n)eri i paFte / )' break' de8ault1 S.stem"out"print( /e dhene gabim / )' 0 0 0 /* SHEM/?@@ AFISHIMI Bep8i 8;j(re8 tuaj te pre1eruar= 1 per te ku9e8= " per te )e)e8= & per te bar$he 8: 1 po shkrua8 8je :aj)e */ Ushtrim 1& : Te ndertohet nje program qe afishon ditet e javes ne .a/e te te dhanave nga perdor esi$ import )ava"util"Scanner' public class !ave { public static void main(String[] args) { int ditet' Scanner input $ neL Scanner( S.stem"in )' S.stem"out"println(/!epni numrin Fe deshironi 1/)' ditet$ input"ne4tAnt()' sLitch (ditet) { case *1 S.stem"out"print( /E Wene / )' break'

18

case -1 S.stem"out"print( case @1 S.stem"out"print( case (1 S.stem"out"print( case &1 S.stem"out"print( case 21 S.stem"out"print( case O1 S.stem"out"print( de8ault1 S.stem"out"print( 0 0 0 /* SHEM/?@@ AFISHIMI Bep8i 8umri8 9e $eshiro8i : & E Merkure */

/E Marte / )' break' /E Merkure / )' break' /E En)te / )' break' /E 3remte / )' break' /E Shtune / )' break' /E >iele / )' break' /Ir eshte dhene gabim/ )'

Ushtrim 1( : 0hkr ani nje program qe llogarit nese tre n mra te dhene m nd te formojne nje trekendesh$ import )ava"util"Scanner' public class Trekendesh { public static void main(String[] args) { int a#b#c' Scanner input $ neL Scanner(S.stem"in)' S.stem"out"println (/ !ep brin)en e pare/)' a$input"ne4tAnt()' S.stem"out"println (/!ep brin)en e d.te /)' b$input"ne4tAnt()' S.stem"out"println (/!ep brin)en e trete /)' c$input"ne4tAnt()' i8 ((a%bJc)::(a%cJb)::(b%cJa)) S.stem"out"println (/Iumrat e dhene# 8ormo)ne trekendesh /)' else S.stem"out"println (/Iuk 8ormohet trekendesh /)' 0 0 /* AFISHIMET Bep bri8je8 e pare "

1,

Bep bri8je8 e $(te " Bep bri8je8 e trete + Cuk 1ormohet treke8$esh */ Ushtrim 1) : 0hkr aj nj1 program q1 rekomandon n mrin e kalorive nj1 person d het t1 haje ne dit1# Galori eshte 8jHsia e e8er;jisH 9e ;je8$et 8H tH ;jitha ush9imet# A er rekoma8$imi8 tuaj 8H ba)ohe8i 8e peshH8 e perso8it $he 8Hse perso8i ka 8jH jete akti:e ose pasi:e # CHse perso8i HshtH pasi:= 1aktori i akti:itetit HshtH 1&# CHse perso8i HshtH akti:= 1aktori i akti:itetit HshtH 1+# Shume)o8i 1aktori8 e :eprimtarisH me peshe8 e perso8it pHr tH marrH 8umri8 e rekoma8$uar te kalori:e# Fillo8i pro;rami8 tuaj 8;a: *per$oruesi jep peshe8 me 8je shi1er me presje per$oruesi :e8$os akti:iteti8 e tij= IaJ per akti: $he IpJ per pasi: *shume)ohe8 :lerat= te per$oret i8struksio8i <ase *a1ishohet re)ultati import )ava"util"Scanner' public class Halori { public static void main(String[] args) { 8loat kalorite# pesha' int aktiviteti' Scanner input $ neL Scanner(S.stem"in)' S.stem"out"println (/ !epni peshen tua)/)' pesha$input"ne4tRloat()' S.stem"out"println (/Shkruani * nFs )eni aktiv#- nFs )eni pasiv/)' aktiviteti$input"ne4tAnt()' sLitch(aktiviteti){ case *1 kalorite $ *@ pesha' S.stem"out"println (/!u konsumoni /%kalorite%/ kalori ne dite/)' break' case -1 kalorite $ *& pesha' S.stem"out"println (/!u konsumoni /%kalorite%/ kalori ne dite/)' 0 0 0 /* SHEM/?@@ AFISHIMI Bep8i peshe8 tuaj !6 Shkrua8i 1 89s je8i akti:=" 89s je8i pasi: 1 Bu ko8sumo8i 8&"#0 kalori 8e $ite */ "0

Ushtrim 1* : 2dertoni nje program qe afishon te dhena te perp n ara nga metodat e klases 3ath import )ava"lang"Math' public class M.Math { public static void main(String[] args) { double 8' long i' 8$Math"ceil(B"*O)' //rrumbullakim nga lart S.stem"out"println(/8$/%8)' 8$Math"poL(-# ()' //8uFia S.stem"out"println(8)' 8$Math"sFrt(2()' //rren)a katrore S.stem"out"println(8)' 8$Math"8loor(*-"O@) % Math"ma4(N# &)' //merr rrumbullakimin nga poshte % maksimumin S.stem"out"println(8)' 8$Math"abs(Math"min(,*#,@))' //vlera absolute e numrit minimal S.stem"out"println(8)' 8$Math"ceil(Math"random())' // c8aredo S.stem"out"println(8)' 8$Math"poL(-#-) %Math"poL(,-# @) % Math"poL(-# ,-)' //mbledh)e 8uFish S.stem"out"println(8)' i$Math"round(("-&)% Math"round(&"@N) % Math"round(2"(B)' //mbledh)e rrumbullakimesh S.stem"out"println(i)' 0 0 /* AFISHIME 1=10#0 1!#0 8#0 "0#0 &#0 1#0 *&# + 1+ */ Ushtrim 1, : 0hkr ani nje metode qe llogarit faktorialin e nje n mri$ import )ava"util"Scanner' public class Raktorial { static int 8ak(int a){ int b$*' 8or(int i$a'iJ$*'i,,) b$b i' return b' 0 "1

public static void main(String[] args) { Scanner input $ neL Scanner( S.stem"in )' int n' S.stem"out"println(/)ep numrin /)' n$input"ne4tAnt()' S.stem"out"print(/8aktoriali i /)' S.stem"out"print(n)' S.stem"out"print(/; $ /)' S.stem"out"print(8ak(n))' 0 0 /* AFISHIMET jep 8umri8 6 1aktoriali i 62 = "6 */ Ushtrim 2- : 2dertoni nje makine llogaritese d ke perdore instr ksionin "ase per veprimin dhe metoda qe llogarit re/ ltatin e se"ilit veprim$ import )ava"util"Scanner' public class MakinaMlogaritese { static int veprimi# nr*# nr-# Shuma# ?br# 3)# Shum5' static Scanner input $ neL Scanner( S.stem"in )' static void Makina(){ S.stem"out"println (/H)o eshte n)e makine llogaritese"/)' S.stem"out"println (/?g)idhnie cilin veprim doni te kr.eni1/)' S.stem"out"println (/*" Mbledh)e/)' S.stem"out"println (/-" ?brit)e/)' S.stem"out"println (/@" Shume5im/)' S.stem"out"println (/(" 3)estim/)' veprimi $ input"ne4tAnt()' sLitch (veprimi){ case *1 { S.stem"out"println (/!epni d. numrat Fe doni te mblidhni1 /)' S.stem"out"println (/!epni numrin e pare1 /)' nr* $ input"ne4tAnt()' S.stem"out"println (/!epni numrin e d.te1 /)' nr- $ input"ne4tAnt()' Mbledh)e()' 0 break' case -1 { S.stem"out"println (/!epni d. numrat Fe doni te 5brisni1 /)' S.stem"out"println (/!epni numrin e pare1 /)' nr* $ input"ne4tAnt()' S.stem"out"println (/!epni numrin e d.te1 /)'

""

nr- $ input"ne4tAnt()' ?brit)e()' 0 break' case @1 { S.stem"out"println (/!epni S.stem"out"println (/!epni nr* $ input"ne4tAnt()' S.stem"out"println (/!epni nr- $ input"ne4tAnt()' Shume5im()' 0 break' case (1 { S.stem"out"println (/!epni S.stem"out"println (/!epni nr* $ input"ne4tAnt()' S.stem"out"println (/!epni nr- $ input"ne4tAnt()' 3)estim()' 0 break' de8ault1 { S.stem"out"println (/H. opsion nuk ek5iston;/)' 0 0 0 static void Mbledh)e(){ Shuma$nr*%nr-' S.stem"out"println (/Shuma e /%nr*%/ dhe /%nr-%/ eshte 1/%Shuma)' S.stem"out"println (/Sht.pni + per tu kth.er"/)' veprimi $ input"ne4tAnt()' i8 (veprimi$$+) Makina()' 0 static void ?brit)e(){ ?br$nr*,nr-' S.stem"out"println (/Idr.shimi i /%nr*%/ dhe /%nr-%/ eshte 1/%?br)' S.stem"out"println (/Sht.pni + per tu kth.er"/)' veprimi $ input"ne4tAnt()' i8 (veprimi$$+) Makina()' 0

d. numrat Fe do te shume5oni1 /)' numrin e pare1 /)' numrin e d.te1 /)'

d. numrat Fe doni te p)estoni1 /)' numrin e pare1 /)' numrin e d.te1 /)'

"&

static void Shume5im(){ Shum5$nr* nr-' S.stem"out"println (/Shum5imi i /%nr*%/ dhe /%nr-%/ eshte 1/%Shum5)' S.stem"out"println (/Sht.pni + per tu kth.er"/)' veprimi $ input"ne4tAnt()' i8 (veprimi$$+) Makina()' 0 static void 3)estim(){ 3)$nr*/nr-' S.stem"out"println (/3)estimi i /%nr*%/ dhe /%nr-%/ eshte 1/%3))' S.stem"out"println (/Sht.pni + per tu kth.er"/)' veprimi $ input"ne4tAnt()' i8 (veprimi$$+) Makina()' 0 public static void main(String[] args) { Makina()' 0 0 /* SHEM/?@@ AFISHIMI Gjo eshte 8je maki8e llo;aritese# K;ji$h8ie <ili8 :eprim $o8i te kr(e8i: 1# Mble$hje "# Kbritje &# Shume)im 6# Ajestim " Bep8i $( 8umrat 9e $o8i te )bris8i: Bep8i 8umri8 e pare: 6 Bep8i 8umri8 e $(te: + C$r(shimi i 6 $he + eshte :6" Sht(p8i 0 per tu kth(er# 0 Gjo eshte 8je maki8e llo;aritese# K;ji$h8ie <ili8 :eprim $o8i te kr(e8i: 1# Mble$hje "# Kbritje &# Shume)im 6# Ajestim 1 Bep8i $( 8umrat 9e $o8i te mbli$h8i:

"6

Bep8i 8umri8 e pare: "+ Bep8i 8umri8 e $(te: 1" Shuma e "+ $he 1" eshte :& Sht(p8i 0 per tu kth(er# */ Ushtrim 21 : Te ndertohet nje program ne Java qe .en afishime sipas skemave te dhena$ 2 mri n jepet nga perdor esi$ public class Trekendesh { public static void main(String[] args) { int g)er' Scanner input$ neL Scanner(S.stem"in)' S.stem"out"print(/)ep g)eresine/)' g)er$input"ne4tAnt()' S.stem"out"print(/,,,,,,,8igura *,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$*'iG$g)er'i%%) { 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 S.stem"out"print(/,,,,,,,,8igura -,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$g)er'iJ$*'i,,) { 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 S.stem"out"print(/,,,,,8igura @,,,,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$*'iG$g)er'i%%) { 8or(int c$*'cG$g)er,i'c%%) S.stem"out"print(/ /)' 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 S.stem"out"print(/,,,,,,,8igura (,,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$g)er'iJ$*'i,,) {

"+

8or(int c$*'cG$g)er,i'c%%) S.stem"out"print(/ /)' 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 S.stem"out"print(/,,,,,8igura &,,,,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$*'iG$g)er'i%%) { 8or(int c$*'cG$g)er,i'c%%) S.stem"out"print(/ /)' 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 S.stem"out"print(/,,,,,,,8igura 2,,,,,,,,,,,,,,,/)' S.stem"out"println(/ /)' 8or(int i$g)er'iJ$*'i,,) { 8or(int c$*'cG$g)er,i'c%%) S.stem"out"print(/ /)' 8or(int )$*')G$i')%%) S.stem"out"print(/ /)' S.stem"out"println(/ /)' 0 0 0 /* AFISHIMET jep ;jeresi8e6 *******1i;ura 1************** * ** *** **** ********1i;ura "************** **** *** ** * *****1i;ura &***************** * ** *** ****

"!

*******1i;ura 6*************** **** *** ** * *****1i;ura +***************** * ** *** **** *******1i;ura !*************** **** *** ** * */ Ushtrim 22 : Te ndertohet nje program qe jep ne men're te rastit d' n mra te plote me te vegjel se 2-, dhe kerkon nga perdor esi te llogarise prodhimin e ket're d' n mrave$ P'etjet /hvillohen ne forme q i/$ import )ava"util"=andom' import )ava"util"Scanner' public class 3rodhimA=astit { public static void main(String[] args) { =andom rast$neL =andom(-+)' Scanner input$neL Scanner(S.stem"in)' int a#b' int per' boolean sakte' 8or(int i$*'iG$&'i%%){ sakte$8alse' a$rast"ne4tAnt(-+)' b$rast"ne4tAnt(-+)' S.stem"out"println(/nr* $ /%a%/ n- $ /%b)' S.stem"out"println(/sa eshte nr* nr- /)' Lhile(;sakte){ S.stem"out"println(/)ep perg)ig)en /)' per$input"ne4tAnt()' i8 (per$$a b) {S.stem"out"println(/perg)ig)a eshte e sakte/)' sakte$true' 0 else {S.stem"out"println(/perg)ig)a nuk eshte e sakte/)' sakte$8alse'0 0 "

0 0 0 /* AFISHIMET 8r1 = 1& 8" = 1! sa eshte 8r1 * 8r" jep per;ji;je8 "08 per;ji;ja eshte e sakte 8r1 = 1 8" = 1 sa eshte 8r1 * 8r" jep per;ji;je8 1 per;ji;ja eshte e sakte 8r1 = + 8" = 1+ sa eshte 8r1 * 8r" jep per;ji;je8 + per;ji;ja eshte e sakte 8r1 = 1& 8" = 1+ sa eshte 8r1 * 8r" jep per;ji;je8 "00 per;ji;ja 8uk eshte e sakte jep per;ji;je8 "0+ per;ji;ja 8uk eshte e sakte jep per;ji;je8 1,+ per;ji;ja eshte e sakte 8r1 = 1& 8" = 8 sa eshte 8r1 * 8r" jep per;ji;je8 100 per;ji;ja 8uk eshte e sakte jep per;ji;je8 106 per;ji;ja eshte e sakte */ Ushtrim 23 : Te perdoren klasat e gatshme te li.rares ne java$ til per te afish ar te dhena per daten$ import )ava"util">ate' import )ava"util"Dalendar' public class Halendar {

"8

public static void main(String[] args) { >ate sot$neL >ate()' S.stem"out"println(/dita sot1/%sot"get>ate())' S.stem"out"println(/mua)i1/%sot"getMonth())' S.stem"out"println(/viti 1/%sot"getQear())' S.stem"out"println(/ora1/%sot"getWours())' S.stem"out"println(/minuti1/%sot"getMinutes())' S.stem"out"println(/)ava sot 1/%Dalendar"XEEHPORPQEA=)' 0 0 /* AFISHIMET $ita sot:11 muaji:8 :iti :110 ora:16 mi8uti:6+ ja:a sot :& */ Ushtrimi 24 : Te ndertohet klasa 4afe$ public class Ha8e { int sasiPsheFeri' int sasiPka8e' String llo)i' void shtoPsheFer(int sasi){ this"sasiPsheFeri$this"sasiPsheFeri%sasi' 0 void provo(){ S.stem"out"println(/duke provuar ka8ene/)' i8(this"sasiPsheFeriG*) S.stem"out"println(/ka8e e hidhur/)' else i8(this"sasiPsheFeriJ@) S.stem"out"println(/ka8e)a eshte e embel/)' else S.stem"out"println(/ka8e)a eshte normale/)' S.stem"out"println(/sasia e ka8ese eshte /%this"sasiPka8e)' S.stem"out"println(/llo)i i ka8ese eshte 1/%this"llo)i)' 0 void derdh(){ this"sasiPsheFeri$+' this"sasiPka8e$+' ",

this"llo)i$/nuk dihet/' S.stem"out"println(/ka8e)a u derdh;;;/)' 0 public static void main(String[] args) { Ha8e k8*$neL Ha8e()' Ha8e k8-$neL Ha8e()' k8*"sasiPsheFeri$*' k8*"sasiPka8e$*' k8*"llo)i$/turke/' k8-"sasiPsheFeri$-' k8-"sasiPka8e$*' k8-"llo)i$/makiato/' k8*"shtoPsheFer(-)' k8*"provo()' k8-"provo()' k8*"derdh()' 0 0 /* AFISHIMET $uke pro:uar ka1e8e ka1eja eshte 8ormale sasia e ka1ese eshte 1 lloji i ka1ese eshte :turke $uke pro:uar ka1e8e ka1eja eshte 8ormale sasia e ka1ese eshte 1 lloji i ka1ese eshte :makiato ka1eja u $er$h222 */ Ushtrimi 2& : Te ndertohet klasa e em.lesirave$ class Embelsira{ String emri' String llo)i' int n)esiPsasie' String 8orma' //konstruktor public Embelsira(String e#String l#int n# String 8) { emri$e' llo)i$l' n)esiPsasie$n' 8orma$8' 0 0 &0

public class EmbelsiraTest{ public static void main(String args[]) { Embelsira biskota$neL Embelsira(/biskote/#/me g)alpe/#-+#/katore/)' S.stem"out"println(/biskota b. denisa/)' S.stem"out"println(/in8o 1/)' S.stem"out"println(biskota"emri%/ /%biskota"llo)i%/ /%biskota"n)esiPsasie%/ /%biskota"8orma)' 0 0 /* AFISHIMET biskota b( $e8isa i81o : biskote me ;jalpe "0 katore */ Ushtrim 2( : 2e restorant5 Porositni em.elsira, Pi//a, dhe k /hinieri do j a pergatise sipas kerkesave t aja$ public class Embelsira{ String emri' String llo)i' int n)esiPsasie' String 8orma' 0 public class 3i55a{ String llo)i' String masa' String e4tra' 0 public class Hu5hinieri{ String emri' int mosha' char g)inia' double vitePpune' void gatua)Pembelsire(Embelsira e#int s){ S.stem"out"println(/duke gatuar embelsiren /)' S.stem"out"println(e"emri)' S.stem"out"println(/Fe eshte e llo)it/)' S.stem"out"println(e"llo)i)' i8 (e"n)esiPsasie G s) S.stem"out"println(/duhet te gatuhet me shume se n)e n)esi/)' S.stem"out"println(/8orma eshte /%e"8orma)' 0

&1

void gatua)Ppi55a(3i55a p){ S.stem"out"println(/gatimi i 3i55a,s/)' S.stem"out"println(/k)o pi55a eshte e llo)it1/)' S.stem"out"println(p"llo)i)' S.stem"out"println(/masa eshte 1/)' S.stem"out"println(p"masa)' S.stem"out"println(/te dhena e4tra per pi55an e porositur/)' S.stem"out"println(p"e4tra)' 0 0 public class 3orosia{ public static void main (String args[]){ Hu5hinieri k*$neL Hu5hinieri()' Embelsira e*$neL Embelsira()' Embelsira e-$neL Embelsira()' 3i55a p*$neL 3i55a()' 3i55a p-$neL 3i55a()' 3i55a p@$neL 3i55a()' // i )apim vlere ob)ektit ku5hinieri k* k*"emri$/Agim/' k*"mosha$@-' k*"g)inia$YMY' k*"vitePpune$-' // i )apim vlere ob)ektit embelsires e* e*"emri$/bakllava/' e*"llo)i$/me arra%sherbet%shuume e mire/' e*"n)esiPsasie$-' e*"8orma$/romb/' // i )apim vlere ob)ektit embelsires ee-"emri$/trelece/' e-"llo)i$/no/' e-"n)esiPsasie$*' e-"8orma$/katror/' // i )apim vlere ob)ektit pi55a p* p*"llo)i$/Margherita/' p*"masa$/8amil)are/' p*"e4tra$/me g)ithe perberesit/' // i )apim vlere ob)ektit pi55a pp-"llo)i$/Hapriciosa/' p-"masa$/8amil)are/' p-"e4tra$/no e4tra/' // i )apim vlere ob)ektit pi55a p@ p@"llo)i$/( stinet/' p@"masa$/8amil)are/' p@"e4tra$/pa speca/' k*"gatua)Pembelsire(e*# @)'

&"

k*"gatua)Pembelsire(e-# -)' k*"gatua)Ppi55a(p*)' k*"gatua)Ppi55a(p-)' k*"gatua)Ppi55a(p@)' 0 0 /* AFISHIMET $uke ;atuar embelsire8 baklla:a 9e eshte e llojit me arra%sherbet%shuume e mire $uhet te ;atuhet me shume se 8je 8jesi 1orma eshte romb $uke ;atuar embelsire8 trele<e 9e eshte e llojit 8o $uhet te ;atuhet me shume se 8je 8jesi 1orma eshte katror ;atimi i Ai))a*s kjo pi))a eshte e llojit: Mar;herita masa eshte : 1amiljare te $he8a e'tra per pi))a8 e porositur me ;jithe perberesit ;atimi i Ai))a*s kjo pi))a eshte e llojit: Gapri<iosa masa eshte : 1amiljare te $he8a e'tra per pi))a8 e porositur 8o e'tra ;atimi i Ai))a*s kjo pi))a eshte e llojit: 6 sti8et masa eshte : 1amiljare te $he8a e'tra per pi))a8 e porositur pa spe<a */

Ushtrim 2) : Te ndertohet nje program ne Java qe konverton temperat ren e dhene nga perdor esi nga 6el"i s ne 7ahrenheit dhe anasjelltas$

&&

import )ava"util"Scanner' public class HonvertimTemp { static double DtoR(double D){ double R' R$B"+/&"+ D%@-' return (R)' 0 static double RtoD(double R){ double D' D$&"+/B"+ (R,@-)' return(D)' 0 public static void main(String[] args) { double tempR#tempD' Scanner input$neL Scanner(S.stem"in)' S.stem"out"println(/!ep temperaturen ne celcius/)' tempD$input"ne4tAnt()' S.stem"out"println(/k)o temperature ne 8ahrenheit eshte 1 /%DtoR(tempD)%/ grade/)' S.stem"out"println(/!ep temperaturen ne 8ahrenheit/)' tempR$input"ne4tAnt()' S.stem"out"println(/k)o temperature ne celcius eshte 1 /%RtoD(tempR)%/ grade/)' 0 0 /* AFISHIMET Bep temperature8 8e <el<ius "1 kjo temperature 8e 1ahre8heit eshte : !,#80000000000001 ;ra$e Bep temperature8 8e 1ahre8heit 100 kjo temperature 8e <el<ius eshte : & # 8 ;ra$e */ Ushtrim 2* : 2dertoni nje klase per makinen t aj te re$ public class Autom)et{ //lista e atributeve per autom)etin String llo)Pkarburanti' String tipi' int modeli' char kategoria' int viti' String ng).ra' //lista e metodave int shtoPshpe)tesine(){ S.stem"out"println(/Shpe)tesia tani eshte N+km/h/)' return N+' 0

&6

int ulPshpe)tesine(){ S.stem"out"println(/Shpe)tesia tani eshte @+km/h/)' return @+' 0 boolean hapPdritaren(){ S.stem"out"println(/dritar)a eshte e hapur tani/)' return true' 0 boolean nde5Pdritat(){ S.stem"out"println(/dritat )ane nde5ur/)' return true' 0 0 public class >emoAuto{ public static void main (String args[]){ // makina * Autom)et m*$neL Autom)et()' m*"llo)Pkarburanti$/>iesel/' m*"tipi$/Riat/' m*"modeli$*' m*"kategoria$Y7Y' m*"viti$*BB-' m*"ng).ra$/E bardhe/' int 4$m*"ulPshpe)tesine()' // makina Autom)et m-$neL Autom)et()' m-"llo)Pkarburanti$/euro,>iesel/' m-"tipi$/7en5/' m-"modeli$--+' m-"kategoria$Y7Y' m-"viti$-+++' m-"ng).ra$/Zri/' 4$m-"shtoPshpe)tesine()' // makina @ Autom)et m@$neL Autom)et()' m@"llo)Pkarburanti$/euro,>iesel/' m@"tipi$/7MX/' m@"modeli$&@+' m@"kategoria$Y7Y' m@"viti$-++&' m@"ng).ra$/E kuFe/' boolean b$m@"hapPdritaren()' 0 0

&+

/* AFISHIMET Shpejtesia ta8i eshte &0km/h Shpejtesia ta8i eshte 80km/h $ritarja eshte e hapur ta8i */ Ushtrim 2, : 2dertoni nje klase per makinen t aj te re, kete here me metoda statike, dhe me nje atri. t stati" per n mrin e makinave ne total per kete vit$ public class Vetura { String targa' String llo)i' String shasia' String pronari' String ng).ra' //atribut statik static long nrPtotalP-+**' public Vetura(String targa#String llo)i#String shasia# String pronari# String ng).ra) { this"targa$targa' this"llo)i$llo)i' this"shasia$shasia' this"pronari$pronari' this"ng).ra$ng).ra' 0 //metode statike static void pershendet)e(){ S.stem"out"println(/t)eta )ue)/)' S.stem"out"println(/te dhenat per makinen i merrni nga main/)' 0 public static void main (String args[]){ // nuk mund te therras konstruktorin e gatshem1 // Vetura v*$ neL Vetura()' Vetura v*$neL Vetura(/sh (-/#/7en5/#/Abd-*/#/!etmir Walluni/#/blu/)' Vetura"nrPtotalP-+**$*+((' // metoda statike nuk thirret ne lidh)e me n)e ob)ekt te caktuar Vetura"pershendet)e()' S.stem"out"println(/ vetura * ka keto te dhena1 /)' S.stem"out"println(/targa 1/%v*"targa)' S.stem"out"println(/llo)i 1/%v*"llo)i)'

&!

S.stem"out"println(/pronari 1/%v*"pronari)' S.stem"out"print(/numri total i makinave deri tani per vitin -+** 1/)' S.stem"out"println(Vetura"nrPtotalP-+**)' 0 0 /* AFISHIMET tjeta juej te $he8at per maki8e8 i merr8i 8;a mai8 :etura 1 ka keto te $he8a: tar;a :sh 6" lloji :/e8) pro8ari :Betmir Hallu8i 8umri total i maki8a:e $eri ta8i per :iti8 "011 :1066 */ Ushtrimi 3-: Te ndertohet klasa 3a"e public class Mac)a { String =raca' String Ig).ra' String Emri' char Z)inia' int ushFimi' String ushFimiPpre8' int Z)uanPmin)(int nr){ S.stem"out"println (/Mac)a sot ka kapur /%nr%/ min)"/)' return nr' 0 public void setVendosPemer(String em){ Emri$em' S.stem"out"println (/Mac)a Fuhet /%em%/"/)' 0 void [shFehet(int ushF){ ushFimi$ushF' S.stem"out"println (/A)o ushFehet /%ushF% / here ne dite" /)' 0 void [shFPpre8(String pre8){ ushFimiPpre8$pre8' S.stem"out"println (/[shFimi i sa) i pre8eruar eshte /%pre8 )' 0 public Mac)a (String =# String Ig)# char Z)){ =raca$=' Ig).ra$Ig)' Z)inia$Z)' 0

&

public static void main(String[] args) { Mac)a M*$ neL Mac)a(/3ersiane/# /ka8e/#YMY)' Mac)a M-$ neL Mac)a(/Eg)iptiane/#/te bardhe/#YRY)' S.stem"out"println (/ 3er macen e pare1 /)' M*"setVendosPemer (/Mio/)' S.stem"out"println (/=raca e maces eshte /%M*"=raca%/"/)' S.stem"out"println (/A)o ka ng).re /%M*"Ig).ra%/"/)' S.stem"out"println (/Z)inia e sa) eshte /%M*"Z)inia%/"/)' M*"Z)uanPmin) (@)' M*"[shFehet (()' M*"[shFPpre8 (/3eshku"/)' S.stem"out"println (/ /)' S.stem"out"println (/ 3er macen e d.te1 /)' M-"setVendosPemer (/7ianca/)' S.stem"out"println (/=raca e maces eshte /%M-"=raca%/"/)' S.stem"out"println (/A)o ka ng).re /%M-"Ig).ra%/"/)' S.stem"out"println (/Z)inia e sa) eshte /%M-"Z)inia%/"/)' M-"Z)uanPmin) (-)' M-"[shFehet (@)' M-"[shFPpre8 (/\umeshti"/)' 0 L /* AFISHIMET Aer ma<e8 e pare: Ma<ja 9uhet Mio# 7ra<a e ma<es eshte Aersia8e# Ajo ka 8;j(re ka1e# Mji8ia e saj eshte M# Ma<ja sot ka kapur & mi8j# Ajo ush9ehet 6 here 8e $ite# ?sh9imi i saj i pre1eruar eshte Aeshku# Aer ma<e8 e $(te: Ma<ja 9uhet /ia8<a# 7ra<a e ma<es eshte E;jiptia8e# Ajo ka 8;j(re te bar$he# Mji8ia e saj eshte F# Ma<ja sot ka kapur " mi8j# Ajo ush9ehet & here 8e $ite# ?sh9imi i saj i pre1eruar eshte Numeshti# */ Ushtrim 31 : Te ndertohet klasa Te8hena qe jep informa"ion per nje .anor, si dhe te dhena statike qe jane per "do .anor te shkodres$ Te dhenat te jene private, dhe te ndertohet per se"ilin atri. t metodat, set dhe get perkates$

&8

public class Tedhena { private String emer' private String mbiemer' private String ditelind)a' private char g)inia' private int g)atesi' private static int Siper8aF)aAM7$+' private static int 7anShk$+' private static int >istTokWen$+' public String getemer(){ return emer' 0 public String getmbiemer(){ return mbiemer' 0 public String getditelind)a(){ return ditelind)a' 0 public char getg)inia(){ return g)inia' 0 public int getg)atesi(){ return g)atesi' 0 public static int getSiper8aF)aAM7(){ return Siper8aF)aAM7' 0 public static int get7anShk(){ return 7anShk' 0 public static int get>istTokWen(){ return >istTokWen' 0 public Tedhena(String emer# String mbiemer# String ditelind)a# char g)inia# int g)atesi) { this"emer$emer' this"mbiemer$mbiemer' this"ditelind)a$ditelind)a' this"g)inia$g)inia' this"g)atesi$g)atesi' Siper8aF)aAM7$-NO(N' 7anShk$*+N+++' >istTokWen$@N((+@' 0 public void A8isho(){ S.stem"out"println(/ Te dhena per banorin nr *1/)'

&,

S.stem"out"println(/Emri i banorit * eshte1/%this"getemer())' S.stem"out"println(/Mbiemri eshte1/%this"getmbiemer())' S.stem"out"print(this" getemer())' S.stem"out"println(/ eshte e g)inise1/%this"getg)inia())' S.stem"out"println(this"getemer()%/ eshte e g)ate /%this"getg)atesi())' S.stem"out"println(/ /)' S.stem"out"println(/Siper8aF)a e ShFiperise eshte1 /%getSiper8aF)aAM7())' S.stem"out"println(/Iumri i popullsise se Shkodres eshte 1 /%get7anShk())' S.stem"out"println(/>istanca Toke,Wene eshte 1 /%get>istTokWen())' 0 0 public class TedhenaTest { public static void main(String[] args) { Tedhena 7anor*$neL Tedhena(/>iana/# /Ele5a)/# /i datelind)es MA=S *BB*/# YRY#*O+)' Tedhena 7anor-$neL Tedhena(/!etmir/# /Walluni/# /i datelind)es !anar *BB+/# YMY#*ON)' S.stem"out"println(/ /)' S.stem"out"println(/ Te dhena per banorin nr -1/)' S.stem"out"println(/Emri i banorit eshte1/%7anor-"getemer())' S.stem"out"println(/Mbiemri i banorit eshte1/%7anor-"getmbiemer())' S.stem"out"print(7anor-"getemer())' S.stem"out"println(/ eshte i g)inise1/%7anor-"getg)inia())' S.stem"out"println(7anor*"getemer()%/ eshte e g)ate /%7anor-"getg)atesi())' S.stem"out"println(/ /)' S.stem"out"println(/Siper8aF)a e ShFiperise eshte1 /%7anor-"getSiper8aF)aAM7())' S.stem"out"println(/Iumri i popullsise se Shkodres eshte 1 /%7anor-"get7anShk())' S.stem"out"println(/>istanca Toke,Wene eshte 1 /%7anor-"get>istTokWen())' S.stem"out"println(/>istanca Toke,Wene eshte 1 /%Tedhena"getSiper8aF)aAM7())' S.stem"out"println(/ /)' S.stem"out"println(/A8ishim te dhenash me metoden void1/)' S.stem"out"println(/ /)' 7anor*"A8isho()' 0 0

60

/* AFISHIMET Te $he8a per ba8ori8 8r ": Emri i ba8orit " eshte:Betmir Mbiemri i ba8orit " eshte:Hallu8i Betmir eshte i ;ji8ise:M Oia8a eshte e ;jate 1 8 Siper1a9ja e Sh9iperise eshte: "8 68 Cumri i popullsise se Shko$res eshte : 108000 Oista8<a Toke*He8e eshte : &8660& Oista8<a Toke*He8e eshte : "8 68 A1ishim te $he8ash me meto$e8 :oi$: Te $he8a per ba8ori8 8r 1: Emri i ba8orit 1 eshte:Oia8a Mbiemri eshte:Ele)aj Oia8a eshte e ;ji8ise:F Oia8a eshte e ;jate 1 0 Siper1a9ja e Sh9iperise eshte: "8 68 Cumri i popullsise se Shko$res eshte : 108000 Oista8<a Toke*He8e eshte : &8660& */ Ushtrim 32: Te ndertohet klasa 9oman$ public class =oman { String titull' String g)inia' String autori' int nrP8aFe' boolean biblio' boolean neP8ilm' public String gettitull(){ return titull' 0 public void settitull(String Tit){ titull$Tit' 0 public String getg)inia(){ return g)inia' 0 public void setg)inia(String Z)){ g)inia$Z)' 0 61

public String getautori(){ return autori' 0 public void setautori(String A){ autori$A' 0 void shtoPnePbiblioteke (boolean biblio){ i8 (biblio) S.stem"out"println(/Mibri nuk eshte ne biblioteke/)' else { biblio$true' S.stem"out"println(/Mibri sapo u shtua ne biblioteke/)' 0 0 void reali5oP8ilm (boolean neP8ilm){ i8 (neP8ilm) S.stem"out"println(/Mibri nuk eshte bere 8ilm/)' else { neP8ilm$true' S.stem"out"println(/Eshte reali5uar n)e 8ilm i ba5uar ne kete liber/)' 0 0 public =oman(int nr# boolean b# boolean 8){ nrP8aFe$nr' biblio$b' neP8ilm$8' 0 public static void main(String[] args) { =oman =*$neL =oman((&@#true#8alse)' =oman =-$neL =oman(@++#8alse#true)' S.stem"out"println(/AIRO MA7=A I= */)' =*"settitull(/3"S A Move Qou/)' S.stem"out"println(/Titulli i librit eshte1/%=*"gettitull())' =*"setg)inia(/=omantik/)' S.stem"out"println(/Mibri eshte1/%=*"getg)inia())' =*"setautori(/Decilia Ahern/)' S.stem"out"println(/Autori i librit eshte1/%=*"getautori())' S.stem"out"println(/Mibri ka 1/%=*"nrP8aFe%/8aFe/)' S.stem"out"println(/A eshte bere n)e 8ilm ba5uar mbi kete liber1/%=*"neP8ilm)' =*"reali5oP8ilm(=*"neP8ilm)' =*"shtoPnePbiblioteke(=*"biblio)' S.stem"out"println(/ /)'

6"

S.stem"out"println(/AIRO MA7=A I= -/)' =-"settitull(/Aksidenti/)' S.stem"out"println(/Titulli i librit eshte1/%=-"gettitull())' =-"setg)inia(/3olicesk/)' S.stem"out"println(/Mibri eshte1/%=-"getg)inia())' =-"setautori(/Asmail Hadare/)' S.stem"out"println(/Autori i librit eshte1/%=-"getautori())' S.stem"out"println(/Mibri ka 1/%=-"nrP8aFe%/ 8aFe/)' =-"reali5oP8ilm(=-"neP8ilm)' 0 0 / ARASWAMET ICFP @I/7I C7 1 Titulli i librit eshte:A#S I @o:e Qou @ibri eshte:7oma8tik Autori i librit eshte:Re<ilia Aher8 @ibri ka :6+&1a9e A eshte bere 8je 1ilm ba)uar mbi kete liber:1alse Eshte reali)uar 8je 1ilm i ba)uar 8e kete liber @ibri 8uk eshte 8e biblioteke ICFP @I/7I C7 " Titulli i librit eshte:Aksi$e8ti @ibri eshte:Aoli<esk Autori i librit eshte:Ismail Ga$are @ibri ka :&00 1a9e @ibri 8uk eshte bere 1ilm */ Ushtrim 33 : 2dertoni nje klase oren$ Te perdoret formatimi me 0tring$format public class Hoha { private int ore' // + , -@ private int minute' // + , &B private int sekonde' // + , &B public void caktoHohen( int o# int m# int s ) { ore $ ( ( o J$ + :: o G -( ) V o 1 + )' minute $ ( ( m J$ + :: m G 2+ ) V m 1 + )' sekonde $ ( ( s J$ + :: s G 2+ ) V s 1 + )' 0 public String konvertoIeString() { return String"8ormat( /6+-d16+-d16+-d/# ore# minute# sekonde )' 0 6&

public String 8ormatiStandart() { return String"8ormat( /6d16+-d16+-d 6s/# ( ( ore $$ + 99 ore $$ *- ) V *- 1 ore 6 *- )# minute# sekonde# ( ore G *- V /AM/ 1 /3M/ ) )' 0 0 public class HohaTest { public static void main( String args[] ) { Hoha koha $ neL Hoha()' S.stem"out"print( /Vlera ne string 1 / )' S.stem"out"println( koha"konvertoIeString() )' S.stem"out"print( /Vlera ne standart1 / )' S.stem"out"println( koha"8ormatiStandart() )' S.stem"out"println()' koha"caktoHohen( *@# -O# 2 )' S.stem"out"print( /Vlera ne string1 / )' S.stem"out"println( koha"konvertoIeString() )' S.stem"out"print( /Vlera standarte tani eshte1 / )' S.stem"out"println( koha"8ormatiStandart() )' S.stem"out"println()' koha"caktoHohen( BB# BB# BB )' S.stem"out"println( /Tentative per te dhena gabim1/ )' S.stem"out"print( /Hoha ne string1 / )' S.stem"out"println( koha"konvertoIeString() )' S.stem"out"print( /Hoha standarte1 / )' S.stem"out"println( koha"8ormatiStandart() )' 0 0 /* AFISHIMET Slera 8e stri8; : 00:00:00 Slera 8e sta8$art: 1":00:00 AM Slera 8e stri8;: 1&:" :0! Slera sta8$arte ta8i eshte: 1:" :0! AM Te8tati:e per te $he8a ;abim: Goha 8e stri8;: 00:00:00 Goha sta8$arte: 1":00:00 AM */

66

Ushtrimi 34 : Te ndertohet nje klase per oren$ Te perdoret fjala "eles this$ class OraTani { public int ore' // +,-@ public int minute' // +,&B public int sekonde' // +,&B public String konvertoIeString() { return String"8ormat( /6-(s1 6sSn6-(s1 6s/# /this"8ormatiStandart ()/# this"8ormatiStandart ()# /8ormatiStandart()/# 8ormatiStandart() )' 0 public String 8ormatiStandart() { return String"8ormat( /6+-d16+-d16+-d/# this"ore# this"minute# this"sekonde )' 0 0 public class ThisTest { public static void main( String args[] ) { OraTani k.Moment $ neL OraTani(*@#*()' //k.Moment"ora$*@' //k.Moment"minute$*(' S.stem"out"println(/ora e painiciali5uar1/)' S.stem"out"println(k.Moment"ore%/1/%k.Moment"minute%/1/%k.Moment"sek onde)' k.Moment"caktoHohen(*&#-(#*-)' S.stem"out"println(/ora e iniciali5uar1/)' S.stem"out"println(k.Moment"ore%/1/%k.Moment"minute%/1/%k.Mome nt"sekonde)' 0 0 /* AFISHIMET ora e pai8i<iali)uar: 1&:16:0 ora e objektit :1 ora lokale e meto$e :1+ mi8uti i objektit :" mi8uti lokal :"6 seko8$i i objektit :& seko8$i lokal :1" ora e i8i<iali)uar: 1:":& */ 6+

Ushtrimi 3& : Te ndertohet thirrja e metodave te klases :ra, por d ke perdore per te gjitha fjalen "eles this$ class OraTani { int ore' // +,-@ int minute' // +,&B int sekonde' // +,&B public OraTani(int ore#int minute){ this"ore$ore' this"minute$minute' this"sekonde$+' 0 public void caktoHohen( int ore# int minute# int sekonde ) { this"ore $ *' this"minute $ -' this"sekonde $ @' S.stem"out"println(/ora e ob)ektit 1/%this"ore)' S.stem"out"println(/ora lokale e metode 1/%ore)' S.stem"out"println(/minuti i ob)ektit 1/%this"minute)' S.stem"out"println(/minuti lokal 1/%minute)' S.stem"out"println(/sekondi i ob)ektit 1/%this"sekonde)' S.stem"out"println(/sekondi lokal 1/%sekonde)' 0 0 Ushtrimi 3( : Te ndertohet klasa ; lishte public class Mulishte { String llo)iPluleve' String pronari' int siper8aF)a' String komponente' public String getMlo)iPluleve() { return llo)iPluleve' 0 public void setMlo)iPluleve(String llo)iMuleve) { llo)iPluleve $ llo)iMuleve' 0 public String get3ronari() { return pronari' 0 public void set3ronari(String pronari) { this"pronari $ pronari' 0

6!

public int getSiper8aF)a() { return siper8aF)a' 0 public void setSiper8aF)a(int siper8aF)a) { this"siper8aF)a $ siper8aF)a' 0 public String getkomponente() { return komponente' 0 public void setkomponente(String komponente) { this"komponente $ komponente' 0 0 public class MulishteTest { public static void main(String[] args) { Mulishte l*$ neL Mulishte()' l*"setMlo)iPluleve(/Trenda8ila/)' l*"set3ronari(/E"W"/)' l*"setSiper8aF)a(-)' l*"setkomponente(/VVVVV/)' S.stem"out"println (/llo)i i luleve eshte 1/%l*"getMlo)iPluleve())' S.stem"out"println (/pronari eshte eshte 1/%l*"get3ronari())' S.stem"out"println (/siper8aF)a eshte 1/%l*"getSiper8aF)a())' S.stem"out"println (/komponentet )ane 1/%l*"getkomponente())' 0 0 /* AFISHIMET lloji i lule:e eshte :Tre8$a1ila pro8ari eshte eshte :E#H# siper1a9ja eshte :" kompo8e8tet ja8e :FFFFF */ Ushtrimi 3) : Te ndertohet klasa 2enp nes, me metoda set dhe get per se"ilin atri. t$ public class Ienpunes { private String emri' private String mbiemri' private static int numer $ +'

public Ienpunes( String emr# String mb ) { emri $ emr' mbiemri $ mb' numer%%' 0 public String getEmri() { return emri' 0 public String getMbiemri() { return mbiemri' 0 public static int getIumer() { return numer' 0 0 public class IenpunesTest { public static void main( String args[] ) { S.stem"out"println( /Iumri i nenpunesve para 8a5es se intervistes se punes1 /% Ienpunes"getIumer() )' Ienpunes e* $ neL Ienpunes( /Susan/# /7aker/ )' Ienpunes e- $ neL Ienpunes( /7ob/# /7lue/ )' S.stem"out"println( /Iumri i nenpunesve pas intervistes1 / )' S.stem"out"println( /via e*"getIumer()1/% e*"getIumer())' S.stem"out"println( /via e-"getIumer()1/% e-"getIumer() )' S.stem"out"println( /via Ienpunes"getIumer()1/% Ienpunes"getIumer() )' S.stem"out"println( /Ienpunesi *1 /% e*"getEmri()%/ /% e*"getMbiemri())' S.stem"out"println( /Ienpunesi -1 /% e-"getEmri()%/ /% e-"getMbiemri())' 0 0 /* AFISHIMET Cumri i 8e8pu8es:e para 1a)es se i8ter:istes se pu8es: 0 Cumri i 8e8pu8es:e pas i8ter:istes: :ia e1#;etCumer45:" :ia e"#;etCumer45:" :ia Ce8pu8es#;etCumer45:" Ce8pu8esi 1: Susa8 /aker Ce8pu8esi ": /ob /lue */ 68

Ushtrim 3* : 2dertohet nje program qe do perdoret ne <ar+9estorant import )ava"util"Scanner' public class Menu { int 5g)edh)a# 5g)edh)aP7ar#5g)edh)aP=es# 5g)edh)aP3i55a#cmim' Scanner input $ neL Scanner( S.stem"in )' void menu*(){ S.stem"out"println (/Mire se vini ne restorantin tone;/)' S.stem"out"println (/!u lutem 5g)idhni n)e opsion1/)' S.stem"out"println (/*" 7ar/)' S.stem"out"println (/-" =estorant/)' S.stem"out"println (/@" 3i55eri/)' this"5g)edh)a $ this"input"ne4tAnt()' i8 (this"5g)edh)a $$*) { S.stem"out"println (/!u 5g)odhet1 7ar"/)' this"7ar()' 0 i8 (this"5g)edh)a $$-) { S.stem"out"println (/!u 5g)odhet1 =estorant"/)' this"=estorant()' 0 i8 (this"5g)edh)a $$@) { S.stem"out"println (/!u 5g)odhet1 3i55eri"/)' this"3i55eri()' 0 i8 (this"5g)edh)a J@) { S.stem"out"println (/H. opsion nuk ek5iston;/)' 0 0 void 7ar(){ S.stem"out"println (/3orosia per ne bar1 /)' S.stem"out"println (/*" Ha8e/)' S.stem"out"println (/-" Machiato/)' S.stem"out"println (/@" Da)/)' S.stem"out"println (/(" 3i)e 8reskuese/)' S.stem"out"println (/&" 3i)e alkoolike/)' S.stem"out"println (/?g)idhni opsionin Fe deshironi1 /)' this"5g)edh)aP7ar $ this"input"ne4tAnt()' i8 (this"5g)edh)aP7ar$$*){ S.stem"out"println (/!u 5g)odhet ka8e"/)' this"cmimi(*)' 0

6,

i8 (this"5g)edh)aP7ar$$-){ S.stem"out"println (/!u 5g)odhet Machiato"/)' this"cmimi(-)' 0 i8 (this"5g)edh)aP7ar$$@){ S.stem"out"println (/!u 5g)odhet Da)"/)' this"cmimi(@)' 0 i8 (this"5g)edh)aP7ar$$(){ S.stem"out"println (/!u 5g)odhet 3i)e 8reskuese"/)' this"cmimi(()' 0 i8 (this"5g)edh)aP7ar$$&){ S.stem"out"println (/!u 5g)odhet 3i)e alkoolike"/)' this"cmimi(&)' 0 i8 (this"5g)edh)aP7arJ&) S.stem"out"println (/H. opsion nuk ek5iston;/)' 0 void =estorant (){ S.stem"out"println (/3orosia per ne =estorant1 /)' S.stem"out"println (/*" 7er5olla/)' S.stem"out"println (/-" 3eshk/)' S.stem"out"println (/@" Makarona/)' S.stem"out"println (/(" Supe/)' S.stem"out"println (/&" Masagna/)' S.stem"out"println (/2" Sallate/)' this"5g)edh)aP=es $ this"input"ne4tAnt()' i8 (this"5g)edh)aP=es$$*){ S.stem"out"println (/!u 5g)odhet 7er5olla"/)' this"cmimi(2)' 0 i8 (this"5g)edh)aP=es$$-){ S.stem"out"println (/!u 5g)odhet 3eshk"/)' this"cmimi(O)' 0 i8 (this"5g)edh)aP=es$$@){ S.stem"out"println (/!u 5g)odhet Makarona"/)' this"cmimi(N)' 0 i8 (this"5g)edh)aP=es$$(){ S.stem"out"println (/!u 5g)odhet Supe"/)' this"cmimi(B)' 0 i8 (this"5g)edh)aP=es$$&){ S.stem"out"println (/!u 5g)odhet Masagna"/)'

+0

this"cmimi(*+)' 0 i8 (this"5g)edh)aP=es$$&){ S.stem"out"println (/!u 5g)odhet Sallate"/)' this" cmimi(**)' 0 i8 (this"5g)edh)aP=esJ&*) S.stem"out"println (/H. opsion nuk ek5iston;/)' 0 void 3i55eri(){ S.stem"out"println (/3orosia per ne 3i55eri1 /)' S.stem"out"println (/*" Margerita/)' S.stem"out"println (/-" ( Stinet/)' S.stem"out"println (/@" Mi44/)' S.stem"out"println (/(" Hater >)athra/)' this"5g)edh)aP3i55a$ input"ne4tAnt()' i8 (this"5g)edh)aP3i55a$$*){ S.stem"out"println (/!u 5g)odhet Margerita"/)' this"cmimi(*-)' 0 i8 (this"5g)edh)aP3i55a$$-){ S.stem"out"println (/!u 5g)odhet ( Stinet"/)' this"cmimi(*@)' 0 i8 (this"5g)edh)aP3i55a$$@){ S.stem"out"println (/!u 5g)odhet Mi44"/)' this"cmimi(*()' 0 i8 (this"5g)edh)aP3i55a$$(){ S.stem"out"println (/!u 5g)odhet Hater >)athra"/)' this"cmimi(*&)' 0 i8 (this"5g)edh)aP3i55aJ() S.stem"out"println (/H. opsion nuk ek5iston;/)' 0 void cmimi (int kodi){ sLitch (kodi) { case *1 S.stem"out"println (/Ha8)a kushton O+ leke"/)' break' case -1 S.stem"out"println (/Machiato kushton N+ leke" /)' break' case @1 S.stem"out"println (/Da) kushton N+ leke"/)'

+1

break' case (1 S.stem"out"println (/3i)e 8reskuese kushton *&+ leke" /)' break' case &1 S.stem"out"println (/3i)e alkoolike kushton -&+ leke"/)' break' case 21 S.stem"out"println (/7er5olla kushton (&+ leke" /)' break' case O1 S.stem"out"println (/3eshk kushton 2++ leke" /)' break' case N1 S.stem"out"println (/Makarona kushton -++ leke" /)' break' case B1 S.stem"out"println (/Supe kushton *++ leke" /)' break' case *+1 S.stem"out"println (/Masagna kushton -&+ leke" /)' break' case **1 S.stem"out"println (/Sallata kushton &+ leke" /)' break' case *-1 S.stem"out"println (/3i55a YMargherittaY kushton (&+ leke" /)' break' case *@1 S.stem"out"println (/3i55a Y( StinetY kushton (++ leke" /)' break' case *(1 S.stem"out"println (/3i55a YMi44 kushtonY &++ leke" /)' break' case *&1 S.stem"out"println (/3i55a YHater >)athraY kushton &&+ leke" /)' break' 0 0

+"

public static void main(String[] args) { Menu m*$neL Menu()' m*"menu*()' 0 0 /* SHEM/?@@ AFISHIMI Mire se :i8i 8e restora8ti8 to8e2 Bu lutem );ji$h8i 8je opsio8: 1# /ar "# 7estora8t &# Ai))eri " Bu );jo$het: 7estora8t# Aorosia per 8e 7estora8t: 1# /er)olla "# Aeshk &# Makaro8a 6# Supe +# @asa;8a !# Sallate + Bu );jo$het @asa;8a# @asa;8a kushto8 "+0 leke# Bu );jo$het Sallate# Sallata kushto8 +0 leke# */ Ushtrimi 3, : 8 ke perdore trashegimine, ndertoni klasat 7orm lar, 7orm lar= dhe 7orm lar=<$ 4onstr ktori i klasave te jete me arg mente$ 4UJ8>0 ne perdorimin e fjales "eles s per$ class Rormular { Rormular(int i){ S.stem"out"println(/konstruktori i 8ormular/)' 0 0 class RormulariA e4tends Rormular{ RormulariA(int i#String s){ super(i)' S.stem"out"println(/konstruktori i 8ormularA/)' 0 0 public class RormularA7 e4tends RormulariA{ RormularA7(int i#String s#int )){ super(i#s)' S.stem"out"println(/konstruktori i 8ormularA7/)' 0

+&

public static void main(String[] args) { RormularA7 4$neL RormularA7(@#/dg8)d/#@()' 0 0 /* AFISHIMET ko8struktori i 1ormular ko8struktori i 1ormularA ko8struktori i 1ormularA/ */ Ushtrimi 4-: Te ndertohet klasa =plikim, 7orm lar dhe 4arte?d$ Te dallohen elementet e trashegimise dhe per.erjes$ public class Rormulari { public Rormulari(String emer#String mbi) { S.stem"out"println(/emeri eshte /%emer)' S.stem"out"println(/mbiemri eshte /%mbi)' 0 0 class RormularA* e4tends Rormulari{ public RormularA*(){ super(/edmir/#/hasmu)a)/)' S.stem"out"println(/k. eshte kosnstruktori 8ormularA* /)' 0 0 class RormularA- e4tends Rormulari { public RormularA-() { super(/edmir/#/hasmu)a)/)' S.stem"out"println(/k. eshte kosnstruktori 8ormularA- /)' 0 0 class Harteid{ public Harteid(String id){ S.stem"out"println(/nr" i id eshte/%id)' 0 0 public class Aplikimi { public static void main(String[] args) { RormularA* a*$neL RormularA*()' S.stem"out"println()' RormularA- a-$neL RormularA-()' S.stem"out"println()' Harteid id$neL Harteid(/A*-@&&BNO@/)' 0 0

+6

/* SHEM/?@@ AA@IGIMI emeri eshte e$mir mbiemri eshte hasmujaj k( eshte kos8struktori 1ormularA1 emeri eshte e$mir mbiemri eshte hasmujaj k( eshte kos8struktori 1ormularA" 8r# i i$ eshteA1"&++,8 & */ She8im : Trashe;imi kemi mes klasa:e FormularA1 $he FormulariT FormularA" $he Formulari# Aerberje kemi 8e klase8 Aplikimi= 9e permba8 objekte te FormularA1= FormularA" $he GarteIO Ushtrim 41: Te ndertohen klasat e nje kopshti /oologjik$ Te perdoret trashegimia, me konstr ktoret pa arg menta$ class ?og{ public ?og(){ S.stem"out"println(/k. eshte konstruktori i 5ogut/)' 0 0 class 3ellumb e4tends ?og{ public 3ellumb(){ S.stem"out"println(/k. eshte konstruktori i pellumbit/)' 0 0 class Ha8she{ public Ha8she(){ S.stem"out"println(/k. eshte konstruktori i ka8she/)' 0 0 class Mace e4tends Ha8she{ public Mace(){ S.stem"out"println(/k. eshte konstruktori i maces/)' 0 0 class \en e4tends Ha8she { public \en(){ S.stem"out"println(/k. eshte konstruktori i Fenit/)' 0 0

++

public class ?oo { public static void main(String[] args) { S.stem"out"println(/thirr)a \en 5*$neL \en ()'/)' \en 5*$neL \en ()' S.stem"out"println()' S.stem"out"println(/thirr)a Mace 5-$neL Mace()'/)' Mace 5-$neL Mace()' S.stem"out"println()' S.stem"out"println(/thirr)a 3ellumb 5@$neL 3ellumb()'/)' 3ellumb 5@$neL 3ellumb()' 0 0 /* AFISHIMET thirrja Ne8 )1=8eU Ne845T k( eshte ko8struktori i ka1she k( eshte ko8struktori i 9e8it thirrja Ma<e )"=8eU Ma<e45T k( eshte ko8struktori i ka1she k( eshte ko8struktori i ma<es thirrja Aellumb )&=8eU Aellumb45T k( eshte ko8struktori i )o;ut k( eshte ko8struktori i pellumbit */ Ushtrim 42 : Te ndertohen klasa kopesht /oologjik$ Te perdoret trashegimia, dhe konstr ktoret te perm.ajne arg mente$ 4UJ8>0 ne perdorimin e fjales "eles s per$ class ?og{ public ?og(int i){ S.stem"out"println(/k. eshte konstruktori i 5ogut i $ /%i)' 0 0 class 3ellumb e4tends ?og{ public 3ellumb(int i#String s){ super(*)' S.stem"out"println(/k. eshte konstruktori i pellumbit i$ /%i%/Sts $/%s)' 0 0 class Ha8she{ public Ha8she(int )#int a){ S.stem"out"println(/k. eshte konstruktori i ka8she ) $/%)%/Sta $/%a)' 0 0

+!

class Mace e4tends Ha8she{ public Mace(int )#String a){ super(-#@)' S.stem"out"println(/k. eshte konstruktori i maces ) $/%)%/Sta $/%a)' 0 0 class >og e4tends Ha8she { public >og(String a#String s){ super(B#*)' S.stem"out"println(/k. eshte konstruktori i Fenit a $/%a%/Sts $/%s)' 0 0 public class ?oo { public static void main(String[] args) { S.stem"out"println(/thirr)a >og 5*$neL >og(S/FenS/#S/rracesS/)'/)' >og 5*$neL >og(/Fen/#/rraces/)' S.stem"out"println()' S.stem"out"println(/thirr)a Mace 5-$neL Mace(+#S/macokS/)'/)' Mace 5-$neL Mace(+#/macok/)' S.stem"out"println()' S.stem"out"println(/thirr)a 3ellumb 5@$neL 3ellumb(N#S/pllumbS/)'/)' 3ellumb 5@$neL 3ellumb(N#/pllumb/)' 0 0 /* AFISHIMET thirrja Oo; )1=8eU Oo;4V9e8V=Vrra<esV5T k( eshte ko8struktori i ka1she j =, a =1 k( eshte ko8struktori i 9e8it a =9e8 s =rra<es thirrja Ma<e )"=8eU Ma<e40=Vma<okV5T k( eshte ko8struktori i ka1she j =" a =& k( eshte ko8struktori i ma<es j =0 a =ma<ok thirrja Aellumb )&=8eU Aellumb48=VpllumbV5T k( eshte ko8struktori i )o;ut i = 1 k( eshte ko8struktori i pellumbit i= 8 s =pllumb */

Ushtrime 43 : Te ndertohet nje ta.ele nje dimensionale, d ke e ini"iali/ ar me vlerat nga kodi$ public class AntTabelaSW* { int tab[]${+#*#-#@#(#&#2#O#N#B0' public static void main(String[] args) { int tab[]${+#*#-#@#(#&#2#O#N#B0' S.stem"out"println(/a8ishimi i tabeles/)' 8or(int i$+' i G tab"length'i%% ) S.stem"out"print(i%/ i $ /%tab[i]%/Sn/)' 0 0 /* AFISHIMET a1ishimi i tabeles 0i=0 1i=1 "i=" &i=& 6i=6 +i=+ !i=! i= 8i=8 ,i=, */ Ushtrime 44 : Te ndertohet nje ta.ele nje dimensionale, d ke e ini"iali/ ar me vlerat nga kodi, dhe nje ta.ele d' dimensionale, te ini"iali/ ar nga kodi$ public class Tab>.>imensionaleSh* { int tab[]${+#*#-#@#(#&#2#O#N#B0' public static void main(String[] args) { int tab[][]${{+#*#-#@#(#&#2#O0#{+#*#-#@#(#&0#{*#-#@#(#&00' S.stem"out"println(/a8ishimi i tabeles/)' 8or ( int i$+' i G tab"length'i%% ) { 8or ( int )$+' ) G tab[i]"length ' )%% ) S.stem"out"print(tab[i][)]%/St/)' S.stem"out"println()' 0 0 0

+8

/* AFISHIMET a1ishimi i tabeles 0 1 " & 0 1 */ 1 " " & & 6

6 6 +

+ +

! !

Ushtrime 4&: Te ndertohet nje ta.ele d' dimensionale, nga tastjera$ Perdor esi jep sa rreshta dhe sa sht'lla do perm.aje matri"a$ import )ava"util"Scanner' public class tabela { static Scanner input $ neL Scanner( S.stem"in )' static int nrPrreshta' static int nrPsht.lla' static int element' public static void main(String[] args) { int tab[][]' S.stem"out"print (/Sa rreshta doni te shkruaniV /)' nrPrreshta $ input"ne4tAnt()' S.stem"out"print (/Sa sht.lla doni te shkruaniV /)' nrPsht.lla $ input"ne4tAnt()' tab$neL int [nrPrreshta][ nrPsht.lla]' 8or (int rresht$+' rreshtGnrPrreshta' rresht%%) { 8or (int sht.lle$+' sht.lleGnrPsht.lla' sht.lle%%) { S.stem"out"print (/!ep elementin1 /)' element $ input"ne4tAnt()' tab[rresht][sht.lle]$element' 0 0 8or (int rresht$+' rreshtGnrPrreshta' rresht%%) { 8or (int sht.lle$+' sht.lleGnrPsht.lla' sht.lle%%) S.stem"out"print( tab[rresht][sht.lle]%/ /)' S.stem"out"println()' 0 0 0 /*AFISHIMET Sa rreshta $o8i te shkrua8iF " Sa sht(lla $o8i te shkrua8iF & +,

Bep eleme8ti8: Bep eleme8ti8: Bep eleme8ti8: Bep eleme8ti8: Bep eleme8ti8: Bep eleme8ti8: ++6 6!! */

+ + 6 6 ! !

Ushtrim 4( : Te ndertohet nje program qe merr nga tastjera permasat e matri"es dhe elementet e saj$ 3atri"a e d'te merr vlera ne .a/e te form les : elementi korespondent i matri"es se pare @ 3 A) import )ava"util"Scanner' public class Matrica { public static void main(String[] args) { Scanner input$neL Scanner(S.stem"in)' int n' int m' S.stem"out"println(/)epni numrin e rreshtave/)' n$input"ne4tAnt()' S.stem"out"println(/)epni numrin e sht.llave/)' m$input"ne4tAnt()' int matric*[][]' matric*$neL int[n][m]'

8or(int i$+'iGn'i%%) 8or(int )$+')Gm')%%) matric*[i][)]$input"ne4tAnt()' S.stem"out"println(/matrica e pare/)' 8or(int i$+'iGn'i%%) {8or(int )$+')Gm')%%) S.stem"out"print(matric*[i][)]%/St/)' S.stem"out"println()'0 int matric-[][]' matric- $neL int[n][m]' S.stem"out"println(/matrica e d.te/)' 8or(int i$+'iGn'i%%) 8or(int )$+')Gm')%%) matric-[i][)] $ (matric*[i][)]) @%O'

!0

8or(int i$+'iGn'i%%) {8or(int )$+')Gm')%%) S.stem"out"print(matric-[i][)]%/St/)' S.stem"out"println()'0 0 0 /* AFISHIMET jep8i 8umri8 e rreshta:e & jep8i 8umri8 e sht(lla:e " 1"&6+! matri<a e pare 1 " & 6 + ! matri<a e $(te 10 1& 1! 1, "" "+ */ Ushtrimi 4) : Te ndertohet nje program qe nderton nje matri"e katrore, si dhe nje matri"e te d'te qe merr si vlere elementet e d'fish ar te matri"es se pare, k rse elementet siper diagonals kr'esore jane /ero$ import )ava"util"Scanner' import )ava"util"Scanner' public class MatricaHatrore { public static void main(String[] args) { Scanner input$neL Scanner(S.stem"in)' int n' S.stem"out"println(/)epni permaseat e matrices katrore/)' n$input"ne4tAnt()' int matric*[][]' matric*$neL int[n][n]' 8or(int i$+'iGn'i%%) 8or(int )$+')Gn')%%) matric*[i][)]$input"ne4tAnt()' S.stem"out"println(/matrica e pare/)' 8or(int i$+'iGn'i%%) {8or(int )$+')Gn')%%) !1

S.stem"out"print(matric*[i][)]%/St/)' S.stem"out"println()'0 int matric-[][]' matric- $neL int[n][n]' S.stem"out"println(/matrica e d.te/)' 8or(int i$+'iGn'i%%) 8or(int )$+')Gi')%%) matric-[i][)] $ (matric*[i][)]) -' 8or(int i$+'iGn'i%%) 8or(int )$i')Gn')%%) matric-[i][)] $ +' 8or(int i$+'iGn'i%%) {8or(int )$+')Gn')%%) S.stem"out"print(matric-[i][)]%/St/)' S.stem"out"println()'0 0 0 /*AFISHIMET jep8i permaseat e matri<es katrore & 1"&6+! 8, matri<a e pare 1 " 6 + 8 matri<a e $(te 0 0 8 0 16 1! */ & ! , 0 0 0

Ushtrim 4* : Te ndertohet nje program ne Java qe llogarit maksim met e minim met e rreshtave dhe sht'llave te matri"es se dhene$ import )ava"util"Scanner' public class MatricaMa4Min { public static void main(String[] args) { Scanner input$neL Scanner(S.stem"in)' int n' int m' int min#ma4' !"

S.stem"out"println(/)epni numrin e rreshtave/)' n$input"ne4tAnt()' S.stem"out"println(/)epni numrin e sht.llave/)' m$input"ne4tAnt()' int matric*[][]' matric*$neL int[n][m]' S.stem"out"println(/)epni elementet e matrices/)' 8or(int i$+'iGn'i%%) 8or(int )$+')Gm')%%) matric*[i][)]$input"ne4tAnt()' S.stem"out"println(/matrica e pare/)' 8or(int i$+'iGn'i%%) { 8or(int )$+')Gm')%%) S.stem"out"print(matric*[i][)]%/St/)' S.stem"out"println()' 0 S.stem"out"println(/minimumet per rreshta/)' 8or(int i$+'iGn'i%%) { min$matric*[i][*]' 8or(int )$+')Gm')%%){ i8(minJmatric*[i][)]) min$matric*[i][)]' 0 S.stem"out"println(/rreshti /%i%/ minimumi $ /%min)' 0 S.stem"out"println(/minimumet per sht.lla/)' 8or(int i$+'iGm'i%%) { min$matric*[*][i]' 8or(int )$+')Gn')%%) { i8(minJmatric*[)][i]) min$matric*[)][i]' 0 S.stem"out"println(/sht.lla /%i%/ minimumi $ /%min)' 0 S.stem"out"println(/ma4mumet per rreshta/)' 8or(int i$+'iGn'i%%) { ma4$matric*[i][*]' 8or(int )$+')Gm')%%) { i8(ma4Gmatric*[i][)])

!&

ma4$matric*[i][)]' 0 S.stem"out"println(/rreshti /%i%/ ma4imumet $ /%ma4)' 0 S.stem"out"println(/ma4mumet per sht.lla/)' 8or(int i$+'iGm'i%%) { ma4$matric*[*][i]' 8or(int )$+')Gn')%%) { i8(ma4Gmatric*[)][i]) ma4$matric*[)][i]' 0 S.stem"out"println(/sht.lla /%i%/ ma4mumet $ /%ma4)' 0 0 0 /*AFISHIMET jep8i 8umri8 e rreshta:e & jep8i 8umri8 e sht(lla:e " jep8i eleme8tet e matri<es ,8!"0" matri<a e pare , 8 ! " 0 " mi8imumet per rreshta rreshti 0 mi8imumi = 8 rreshti 1 mi8imumi = " rreshti " mi8imumi = 0 mi8imumet per sht(lla sht(lla 0 mi8imumi = 0 sht(lla 1 mi8imumi = " ma'mumet per rreshta rreshti 0 ma'imumet = , rreshti 1 ma'imumet = ! rreshti " ma'imumet = " ma'mumet per sht(lla sht(lla 0 ma'mumet = , sht(lla 1 ma'mumet = 8 */

!6

Ushtrim 4, : te ndertohet matri"a me n rreshta dhe m sht'lla, dhe matri"at maxBnC per maksim min e rreshtave dhe minBmC per minim min e sht'llave$ import )ava"util"Scanner' public class MatriceVektorMa4 { public static void main(String[] args) { Scanner input$neL Scanner(S.stem"in)' int n' int m' S.stem"out"println(/)epni numrin e rreshtave/)' n$input"ne4tAnt()' S.stem"out"println(/)epni numrin e sht.llave/)' m$input"ne4tAnt()' //kri)imi i matrikes int matric*[][]' matric*$neL int[n][m]' //le4imi i matrices nga tastiera S.stem"out"println(/)epni elementet e matrices/)' 8or(int i$+'iGn'i%%) 8or(int )$+')Gm')%%) matric*[i][)]$input"ne4tAnt()' //a8ishimi i matrices S.stem"out"println(/matrica e pare/)' 8or(int i$+'iGn'i%%) { 8or(int )$+')Gm')%%) S.stem"out"print(matric*[i][)]%/St/)' S.stem"out"println()'0 //g)et)a ma4 per rreshta //dhe vendos)a ne vektor ma4 int ma4[]' ma4 $neL int[n]' 8or(int i$+'iGn'i%%) { ma4[i]$matric*[i][*]' 8or(int )$+')Gm')%%) { i8(ma4[i]Gmatric*[i][)]) ma4[i]$matric*[i][)]' 0 0 //g)et)a e min per sht.llat //dhe vendos)a ne vektorin min int min[]' min$neL int[m]'

!+

8or(int i$+'iGm'i%%) { min[i]$matric*[*][i]' 8or(int )$+')Gn')%%) { i8(min[i]Jmatric*[)][i]) min[i]$matric*[)][i]' 0 0 //a8ishimet e vektoreve min dhe ma4 S.stem"out"println(/vektor ma4mumet per rreshta/)' 8or(int i$+'iGn'i%%) S.stem"out"print(ma4[i]%/St/)' S.stem"out"println()' S.stem"out"println(/vektor minimumet per sht.lla/)' 8or(int i$+'iGm'i%%) S.stem"out"print(min[i]%/St/)' 0 0 /*AFISHIMET jep8i 8umri8 e rreshta:e & jep8i 8umri8 e sht(lla:e " jep8i eleme8tet e matri<es ,8! &1 matri<a e pare , 8 ! & 1 :ektor ma'mumet per rreshta , & :ektor mi8imumet per sht(lla & 1 */

Ushtrim &- : Te ndertohet nje skeme per m.ajtjen e te dhenave ne nje s'stem <ankar$ Te perdoret trashegimia, si dhe te ndr'shoni vendosjen e klasave ne paketa te ndr'shme, dhe me aksesim te ndr'shem te atri. teve te klases ;logari$ 9asti 1 : Glasat @lo;ari= @lo;ariFleksi= @lo;ariMeA1at $he /a8ka 8$o$he8 8e te 8jejte8 pakete# Eleme8tet e klases @lo;ari ja8e te ;jithe publike# Te ;jithe eleme8tet aksesohe8 8;a te ;jitha klasat# Go$i 8uk permba8 ;abime#

!!

class Mlogari{ public String emerPklienti' public long IrMlog' public long sasia' public char Valuta' 0 class MlogariRleksi e4tends Mlogari{ public 8loat interesi' 0 class MlogariMeA8at e4tends Mlogari{ public 8loat interes' public int a8atPnePmua)' 0 public class 7anka { public static void main(String[] args) { Mlogari l*$neL Mlogari()' l*"emerPklienti$/An8ormatika sh"a/' l*"IrMlog$ -&@&(2(@' l*"sasia$@++++' l*"Valuta$Y]Y' MlogariRleksi l8$neL MlogariRleksi()' l8"emerPklienti$/Zuri sh"a/' l8"IrMlog$ -@@(&2ON' l8"sasia$N++++' l8"Valuta$Y]Y' l8"interesi$(8loat) +"&' MlogariMeA8at la$ neL MlogariMeA8at()' la"emerPklienti$/Hlasa sh"a/' la"IrMlog$ &@((&2&BN' la"sasia$@+++' la"Valuta$Y]Y' la"interes$(8loat) @"&' la"a8atPnePmua)$2' S.stem"out"println(/Miresevini ne banken toneSnSn/)' S.stem"out"println(/Emri i klientit eshteSt/%l*"emerPklienti)' S.stem"out"println(/Ir i llogarise eshteSt/%l*"IrMlog)' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%l*"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%l*"Valuta%/SnSn/)'

S.stem"out"println(/Emri i klientit per llog 8le4i eshteSt/%l8"emerPklienti)' S.stem"out"println(/Ir i llogarise eshteSt/%l8"IrMlog)' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%l*"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%l8"Valuta)' S.stem"out"println(/Aneteresi per llog 8leksi eshteStSt/%l8"interesi%/6SnSn/)' S.stem"out"println(/Emri i klientit per llog me a8at te g)ate eshteSt/%la"emerPklienti)' S.stem"out"println(/Ir i llogarise eshteSt/%la"IrMlog)' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%la"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%la"Valuta)' S.stem"out"println(/Aneteresi per llog me a8at eshteSt/%la"interes%/6/)' S.stem"out"println(/A8ati mu)or per llog me a8at eshteSt/%la"a8atPnePmua)%/ mua)/)' S.stem"out"print8(/SnSnRaleminderit Fe 5g)idhet banken tone;/)' 0 0 9asti 2 : Glasat @lo;ari= @lo;ariFleksi= @lo;ariMeA1at $he /a8ka 8$o$he8 8e te 8jejte8 pakete# Eleme8tet sasia $he :aluta te klases @lo;ari ja8e me rre;ull aksesimi private# Eleme8tet sasia $he :aluta 8uk aksesohe8 8e klasat e tjera= :e< 8e klase8 @lo;ari# Go$i $o permbaje ;abime 8e rreshtat e meposhtem# l*"sasia$@++++' l*"Valuta$Y]Y' l8"sasia$N++++' l8"Valuta$Y]Y' la"sasia$@+++' la"Valuta$Y]Y' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%l*"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%l*"Valuta%/SnSn/)' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%l*"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%l8"Valuta)' S.stem"out"println(/Sasia e parave te derdhura eshteSt/%la"sasia)' S.stem"out"println(/Mlo)i i valutes eshteSt/%la"Valuta)' Gu$o ku eshte te8tuar aksesimi 8e klasa te tjera per keto eleme8te= merret ;abim 9e 1usha 8uk shikohet 4is 8ot :isible5#

!8

9asti 3 : Glasat @lo;ari= @lo;ariFleksi= @lo;ariMeA1at $he /a8ka 8$o$he8 8e te 8jejte8 pakete# Eleme8tet sasia $he :aluta te klases @lo;ari ja8e me rre;ull aksesimi package aksess, pra aksesim bre8$a paketes# Te ;jithe eleme8tet aksesohe8 8;a te ;jitha klasat# Go$i 8uk permba8 ;abime# 9asti 4 : Glasat @lo;ari 8$o$het 8e te pakete8 1# Glasat @lo;ariFleksi= @lo;ariMeA1at $he /a8ka 8$o$he8 8e pakete8 " Eleme8tet sasia $he :aluta te klases @lo;ari ja8e me rre;ull aksesimi protected, pra aksesim bre8$a paketes PSE aksesim bre8$a trashe;imise 48;a klasat e $eri:uara5 # Te ;jithe eleme8tet aksesohe8 nga klasat e derivuara#Ara klasat @lo;ariFleksi= @lo;ariMeA1at mu8$e8 te aksesoj8e eleme8tet prote<te$ te klases ba)e= e$he pse kjo e 1u8$it eshte 8e pakete tjeter# C9s te8tojme te aksesojme eleme8tet sasia e :aluta= 9e ja8e prote<te$= 8;a klasa /a8ke= $o marrim ;abime 8e ko$# Gjo sepse= klasa /a8ka 8e kete rast 8uk 8$o$het as 8e te 8jete8 pakete $he as 8e trashe;imi me klase8 @lo;ari= 9e permba8 atributet prote<te$# ?shtrim +1 : Te 8$ertohe8 klasa Aktor= Film $he Aro$uksio8= ku 8je Film ka si <ast aktoresh 8je tabele me objekte Aktore# public class Aktor { String emri' char g)inia' String ditelin)a' boolean cmimoscar' 0 public class Rilm { String titulli' int vitireal' String reg)i5or' //Aktor[] cast${neL Aktor()# neL AHtor()0' Aktor[] cast$neL Aktor[-]' public Rilm(){ 8or (int i$+'iG-'i%%) cast[i]$neL Aktor() ' 0 0 public class 3roduksion { public static void main(String[] args) { Rilm 8$neL Rilm()' Rilm e$neL Rilm()' 8"titulli$/mr": mrs" Smith/' 8"vitireal$-++N' 8"reg)i5or$/doug liman/' !,

8"cast[+]"emri$/brad pitt/' 8"cast[+]"g)inia$YmY' 8"cast[+]"ditelin)a$/*B2*/' 8"cast[+]"cmimoscar$8alse' 8"cast[*]"emri$/angelina )olie/' 8"cast[*]"g)inia$Y8Y' 8"cast[*]"ditelin)a$/*B2N/' 8"cast[*]"cmimoscar$8alse' e"titulli$/A am number 8our/' e"vitireal$-+**' e"reg)i5or$/chris bender/' e"cast[+]"emri$/ale4 pett.8er/' e"cast[+]"g)inia$YmY' e"cast[+]"ditelin)a$/*BNB/' e"cast[+]"cmimoscar$8alse' e"cast[*]"emri$/teresa palmer/' e"cast[*]"g)inia$Y8Y' e"cast[*]"ditelin)a$/*BN+/' e"cast[*]"cmimoscar$8alse' S.stem"out"println(/titulli i 8ilmit /%8"titulli)' S.stem"out"println(/viti i prollimit /%8"vitireal)' S.stem"out"println(/reg)isori /%8"reg)i5or)' S.stem"out"println(/- nder aktoret )ane /)' S.stem"out"println(8"cast[+]"emri)' S.stem"out"println(/g)inia /%8"cast[+]"g)inia)' S.stem"out"println(/ditelin)a /%8"cast[+]"ditelin)a)' S.stem"out"println(/ka marr cmim oscar /%8"cast[+]"cmimoscar)' S.stem"out"println(/Sn/%8"cast[*]"emri)' S.stem"out"println(/g)inia /%8"cast[*]"g)inia)' S.stem"out"println(/ditelin)a /%8"cast[*]"ditelin)a)' S.stem"out"println(/ka marr cmimi oscar /%8"cast[*]"cmimoscar)' S.stem"out"println(/titulli i 8ilmit /%e"titulli)' S.stem"out"println(/viti i prollimit /%e"vitireal)' S.stem"out"println(/reg)isori /%e"reg)i5or)' S.stem"out"println(/- nder aktoret )ane /)' S.stem"out"println(e"cast[+]"emri)' S.stem"out"println(/g)inia /%e"cast[+]"g)inia)' S.stem"out"println(/ditelin)a /%e"cast[+]"ditelin)a)' S.stem"out"println(/ka marr cmim oscar /%e"cast[+]"cmimoscar)' S.stem"out"println(/Sn/%e"cast[*]"emri)' S.stem"out"println(/g)inia /%e"cast[*]"g)inia)' S.stem"out"println(/ditelin)a /%e"cast[*]"ditelin)a)' S.stem"out"println(/ka marr cmimi oscar /%e"cast[*]"cmimoscar)' 0 0

/*AFISHIMET titulli i 1ilmit mr#0 mrs# Smith :iti i prollimit "008 re;jisori $ou; lima8 " 8$er aktoret ja8e bra$ pitt ;ji8ia m $iteli8ja 1,!1 ka marr <mim os<ar 1alse a8;eli8a jolie ;ji8ia 1 $iteli8ja 1,!8 ka marr <mimi os<ar 1alse titulli i 1ilmit I am 8umber 1our :iti i prollimit "011 re;jisori <hris be8$er " 8$er aktoret ja8e ale' pett(1er ;ji8ia m $iteli8ja 1,8, ka marr <mim os<ar 1alse teresa palmer ;ji8ia 1 $iteli8ja 1,80 ka marr <mimi os<ar 1alse */

Vous aimerez peut-être aussi