Midterm Exam - Spring 2011

Midterm Exam - Spring 2011 - 30"" «ma...

Info iconThis preview shows pages 1–24. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 18
Background image of page 19

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 20
Background image of page 21

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 22
Background image of page 23

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 24
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 30"" «ma Answer: 6 r .4 C82133 Midterm Spring 2011 Program Structure Multiple Choice Questions: 1) A program. __ diagram helps us visualize the contents of and relationships among the classes of a a) class and object b) UML c) object-oriented d) public 6) private Answer: 5 2) Which of the following object-oriented principles refers to the fact that an object should have its data guarded from inappropriate access? a) encapsulation b) inheritance c) polymorphism d) instance variables e) methods Answer M 3) Which of the following types of methods do not have any return type (not even a void return type)? a) methods declared as static b) methods declared as public c) methods declared as private d) constructors c) all of the above have return types \x 4) A variable is shared among all instances of a class. a) static b) f inal c) public d) private e) none of the above i. x Answer C 5) parameters are the values that are used when calling a method. a) formal b) actual c) useful a) informal 6) none of the above Answer: V J 6) The reference always refers to the currently executing object. a) null b) static c) final d) actual 6) this Answer: 6 7) A method that has multiple definitions is an method. a) overloaded b) overridden c) overlooked d) overclocked e) none of the above Answer: m True/False Questions: 1) A variable can always be referenced anywhere in a program. Answer: I: 2) An object can be thought of as a blueprint for a set of classes. Answer: 3) A return statement is not required at the end of every method. T Answer: ‘7' 4) When an object is passed to a method, the actual and formal parameters become aliases. Answer: 7-»— 5) There are times when it is appropriate to return data from a method of a type that is inconsistent with the return type specified in the method header. Answer: F— Short Answer Questions: J“ 1) Explain the difference between actual parameters and formal parameters. 5 4 t/ farflMelLff flr’? Wfflbfig r4: fiif‘fli w Ila ill/tim/ Matias/k“ [defame lid} sa/ met/H204 {ES £~ Answer: 2) Write a method called maxOf Three that accepts three integer parameters and returns the largest of the three. Answer: t _ E x x. Path; int Nehsrshnf‘ 0/21?! in?” rm , if)?" fil’mfi‘} i he" largest-“v ofiéxv ‘ 7M hm > Gite £73; two > three} {lafgfii it five,” an? :‘1c(‘ti4ree 7 We 331g rhea? > ‘7"W’O) f/ar7€J~f z: rah {a b’fi“ $J’ Arrays Multiple Choice Questions: 1) Which of the following statements best describes this line of code? int numbers = new int[SO]; a) this is the declaration and initialization of an array that holds 50 integers b) this is a declaration and initialization of an array that holds 49 integers c) this is a declaration and initialization of an integer array that will hold integers smaller than 50 d) this is a declaration and initialization of an integer array that will hold integers smaller than 49 e) none of the above is correct Answerzg 2) Which of the following array declarations are invalid? ,a’fintl] grades = new int[5]; b) int grades = new int[5]; /e)int grades = { 91, 83, 42, 100, 77 }; )d)’ all of the above are valid g)’ none of the above are valid Answer: A 3) Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not correctly process each element in the array. a) for(int i = O; i < names.length; i++) b) for(String name : names) c) for (int i = 0; i < names . length(); i++) d) none of these will correctly process each element 6) all of these will correctly process each element Answer: True/False Questions: 1) In Java, array indexes begin at 0 and end at one less than the length of the array. Answer: 7"" 2) There is only one way to declare and initialized an array in Java. Answer: I F a an. mm itw ways) 3) An array declared as an int can contain elements of different primitive types. Answer: F 4) The foreach loop can be used to process each element of an array. — Answer: a» F 1’ u 5) It is possible to store 11 elements in an array that is declared in the following way. int[l array = new int[lo]; Answer F Short Answer Questions: 1) Explain how arrays are passed to methods as parameters. :4 u 3 [7&1 (It‘ll u ‘ Answer (4 3M3 jag, a} “Hit. "W" P a ‘\ /-\ 2) Write a loop that cycles through an array of String objects called names and prints them out, one per line. Your loop should not use a foreach loop. 1%! (/44 i=0J'1/<‘ [la/V765, /&/13 Ha ()[X'I-i') Answer: é $515M. aaf./or/4f/n (mama [521,32 3) Write a method that accepts an array of integers as a parameter and returns the sum of all of the integers in the may‘ - VAL/,2 inf {MN All [INT] “leaa‘Q Answer: g I'A+ {M 3 0 'fby’ (0%} u: 3 D; I‘ 4 ill/544611“ . '45,??AC); i 3 re M 5am; .3 4) Write a method called average that accepts an array of floating point numbers and returns their average. flak/1'6 ail/era ,a. AVA!) (IS) % averaWnaWSJ' (I); , 50m 2 0/ Q “7} £910”; 1.90)” I“ "UN’LVS' lfieiiieil; Sum +3 I'll/M510“ Ell]; Answer: 3 gum 7‘ 3' “Vmg’e‘” {'71, it mvaagaDF/‘H/ : SVM/evemfie/VI' f2+v M av effigy}; 5) Write a methodgiat takes in an arbitrary number of String objects, and then prints out all of them that have over 10 characters. PM 5/12 \wi‘d Prfinlflfl‘ngs (5M5 W; M, w “mas 5 579539 lmx =_ “44am: aeaaa “j H: (we. cam/me 73an) > by a fi/dtm bah/mini 1/" (0%»);5 (570(nw44‘u, Lora/{Ar}: i; [Mk—5 7 2?. g‘v/S‘limmuh iridium (mp/rid); .3 Answer: Inheritance Multiple Choice Questions: 1) The process of inheritance should establish a(n) relationship. a) is-a b) has-a 0) static d) not-a e) none of the above Answer: a 2) The original class that is used to derive a new class using inheritance is called a) a superclass b) a parent class c) a base class d) all of the above 6) neither a, b, nor c > Answer: 4 3) The derived class created using inheritace is called a) a child class b) a superclass c) a parent class d) all of the above 6) neither a, b, nor c Answer a 4) In order for derived classed to have access to encapsulated data members and methods of superclasses, the data members and methods should be declared using the modifier. a) private b) public c) protected d) final e) static Answer: C 5) The special reference is used to refer to the parent class in a child class. a) this b) super 0) null (1) parent , e) none of the above Answer b 6) When a variable is declared in a subclass has the same name as a variable declared in a superclass, it is called a variable. a) final b) shadow c) static d) dead e) this is not allowed in Java Answer: 7) A class represents a generic concept in a class hierarchy. a) super b) abstract c) interface (1) shadow e) generic Answer: E 8) A class declared as final a) cannot be changed. b) cannot have subclasses. 23/ cannot have superclasses. Mas several abstract methods. p)’ cannot be used in a program. Answer: 4; Short Answer Questions: 1) Explain why inheritance is useful. Answer: It" allows e fragramma is reusv “A? by 56W")? Corie C0MN‘3QR 7’7, “If; [gram :4}: fig. Paaram 2) Compare and contrast the private Visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy? ‘ Answer: lab/(60h Acclarw! ag szVVaic N/ arc enrflfiseleéfié‘g Jami {Friva’l‘e Objtmb (amid lye, agwf by :4 die/fl. (Jaw, waif/1:3 lam’zfiwg obit-car (en 12¢, 3) Suppose we create a subclass from a class that has a method called someMethod. If we override someMethod in the subclass, is it possible to access the superclass's version of someMethod? If so, how? AnSWer: y55,_ “9&6 u rim/091’; mo‘Hw/ n 4) Can a class be a parent of more than one subclass? Can a class be a child of more than one parent? Explain. Answer: Yas, a Permit dag; mp AM (vim/fsz 4.7;! Jerri, Ya, a 6L5” aim (an «ma/him? law? classgzma/a) Animajggj {I ., 5) Explain the relevance of the Object class to the Java programming langggg gfii?’vu Wifiy‘ § Alma Answer: 7‘” «Db/La; dag; gimp”, é, MINUL’ auhjk’g 4’10, misfivl‘éj Ii3 5: gamed 6) What is an abstract class, and why might it be useful in an inheritance hierarchy? [1 a k £3 I # $ (a gym Answer: If is our god/0 £7 645 // £5253}? (fit/65.}; a AVA 1" “a r ‘ ’ 5 AA) gin“ va/McJ wAan neat/54" 1+ I“; “Sefh/ A, (5.!!! jMSVL able/n Vklwfi. 4/570} if” Mat/0.? 556’! /b W” ”‘ kararalxv V sin,an 7) Explain how a subclass can can access its parent classes private instance variables and methods. "v . Answer: 1+ Cam/’04 ax“; fix/mic. VA fiablé .s, May m 415% la; cimfiég ‘21» gratuity! VF 9) Which of the following key words indicates a new class is being derived from an existing class? a) super b) final c) extends d) inherits e) expands Answer: C 10) To invoke a parents constructor in a subclass, we use the method. a) abstract b) construct c) parent d) super e) extends Answer:¢l True/False Questions: 1) Methods and variables declared as private in a parent class cannot be accessed in a child class. Answer: T 2) Once a method is overridden in a subclass, the original version can'never be referenced from within the subclass. Amwer:F We? Can ufie ~9M/flf) 3) Java supports multiple inheritance. Answer: 7' 4) In Java subclass can only extend one parent class. Answer: F 5) A child class is allowed to define a method with the same name and parameter list as a method in the parent class. Answer: T 8) A programmer tries to create a subclass of String called MyString. When the programmer compiles her new class, the compiler produces the following message: Mystring.java:l: cannot inherit from final java.lang.String public class Mystring extends String { A 1 error Explain the cause of this error. Answer: wag: Jeaiawmt/ «Fjflfll and [flfwgra‘i fiat}; s s‘ 5 J . u 9) Draw a hierarcly of Anima . The hierarchy should include the following entities: Animfi, Reptile, Mammal, Belgr, Human: Iguana, and Do phin. g A]? {I Mrfi Answer: A a» / Fifi “rag”? / fa ngné‘ [Saar M/Mfi V‘ 10) Consider an software system that will implement the following classes: Student, Professor, StaffMember, ContractWorker. List some common attributes of these classes. What would be a good abstract class from which these classes may be extended via inheritance? (gramme: gfiffiéfl discus i) I I g ( W EVAQVFtSEiEI 4 60196! Q- '5ng W0 be UAFV‘éx‘éifi gleam; Answer: Inheritance/Polymorphism Multiple Choice Questions: 1) A polymorphic reference is one that can refer to type(s) of object(s). a) exactly one b) zero c) multiple (1) abstract e) static Answer: 0 2) The commitment to execute certain code to carry out a method invocation is referred to as a) execution b) binding (3) polymorphism d) inheritance e) none of the above \r,, Answer 3) In Java, polymorphic method binding occurs a) at run time b) at compile time 0) never (1) when a programmer writes the code e) during the testing phase of software development Answer: a 4) Late binding is ' than a) more efficient, compile-time binding b) less efficient, compile—time binding c) more efficient, run—time binding d) less efficient, run-time binding 6) Answer: 5) Suppose that Horse is a subclass of Animal, and neither class is abstract. .Which of the following is an invalid declaration and initialization? A c i . fit M5 Morse h new Horse () ; b) Horse h = new Animal(); Hip/Sf ’fifAnimal a = new Animall); d) Animal a = new Horse(); e) all of the above are valid Answer: l) 6) In Java, a(n) is a collection of constants and abstract methods. a) polymorphic reference b) abstract class c) implementation d) interface e) iterator Answer 65 7) In Java, polymorphic references can be created through the use of and a) inheritance, interfaces b) inheritance, abstract classes c) interfaces, abstract classes d) interfaces, iterators 6) none of the above (1 4., V “"3: Answer: F 2) Let Animal be an interface. Then it is possible to create an object by instantiating the Animal interface. Answer: .ir/ 3) The compareTo method of the Comparable interface returns a boolean value. Answer: F ' 4) The next method of the Iterator interface returns a reference to the next element in a collection and removes it. Answer F 5) A parameter to a method can be polymorphic. Answer: ,— Short Answer Questions: 1) What is polymorphism? N e t / e i A A My Mortals}; 12351’2"“‘““ ’5 we “ii” ‘7‘” Wm h "4‘" f7” SWer: claims. Ftlvwrsiféhism “5“ PDIVM’QV‘FM “jgmfl’fi! *5 “Mg: (a Si U « 2) How does inheritance relate to polymorphism in Java? 3 p \ g l L I’IM‘flomét “$4, i [fioiymoi-[flfiif gram all/«aqudr; Dial L C. 3 fl Answer: fit {\7 LAW W Emma; J a“ ‘ . 9"!!!¥ U W 3) Consider a class hierarchy that includes a class called Vehicle, with subclasses called Car and Airplane. The Vehicle class has a method called getMaxSpeed, which is overridden in the Car class. The getMaXSpeed of the Vehicle class returns 760 mph, while the getMaxSpeed method of the Car class is overridden to return 150 mph. What is the output of the following snippet of code? Explain your answer]; if Va, {6; (3 Vehicle v new Car () ; N, System. out . println (v . getMaXSpeed () + \\ mph/I); CM Answer: 760ml»): (v a Vdiit‘éfie> Answer: a 8) Let Dog be a subclass of Animal, and suppose Animal has a method called speak() that is overridden in the Dog class. Consider the following code. Animal spot = new Dog(); spot.speak() ; ; ifs? rar- Wary, 5:34" 3:” 3"“ Which of the following is true? ,a’f This code will result in a compile-time error. MThis code will result in a run-time error. e) The speak method defined in the Animal class will be called. d) The speak method defined in the Dog class will be called. ’eflhe speak method will not be called at all. as Answer: C 9) The Comparable interface contains which of the following methods? a) isGreaterThan b) isLessThan c) equals d) compareTo e) all of the above Answer: A 10) Let Object a be larger than Object b. What will the following method call return? a. compareTo (b) a) it will return 0 b) it will return a number greater than 0 c) it will return a number less than 0 d) it will return true C) it will return false Answer: 5 True/False Questions: 1) Consider a reference declared in the following manner. Animal a; This reference may only point to an object that created by instantiating the Animal class. 4) Consider the following inheritance hierarchy that is used in a video game. Character / \ Friend Villain / \ / \ WiseMan ShopKeeper Dragon Skeleton l l FlyingDragon Eliteskeleton Which of the following declarations and initializations will not cause a compiler error? 5) What is an interface? Answer‘ 4 (gliw‘liafim $15: (IQ/15711197]? aria! abgf'fag; “(flit “if 6) Are there any differences between extending a class and mplemejng an interface? chg admin/g "5 Ciaifi marl: (2):“me WPMQJSE #6:} 9114 he} aéshari‘ Answer: 7) Describe the compareTo method the circumstances under which it returns different values. at .CQM/QAFCT; if a £5 Kara!“ - a Vain t3me 5:111 raga/owl ' h" at :5 = a Val”: vi” 0 Ag’refmso’ "p Diff 4!! :' pg Van/W» #55“ +1754»? 6 1'3 Tailormm} Answer: 8) How do interfaces relate to multiple inheritance? 71M (007%;th an; at“? if data in “in b"! Answer V M1 W5 tfw/ 7%? m0 0, "1/3101 01er 9/645 5 in A Agua (£0 c W t mm :a m A? Wt it») 9) Can references to interface types be polymorphic? Explgain. R f i! (S ycj/ &!e in. an (n+1! “Lc/ 45654.43” Cam %;V‘ fits}? Mtfjlhwij VA Iva} ‘Ifl 53Mst Answer: 10) Write an interface for a CD player. It should have the standard operations (i.e. play, stop, etc) that usual CD players have. Answer: PM Hit: Va [Bylaw] 61/ g » Pvt Us}: we??? ’33.;ny [5, PM V93}; flimlnj " - Pug/4k V9”? gfigfwwd H; méiz‘fl Y9 {J 9&6 [4 {can}: {:sfmf‘kvaCE “ P , t! J F, ii pmiaiifi Vast? Seek lrficfi Egéfigyflfij 5%; E MULTIPLE CHOICE File 10 1. Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt"); a. System.out.println (diskOut, "Calvin") ; b. DiskFile .println ( "Calvin") ; c. PrintWriter.println ( "Calvin") ; d. diskOut.println("Calvin") ; ANS:d/ 2. When using the PrintWriter class, which of the following import statements would you write near the top of your program? a. import javax. swing . *; b. import java.io. *; c. import PrintWriter; d. import java.file.*; ANs:b, 3. Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents? a. FileWriter fwriter = new FileWriter ( "MyFile . txt" , true) ; PrintWriter outFile = new PrintWriter(fwriter); b. FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter); c. PrintWriter outfile = new PrintWriter("MyFile.tXt", true); d. PrintWriter outfile new PrintWriter<true, "MyFile.txt"); 0t, ANS: 4. Assume that inputFi le references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached? a. while (inputFile != null) b. while (linputFile . EOF) C. while (inputFile . hasNext ()) d. while (inputFile.nextLine == " ") {...} ANS: 0b .95: 5. Which of the following will open a file named MyFile.txt and allow you to read data from it? a. File file = new File("MyFile.txt"),- b. Scanner inputFile = new Scanner("MyFile.txt"); c. File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); d. PrintWriter inputFile = new PrintWriter("MyFile.txt"); ANS: C 6. Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file? a. int number = inputFile.nextInt(); b. int number = inputFile.next(); 0. int number = inputFile.readInt(); d. int number = inputFile.integer(); ANS:17 1 e " 7. You can use this method to determine whether a file exists. a. The Scanner class's exists method b. The File class's exists method c. The File class's canOpen method d. The PrintWriter class‘s fileEXists method ANSLB, 1. Data stored in a file is considered: a) temporary data b) persistent data c) recurring data d) there is no need to store data in files lo. Ans: b: 2. Computer circuitry is able to: a) get the value of a bit b) examine the value of a bit c) reverse the value of a bit (1) All of the above Ans: C“ 3. An example of when a file should not be used is: a) to save the status of a video game for another session. b) to save the value of a variable at runtime. c) to log errors in the execution of a program. d) these are all good examples of when files should be used. Ans: bl 4.What kind of exception is thrown if there is a problem opening or creating a StreamWriter? - a) Exception b) StreamException c) ‘OpenAndCreatingException d) IOException Anszd' True False Questions 1. Saving data to a file is the only way to keep that data when the program terminates. Ans: F’ 2. File—processing capabilities are important for a programming language to support commercial applications. Ans: 7/ 3. To distinguish fields or records there has to be one that is different from every other, this is called the record key. Ans: 1/ 4. Characters in Java are Unicode characters, each represented by one byte. Ans /" r 5. All files must end with an end-of-file marker, so that the computer knows where the file ends. Ans: T 5. Classes StreamIn and StreamOut are used to read from text files and output to text files. Ans: F , 6. When a file is opened, a stream object is created and associated with the file. Ans: / i 7. The standard output stream object enables a program to output data to the screen. AnszT 8. Every file automatically closes itself when not needed. Ans: -~ \,. 9. You can use the PrintWriter class to open a le for writing and write data to it. yams Answer: C 5) Every line of a(n) a) try block b) call stack trace c) catch block d) interface 6) finally block Answer 6 6) If an exception is not caught, a program will ’not compile (bi terminate abnormally ga/print a message and continue executing ' y’all of the above e) neither a, b nor c Answer: e A.) a x 7) The Exception class and the Error class are subclasses of the a) Throwable b) Catchable c) Runt imeProblem d) CompilerProblem e) none of the above Answer: {A , 8) A(n) is an ordered sequence of bytes. a) exception b) error e) input-output flow (1) stream e) none of the above Answer: 6} True/False Questions: 1) Unchecked exceptions must be caught or propogated, or a program will not compile. Answer F ' is executed no matter what exceptions are thrown, class. ANS: F 10. A file must always be opened before using it and closed when the program is finished using it. ANS: 7/ Exception Handling Multiple Choice Questions: 1) A(n) is an object that defines an unusual or erroneous situation that is typically recoverable. a) error b) exception c) interface (1) try block e) catch block Answer b 2) A(n) can be used to find the exact line where an exception was thrown during program execution. a) interface b) call-stack trace c) try block d) catch block e) none of the above Answer: b 3) A(n) is used to identify a block of statements that may cause an exception. a) call—stack trace b) error e) catch block (1) try block e) none of the above Answer: a 4) A(n) is used to specify how certain exceptions should be handled. a) finally block b) try block 0) catch block d) error e) none of the above t; 2) A final 1y clause is always required in a try-catch block. Answer: /» 3) Attempting to divide by zero will result in an Error being thrown, not an Except ion. Answer: F 4) Every line in a catch block is guaranteed to be executed in all situations. Answer: or Short Answer Questions: 1) What is a try block? A Head! of daiemfioif Why #rbw ram Exec? ’7’wa Answer: 2) What is a catch clause? We claim :Hmi gays Mm? exec/rife» géeuid L»; Hiram “Ml “A”; “f” be gone huge-a} 3) How is a finally clause different from a try block and a catch clause? ... ‘ I; , V A 4, Answer Evuq UM- m 6: 70/254in 5/610“ ,5 gjgefiuhr} Ac Meiji“ or ‘« Answer: 4) What is the difference between a checked exception and an unchecked exception? y a! f Q/VCéPfi‘Qfif (ahy3i;~ 0" (/7 of ff a» Answer f I ’ fl fflVgImM é (fifn/F.é. 5) Consider the following code fragment. String s; for(int i = O; i < s.length(); i++) System.out.println(s.charAt(i)); What exception will be thrown by this code and why? Answer; Nu” Val“; é" g jaw $19; 5654* Incpfil‘fi/llflt-él {*4 ’lt M: A o W! (Va 6) Consider the following code fragment. new int [50]; 100; int a a[50] Will this code fragment throw an exception? Explain. Answer: A‘rmygggatxaatdganflzfgr 71ng firmv I ? Q’PQ‘E O fAf’OMfPC 4‘7 (£3! J1 [fag/51” 55) figffig‘), 5%) gfufl :57 rouge- WI‘Ii {Ofl+¢ri,n~\/filw€$ a! 7) Is an exception an object? Explain. Answer: >410 fiygwpfi {jig r15; {31 EM. :5! g){ g is: 9%)} (lam; We? extrefifi'e» Q: Iva/2L6; H4 MWWM‘” §§ GUI Multiple Choice Questions: 1) GUI is an acronym for a) graphical UML interface b) graphical UML implementation c) graphical user implementation d) graphical user interface e) none of the above Answer: A 2) A(n) is an object that defines a screen element used to display information or allow the user to interact with a program in a certain way. a) GUI b) component 0) event (:1) listener e) AWT Answer ‘b 3) A(n) does. is an object that waits for an event to occur and responds in some way when it a) GUI b) component c) listener d) frame e) panel Answer 0 8) Which of the following components can be toggled on or off using the mouse, indicating that a particular boolean condition is set or unset? a) check box b) radio button 0) slider d) dialog box e) none of the above Answer: a True/False Questions: 1) A panel is displayed as a separate window, but a frame can only be displayed as part of another container. Answer: 2) Layout managers determine how components are visually presented. Answer: 3) Check boxes operate as a group, providing a set of mutually exclusive options. Answer: «— 4) A dialog box allows the user to select one of several options from a “drop down” menu. Answer: F 5) The ability of the user should be ignored when designing GUIs. In other words, GUIs should be designed with the most unskilled user in mind. Answer: F Short Answer Questions: 1) Explain the difference between check boxes and radio buttons. ¢ 6‘ m a.” g 6 Chm- boXM CM hr in dilli‘dflégfi? hath; W U “"3 ’ f {f I 2 fl View FMAA“ ’ , \Jl’lt‘t fétélib %<2}(€§ Opef'dé‘e a 5: ti, jgéflwfi firfiffig’fi M lit 6; W? we “has :54; 35:5,?“ 5; W? OF {$159 ’35 Answer: 2) Explain the difference between a combo box and a dialog box. A Coma w til/aw; Hi h 5456* W “6 “W's . , e * M NEW”: twigs-ES: (tuft v {jam 23 Answer: am W ygfltmai (gees hair 4) A container is goverened by a(n) , which determines exactly how the components added to the panel will be displayed. a) event b) content pane c) JFrame object d) JPanel object e) layout manager Answer: 6 5) Which of the following components allows the user to select one of several options from a “drop down” menu? a) check boxes b) radio buttons c) sliders (1) combo boxes e) none of the above Answer: 4 6) Which of the following layout managers organize the components from left to right, starting new rows as necessary? a) Border Layout b) Box Layout 0) Card Layout d) Flow Layout e) Grid Layout Answer: 7) Which of the following is a fundamental idea of good GUI design? a) Know the user b) Prevent user errors c) Optimize user abilities. d) Be consistent. e) all of the above Answer: (GP fr/ (ii r /” x 3 i i» How >< 3 ” Mex < . , [ii 212 x 0:: r Al? g, 3’s“ 55“va Pf/A :iflf} 3) Give an example of a common use of a dialog box. ‘\ Answer: Tc; 64k or M55f I (5/9.? 0‘ ma) 1( Ira/4A6 {Ix/6011‘; Frag CEfirt‘I 4) Suppose we have created a class called MyGUI, which represents a GUI. Write a program that creates a J Frame object, adds a MyGUI object to the frame and makes it visible. Answer: {mflor‘l java. Swings ’2’ Mfr-(l $901.9. 5M? ,1“ ,1 Publir dark; geari‘fijéUEU /\ é Tgamé )0er W54” Oath” Mgrél/é} E 5 Describe the areas of a border layout. 711: Answer: were are, five: @xfeffli ca“ Ci how}? I T)”: bahtom are #5 NW” kgandat/‘akf am! f'iiley an: 7A}: éa/W “é fie lav/1:: TLt 52/645 In Lcfl/een a?!“ *ke Ear (raw), mu L42»), [Mk1 611 zap/16:1 H, X e a? AC: E I A. [w 3&54 59$» 54 . b {:flam‘d/ A: ...
View Full Document

Page1 / 24

Midterm Exam - Spring 2011 - 30&amp;quot;&amp;quot; «ma...

This preview shows document pages 1 - 24. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online