+ All Categories
Home > Documents > Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A...

Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A...

Date post: 30-Jun-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
33
Lab5 Wooseok Kim [email protected] www.cs.albany.edu/~wooseok/201
Transcript
Page 1: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Lab5Wooseok Kim

[email protected]

www.cs.albany.edu/~wooseok/201

Page 2: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question Answer Points

1 A 8

2 A 8

3 E 8

4 D 8

5 20• 5for class• 10for main• 5points for

output

6 A 8

7 B 8

8 0 15

9 D 8

10 B 8

Page 3: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question Answer Points

11 A 8

12 D 8

13 A 8

14 A 8

15 E 8

16 B 8

17 A 8

18 C 8

19 nextInt( 19)+22 20

• 10for21• 10for20

20 25

• 10forcorrectsubstring

• 10forcorrect calltolength()

• 5forcorrectoutput

Page 4: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question1

ThelineofJavacode"//System.out.println("Hello");"will

• A)donothing• B)cause”Hello”tobeoutupt• C)cause asyntax error• D)cause“(Hello)”tobeoutput• E)thereisnowaytoknowwithoutexecutingthislineofcode

Page 5: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question2

AuniqueaspectofJavathatallowscodecompiledononemachinetobeexecutedonamachineofadifferenthardwareplatformisJava’s• A)bytecodes• B)syntax• C)useofobjects• D)useofexceptionhandling• E)alloftheabove

Page 6: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question2

Page 7: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question3

Whichcharacterbelowisnotallowedinanidentifier?• A)$• B)_• C)0(zero)• D)q• E)^

Page 8: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question4

Anerrorinaprogramthatresultsintheprogramoutputting$100insteadofthecorrectanswer,$250 is• A)Aprogrammererror• B)Asyntaxerror• C)Arun-timeerror• D)Alogical error• E)Asnafu

Page 9: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question4

• B)Asyntaxerror• Compile Error

• C)Arun-timeerror• 12/0=?

• D)Alogicalerror• IncorrectAnswer

Page 10: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question5

• WriteaJavaprogramthatwilldisplayontwoseparatelinesyournameandyourmajor.

Page 11: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question5(GradingGuideline)

• 5pointsforhavingthekeywordclassandareasonableclassnameintherightplace• 2pointseachforstatic,void,main(),String[],args• 5pointsforoutput– thenameandthemajor

Page 12: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question6

FollowingJavanamingconvention,whichofthefollowingwouldbethebestnameforaclassaboutstorecustomers?• A)StoreCustomer• B)StoreCustomer• C)storeCustomer• D)STORE_CUSTOMER• E)Store-Customer

Page 13: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question7

Ifxisanint andyisadouble,allofthefollowingarelegalexceptwhichassignmentstatement?• A)y=(double)x;• B)x=y;• C)y=x;• D)x=(int)y;• E)alloftheabovearelegal

Page 14: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question7

Ifxisanint andyisafloat,allofthefollowingarelegalexceptwhichassignmentstatement?• A)y=(double)x;• B)x=y;

• int <double• C)y=(float)x;• D)x=(int)y;• E)alloftheabovearelegal

Page 15: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question8

• Whatwillbetheresultofainthefollowingassignmentstatement?Assumeb=8andc=10.

Page 16: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question8(GradingGuideline)

• 15pionts• Upto10pointspartical creditiftheyhavesomecorrectwork

Page 17: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question9

WhichlibrarypackagewouldyouimporttouseNumberFormat andDecimalFormat?• A)java.beans• B)java.io• C)java.lang• D)java.text• E)java.util

Page 18: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question10

QuestionNineAndTen computes• A)Thecorrectaverageofx,yandzasadouble• B)Thecorrectaverageofx,yandzasanint• C)Theaverageofx,y,andzasadouble,buttheresultmaynotbeaccurate• D)Thesumofx,yandz• E)Theremainderofthesumofx,yandzdividedby3

Page 19: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question11

Whatisoutputifx=0,y=1andz=1?• A)0• B)0.0• C)0.66666666• D)0.66666667• E)0.67

Page 20: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question12

Inordertocreateaconstant,youwouldusewhichofthefollowingJavareservedwords?• A)private• B)static

• https://www.javatpoint.com/static-keyword-in-java

• C)int• D)final• E)class

Page 21: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question13

InJava,avariablemaycontain• A)aprimitive valueoranobjectreference• B)apackage• C)amethod• D)aclass• E)anyoftheabove

Page 22: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question14

Mistyping“println”as“printn”willresultin• A)Asyntaxerror• B)Aruntimeerror• C)alogicalerror• D)noerroratall• E)Convertingthestatementintoacomment

Page 23: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question15

Whatisthefunctionofthedotoperator?• A)Itservestoseparatetheintegerportionfromthefractionalportionofafloatingpointnumber• B)Itallowsonetoaccessthedatawithinanobjectwhengivenareferencetotheobject• C)Itallowsonetoinvokeamethodwithinanobjectwhengivenareferencetotheobject• D)Itisusedtoterminatecommands(muchasaperiodterminatesasentenceinEnglish)• E)BothBandCarecorrect

Page 24: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •
Page 25: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question16

InJava,”instantiation”means• A)noticingthefirsttimesomethingisused• B)creatinganewobjectoftheclass• C)creatinganewaliastoanexistingobject• D)launchingamethod• E)noneoftheabove

Page 26: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •
Page 27: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question17

An“alias”when• A)Twodifferentreferencevariablesrefertothesamephysicalobject• B)Twodifferentnumericvariablesrefertothesamephysicalobject• C)Twodifferentnumericvariablescontainidenticalvalues• D)Twovariableshavethesamenames• E)noneoftheabove

Page 28: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •
Page 29: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question18.

AnAPIis• A)anAbstractProgrammingInterface• B)anApplicationProgrammer’sInterface• C)anApplication ProgrammingInterface• D)anAbstractProgrammer’sInterface• E)anAbsoluteProgrammingInterface

Page 30: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question19.

• Completethefollowingassignmentstatementthatgeneratesarandomnumberbetween22(inclusive)to40(inclusive).

Page 31: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question20

• GivenaStringobject“ComputerScience”whoseobjectreferenceismajor,usetheobjectreferencetoinvokeproperStringinstancemethodstocreateasubstringcontaining“Sci”, calculatethelengthofthesubstring,displayboththesubstringanditslengthonthesameline.

Stringmajor=newString(“ComputerScience”);StringsubStringOfMajor;//Storethesubstringofmajorint lengthOfMajor;//Storethelengthofthesubstring

Page 32: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question20

Page 33: Lab5 - Albany › ~wooseok › 201 › slide › Lab5-1.pdfQuestion Answer Points 11 A 8 12 D 8 13 A 8 14 A 8 15 E 8 16 B 8 17 A 8 18 C 8 19 nextInt( 19 ) + 22 20 • 10 for 21 •

Question20(GradingGuideline)

25points• 10forcorrectsubstringcall

• takeoff5points ifthenumbersarenotcorrect

• 10forcorrectcalltolength()• 5forcorrectoutput:thesubstringandit’slengthmustbeonthesameline


Recommended