Long Quiz #1 - Objects NAME - Score
Long Quiz #1 - Objects NAME - Score
[40 m r!s" A#s$er ALL %&es'(o#s (# ')(s sec'(o#* A1. State an appropriate method for each of the following situations below: a) To convert strings to upper case. b) To covert strings to lower case. c) To convert strings to integer. d) To convert strings to double. e) To calculate the si e of the string. f) To change the color of a te!t in an applet. g) To evaluate the contents of two string ob"ects to determine their e#uivalence. h) To displa$ a string in an applet program. + 'oU,,erC se-+ .+ 'oLo$erC se-+ c+ I#'e/er*, rseI#'-+ 0+ 1o&.2e*, rse1o&.2e-+ e+ Le#/')-+ 3+ Se'Co2or-+ /+ e%& 2s-+ )+ 0r $S'r(#/-+ A%. &or the following data t$pes below' give an appropriate e!ample for each of them.[(] a) int b) boolean [1" [1" [1" [1" [1" [1" [1" [1" [8]
score:_________
)age 1
c) char d) float e) b$te f) long + 40456[ cce,' #7 re so# .2e e8 m,2e" [1" .+ 'r&e93 2se [1" c+ :A; [ cce,' #7 re so# .2e e8 m,2e" e+ 11=[ cce,' #7 re so# .2e e8 m,2e" [1" [1" [1" 0+ <*4=3[ cce,' #7 re so# .2e e8 m,2e" [1" 3+ 14>=<66?[ cce,' #7 re so# .2e e8 m,2e" A*. )ic+ a correct statement or phrase to complete the sentence. a) -ava programming can support i) ii) iii) iv) onl$ one dimension arra$. less than two dimension arra$. more than two dimension arra$. .nl$ two dimension arra$. [1,]
b) /iven the following String product0 1Shampoo23 int si e 0 product.length4)3 5hat is the value of variable si e6 i) ii) iii) iv) 7 8 9 11
c) 5hich of the following is found in the -ava :evelopment ;it6 i) ii) te!t editor notepad
)age %
iii) iv)
d) 5hich of the following is not a relational operator in -ava programming6 i) ii) iii) iv) 0 00 <0 =
e) 5hich of the following is a logical operator in -ava programming6 i) ii) iii) iv) > ?? @ AA
f) 5hich of the following declaration is correct6 i) ii) iii) iv) Boolean switch 0 true3 boolean switch 0 true3 boolean Switch 0 false3 Boolean Switch 0 &ACSD3
g) 5hich of the following declaration of an arra$ is correct6 i) ii) iii) iv) int number[] 0 new int[*]3 float [] number 0 E%.*' 7.F' *.9 G3 int number[]3 int[] number 0 new int[F]3
h) 5hich of the following statement will displa$ this message 1hip hip hurra$2 three times on the screen6 i) for 4int count013count=0*3 HHcount) S$stem.out.println41hip hip hurra$2)3
)age *
for 4int count013count<0*3 HHcount) S$stem.out.println41hip hip hurra$2)3 for 4int count013count=*3 HHcount) S$stem.out.println41hip hip hurra$2)3 for 4int count013count0*3 HHcount) S$stem.out.println41hip hip hurra$2)3
i) 5hat will the following code displa$6 int no0,3 int total0,3 do E total H0 no3 HH no3 Gwhile 4no I0 7)3 S$stem.out.println41The total is2 H total)3 i) ii) iii) iv) ( 1, * 8
") 5hich of the following declaration of a method is correct6 i) ii) iii) iv) + ((( .+ (( c+ ((( 0+ ( e+ (@ 3+ ((( [1" [1" [1" [1" [1" [1" public void sum4 int A' B)3 public void sum4int A3 int B) public void sum4 float A' int B) public void sum4A'B)
)age F
/+ (@ [1" )+ ( [1" (+ (( [1" A+ ((( [1" AF. &ill in the blan+s with an appropriate phrase or word. a) Button and Te!t&ield are e!amples of JJJJJJJJJJJJJJ classes. b) JJJJJJJJJJ allows the use of the same method name to indicate different implementation. c) The parent class is also +nown as the JJJJJJJJJ. d) A series of JJJJJJJJJJ ma+es an animation. e) A JJJJJJJJJJJJJ is onl$ accessible within the method where it is declared. f) The JJJJJJJJJJmethod is used to draw a straight line between an$ two points on the screen. g) A JJJJJJJJJJ is used to convert a source program written in a programming language to an ob"ect code. h) The JJJJJJJJJJJ method is used for drawing strings' geometric figures and images. i) JJJJJJJJJJJJ allows us to specif$ how the classes and methods can be accessed. ") A windows component which enables the user to enter a single line of te!t is a JJJJJJJJJJJJJJ. + com,o#e#' .+ ,o27mor,)(sm c+ s&,erc2 ss + Im /es .+ Loc 2 @ r( .2e c+ 0r $L(#e-+ 0+ 'r #s2 'or e+ , (#'-+ /+ Te8'B(e20 [1" [1" [1" [1" [1" [1" [1" [1" [1" [1,]
)age 7
A7. State the * t$pes of comments used in -ava programming. L(#e comme#' B2oc! comme#' J @ 0oc comme#' A(. 5rite a -ava statement or a set of -ava statements to accomplish the following which perform the sum the odd integers between 1 and 99 using Bor structure. Assume the integer variables s&m and co&#' have been declared. s&m C 0D s&m FC co&#'D [1" [1" [1" [*] [1" [1" [1" [*]
)age (
Start
:ispla$ menu
Dnter choice
Mhoice 01
no
Mhoice 0%
no
Mhoice 0*
no
invalid option
$es
Add option
$es
:ispla$ option
$es
Correc' &se o3 (#,&'9o&',&' s7m.o2 Correc' &se o3 se2ec'(o# s7m.o2 Correc' &se o3 'erm(# 'or s7m.o2 S)o$s ')e correc' 32o$ o3 0 ' O@er 22 0( /r m correc'
Stop
)age 8
b) Nember access modifiers include the following: private and public. D!plain what is the difference between the two modifiers. A#7 (#s' #ce @ r( .2e or me')o0 0ec2 re0 $(') ')e ccess mo0(3(er ,&.2(c (s ccess(.2e $)ere@er ')e ,ro/r m ) s ccess 'o # o.Aec' o3 ccess(.2e o#27 'o ')e me')o0s o3 ')e c2 ss* c2 ss* [<" [<" I3 0ec2 re0 $(') ccess mo0(3(er ,r(@ 'eH ')e (#s' #ce @ r( .2e or me')o0 (s [F]
c) Binar$ search is one of the methods use to search for a particular record. D!plain the steps how binar$ search is performed. -')e 0 ' e2eme#'s (# ')e 2(s' m&s' .e sor'e0 (# se%&e#ce 3(rs'* -$or!s .7 3(rs'27 (0e#'(37(#/ ')e m(002e e2eme#' o3 ')e 2(s'* -com, res ')e ' r/e' e2eme#' $(') ')e m(002e e2eme#'* -(3 (' (s 3o�H se rc) $(22 e#0* ) 23 o3 ')e 2(s'* -. se0 o# ')(sH ')e 2(s' $(22 / (# .e 0(@(0e0 (#'o ) 23* [1" [1" [1" [1" [1" [1" [1" [8]
-o')er$(seH (' c)ec!s 'o see (3 ')e re%&(re0 0 ' .e2o#/s 'o ')e &,,er ) 23 or 2o$er -(3 (' .e2o#/s 'o ')e &,,er ) 23 ')e# ')e 2o$er ) 23 (s (/#ore0 #0 @(ce @ers * -')e ,rocess (s re,e 'e0 &#'(2 ')e re%&(re0 0 ' (s 3o�* [1" d) 5hen declaring variables' there must be two important components. 5hat are these two components and give three e!amples each of the components mentioned. T$o com,o#e#'s re: -@ r( .2e # me -0 ' '7,e [1" [1" [4" [8]
E/* o3 @ r( .2e # me: - /eH # meH c2 ssco0e -1 m r! 3or e c) s&(' .2e #s$er*
)age 8
E/* o3 0 ' '7,e: -(#'H 32o 'H c) rH .7'eH 2o#/H s)or'H .oo2e #H 0o&.2e* -1 m r! 3or e c) s&(' .2e #s$er* [m 8* 4 m!s" B%. a) Ldentif$ the la$out manager' component or method which will perform the following: [(] i) A window component into which a user can t$pe a single line of te!t data. ii) A builtKin class that holds te!t that can be displa$ed within an applet. iii) A component which is used to displa$ a series of items from which the user ma$ select one or more items. iv) The user re#uires the name entered to be stored in lower case. v) A window component which allows the user to clic+ to trigger a specific action. vi) A la$out manager which allows the programmer to arrange the window components into five areas: north' south' east' west and center. (+ Te8'B(e20 ((+ L .e2 (((+ L(s' (@+ 'oLo$erC se-+ @+ B&''o# [1" [1" @(+ Bor0erL 7o&' [1" [1" [1" [1"
b) 5rite a program in -ava programming using the &or Coop statement that will produce the following output. 1 % * % F ( * ( 9 F 8 1% [1%]
)age 9
1% [1" [1"
1(
C 1D EC4D FF +
3or -. C 1D .EC 4D FF .+ I
[ 1 m! 3or 'o' 227 correc' #s$er" [ $ r0 3&22 m r!s 3or #7 $or! .2e so2&'(o# " c) Dvaluate the following e!pression: i) 8 <0 8 ii) * H 1, > ( iii) ( H 1, O %% iv) %7 ? 1% v) %7 I0 1,, ? F (+ Tr&e ((+ =4 (((+ O= (@+ < @+ 3 2se [7]
)age 1,
d) 5rite an applet program that displa$s the following te!t 15elcome To M$ber Mampus2 using the drawString4) method. (m,or' A @ * ,,2e'*A,,2e'D [1" (m,or' A @ * $'*Gr ,)(csD [1" ,&.2(c c2 ss .<0 e8'e#0s A,,2e' I ,&.2(c @o(0 , (#'-Gr ,)(cs /+ I /*0r $s'r(#/-KGe2come To C7.er C m,&sMH<>H <>+D N N B*. a) Sometimes an image flic+ers on an applet. D!plain briefl$ what causes this flic+ering and how it can be stopped. B2(c!er(#/ o3 (m /es (s c &se0 .7 ')e re, (#'-+ me')o0* [1" Pe, (#'-+ me')o0 c 22s ')e &,0 'e-+ me')o0 'o c2e r ')e scree#* [1" T)e# (' c 22s ')e , (#'-+ me')o0* c # ,re@e#' 32(c!er(#/: ,&.2(c @o(0 &,0 'e-Gr ,)(cs scr+ [1" I , (#'-scr+D N [1" [1" [1" [1" B7 o@err(0(#/ ')e &,0 'e-+ me')o0 $(') ')e 3o22o$(#/ co0e [8] [1" [1" [1" [1" [1" [8]
b) To draw a rectangle with rounded edges' the drawPoundPect4) method is used' for e!ample' drawPoundPect41,' 1,' *,' *,' 7' 7). State what the arguments represent in the brac+ets. [(]
)age 11
I' re,rese#'s: -co2&m# -ro$ -$(0') -)e(/)' [1" [1" [1" [1" [1"
-)e(/)' o3 ')e ro�e0 rc [1" c) The four +e$ methods of the Applet class includes init4)' start4)' stop4) and destro$4) methods. Briefl$ e!plain when each of these methods is used and its purpose. (#('-+ me')o0 K K T)e me')o0 (s c 22e0 o#ce $)e# # ,,2e' (s 2o 0e0 3or e8ec&'(o#* [1" I' ,er3orms (#('( 2(Q '(o# o3 # ,,2e' s&c) s (#('( 2(s '(o# o3 (#s' #ce @ r( .2es #0 GUI com,o#e#'s o3 ')e ,,2e'* s' r'-+ me')o0 K T)e me')o0 (s c 22e0 3'er ')e (#('-+ me')o0 com,2e'es e8ec&'(o# #0 e@er7 '(me ')e &ser o3 ')e .ro$ser re'&r#s 'o ')e RTML , /e o# $)(c) ')e ,,2e' res(0es* K [1" I' ,er3orms ' s!s ') ' m&s' .e com,2e'e0 $)e# ')e ,,2e' (s 2o 0e0 3or ')e 3(rs' '(me (#'o ')e .ro$ser #0 ') ' m&s' .e ,er3orme0 e@er7 '(me ')e RTML , /e o# $)(c) ')e ,,2e' res(0es (s re@(s('e0* [1" [1" [8]
s'o,-+ me')o0 K T)e me')o0 (s c 22e0 $)e# # ,,2e' s)o&20 s'o, e8ec&'(o#H #orm 227 $)e# ')e &ser o3 ')e .ro$ser 2e @es ')e RTML , /e o# $)(c) ')e ,,2e' s(0es* [1"
)age 1%
I' ,er3orms ' s!s ') ' re re%&(re0 'o s&s,e#0 ')e ,,2e';s e8ec&'(o#*[1"
0es'ro7-+ me')o0 K K T)e me')o0 (s c 22e0 $)e# ')e ,,2e' (s .e(#/ remo@e0 3rom memor7H #orm 227 $)e# ')e &ser o3 ')e .ro$ser e8('s ')e .ro$s(#/ sess(o#* [1" I' ,er3orms ' s!s ') ' re re%&(re0 'o 0es'ro7 reso&rces 22oc 'e0 'o ')e ,,2e'* [1"
d) Ldentif$ and correct the errors in each of the following statements: i) if 4 c = 8 )3 g.drawString41c is less than 82'%7' %7)3 ii) if 4 c 0< 8 ) g.drawString41c is e#ual to or greater than 82'%7' %7)3 (+ error: sem(co2o# ,2 ce0 3'er ')e r(/)' , re#')es(s o3 ')e co#0('(o# (# ')e (3 s' 'eme#'* correc'(o#: remo@e ')e sem(co2o# 3'er ')e r(/)' , re#')es(s* ((+ error: ')e re2 '(o# 2 o,er 'or :CS;* correc'(o#: c) #/e CS 'o SC* e) There are 7 t$pes of operators. Qame the 7 t$pes of operators. r(')me'(c 2o/(c 2 ss(/#me#' com, r(so# [1" [1" [1" [1" [1" [1" [1" [1" [1"
[F]
[7]
(#creme#'90ecreme#'
)age 1*