OLLSCOIL NA héireann THE NATIONAL UNIVERSITY OF IRELAND COLÁISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK. Summer Examination PDF

Description
OLLSCOIL NA héireann THE NATIONAL UNIVERSITY OF IRELAND COLÁISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK Summer Examination 2011 Computer Science CS5015 Object-oriented Software Development Dr

Please download to get full document.

View again

of 8
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information
Category:

Reviews

Publish on:

Views: 10 | Pages: 8

Extension: PDF | Download: 0

Share
Transcript
OLLSCOIL NA héireann THE NATIONAL UNIVERSITY OF IRELAND COLÁISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK Summer Examination 2011 Computer Science CS5015 Object-oriented Software Development Dr Carron Shankland Prof. James A. Bowen Mr. Adrian P. O'Riordan Time: 3 Hours Answer Question 1 and three of the other four questions Total = 140 marks Do not write answers on exam paper Page 1 of 8 Instructions for Question 1: There are a total of 50 marks for this multiple-choice question; each part is worth two marks. There is one correct answer (a., b., c., or d.) for each question. Write all your answers in an answer book, e.g. (i) b., (ii) d., etc. Question 1. (i) The JDK command to run a class Test is a. java Test b. java Test.class c. javac Test.java d. javac Test (ii) In Java, 13 / 5 evaluates to a. 7 b. 2 c. 2.6 d. 3 (iii) All of the following statements correctly display the text Welcome to Java. Which one is displayed in a separate window? a. JOptionPane.showMessageDialog(null, Welcome to Java ); b. System.out.println( Welcome to Java ); c. mylabel.settext( Welcome to Java ); d. g.drawstring( Welcome to Java, 0, 0); (iv) Which one of the following expressions will yield 0.5? a. 1 / 2 b. 1.0 / 2 c. (double) (1 / 2) d. 2 / (double) 1 (v) An instance of a class is known as a/an... a. identifier; b. data type; c. reference; d. object. (vi) What is displayed by the following statement? System.out.println( One ); a. One5 b. 6 c. One23 d. One 5 Page 2 of 8 (vii) Consider the following code snippet: char[] river = {'L', 'e', 'e'; System.out.print(river.length); What is printed? a. 0 b. 1 c. 3 d. nothing it generates an exception. (viii) In the following line of code, how many times is the constructor for Value called? Value[] thevalues = new Value[3]; a. 0; b. 1; c. 4; d. 3. (ix) How many objects have been created in total by the following Java declarations? int weight; Integer bhp; Engine e; a. 0; b. 1; c. 2; d. 3. (x) Consider the following very simple class: public class MyClass{ public MyClass(int i) { Which one of these instantiations of MyClass will give a compile-time error? a. MyClass mc = new MyClass(); b. MyClass mc = new MyClass(1); c. MyClass mc = new MyClass( new Integer(1)); d. MyClass mc = new MyClass((int)1.0); (xi) Which of the following statements is false? a. An instance of an int is the same size on all machines that a Java program is run on; b. You must define a constructor in every class; c. You can override a base class method in a derived class; d. You can define multiple constructors; Page 3 of 8 (xii) Suppose you wish to provide a mutator method for a Boolean field finished, what should be the signature of the method? a. void setfinished(boolean f); b. boolean isfinished(); c. boolean getfinished(); d. boolean setfinished(); (xiii) Consider the following variable declaration BankAccount b; This declaration will... a. create a BankAccount object; b. create a reference to a BankAccount object; c. create both a reference to a BankAccount object and an unnamed BankAccount object; d. create a BankAccount object only if the class has a no-argument constructor. (xiv) What would be the output after running the following program? public class LinePrinter { private String manufacturer = HP ; // default public LinePrinter(String m) { manufacturer = m; public String getmanufacturer() { return manufacturer; public static void main(string[] args) { LinePrinter p1 = new LinePrinter( Canon ); LinePrinter p2 = new LinePrinter( Epson ); p1 = p2; System.out.println(p1.getManufacturer()); a. Xerox b. HP c. Canon d. Epson (xv) Which of the following best describes method binding in Java? a. Methods are bound at compile time (i.e. early); b. Methods are bound at run time (i.e. late); c. Methods are sometimes bound early and sometimes late; d. The programmer can decide how methods are bound. (xvi) Which of the following best describes the use of the keyword this in Java? a. this refers to the computer on which the program is running; b. this refers to the object on which the current method is being run; c. this refers to the current program; d. this refers to the method in which it appears. Page 4 of 8 (xvii) Which one of the following statements is false? a. A method can be overloaded in the same class; b. A method can be overridden in the same class; c. If a method overloads another method, these two methods must have a different signature (i.e. parameter list); d. If a method overrides another method, these two methods must have the same signature (i.e. parameter list); (xviii) Which one of the following creates an ArrayList of initial size 100 referred to by al? a. ArrayList al[100]; b. ArrayList[] al = new ArrayList[100]; c. ArrayList al = ArrayList(100); d. ArrayList al = new ArrayList(100); (xix) Which of these statements is false? a. Swing components such as JButton are lightweight components; b. AWT components such as Button are heavyweight components; c. AWT enables you to draw simple 2D graphics; d. Swing completely replaces the earlier widget toolkit called AWT; (xx) What keyword is used in Java to declare that the variable is a class variable? a. constant; b. immutable; c. static; d. final. (xxi) Which one of the following statements is for terminating the program when closing the frame? a. frame.setdefaultcloseoperation(jframe.exit_on_close); b. frame.setdefaultcloseoperation(null); c. frame.windowclosing(null); d. frame.windowclosing(jframe.exit_on_close); (xxii) Which method should be overridden to draw on a Swing component? a. paint(graphics) b. paintcomponent(graphics) c. repaint() d. update(graphics); Page 5 of 8 (xxiii) Assuming you have a Graphics object called page, which statement will draw an outline of a rectangle of width 30 and height 50 with the upper-left corner at (20, 20)? a. page.drawrect(20,30,20,50); b. page.fillrectfill(20,30,20,50); c. page.fillrect(20,20,30,50); d. page.drawrectfill(20,20,30,50); (xxiv) What is the default layout of a JPanel? a. FlowLayout; b. GridLayout; c. BorderLayout; d. GridBagLayout. (xxv) Which one of these terms best describes the relationship between JComponent and JButton? a. association; b. aggregation; c. composition; d. inheritance. Page 6 of 8 Question 2. (Total of 30 marks for this question) Write a Java class called ExamMarks, which specifies a module name (String), module code (int), year (int) and an array of 20 integer marks. The class should have an appropriate three argument constructor, a tostring() method and methods displaying the highest mark and the average mark. It should have a separate method to obtain up to 20 marks from the user via the console. Use appropriate visibility modifiers to ensure encapsulation. In the main(string[]) method create an ExamMarks object. Marks will be given for good program design, code layout, and choice of identifiers as well as a satisfactory implementation of the requirements above. No marks will be given for comments or the inclusion of extra functionality not described above. Question 3. (Total of 30 marks for this question) The Union Bank of Ireland (UBI) is issuing two types of bonds on a bond market ten year and seven year with different interest rates. Prospective holders will be payed an annualized 7% and 8% on the principal for the ten year and seven year bonds respectively. Each bond has a bond holder name and principal amount. Semi-annually (every six months) the issuer pays the interest to all holders and a simple statement is printed. For example if you hold a 100,000 principal of the ten year bond, you will receive 7,000 in interest each year (in two semi-annual installments of 3,500 each). Write classes in Java to implement this system. Include classes UBI, Bond and subclasses TenYearBond and SevenYearBond. UBI should include an ArrayList of Bonds. Include one appropriate constructor for each class, a tostring() method for each and an overridden pay() method. Include code which creates at least one account of each type. The use of inheritance will gain much higher marks. Marks will be given for good program design, code layout, and choice of identifiers as well as a satisfactory implementation of the requirements above. No marks will be given for comments or the inclusion of extra functionality not described above. Question 4. (Total of 30 marks for this question) Write a Java program to implement the GUI shown below. When the user enters a temperature value in the text input box and then clicks the button (Convert), a Fahrenheit equivalent of the amount should be displayed where the second JLabel is. This result should not be editable by the user. Concentrate on creating the components, adding them and activating them. Use default colours and fonts. The screenshot is an example you do not have to replicate that exact layout or positioning. Page 7 of 8 Marks will be given for good program design, code layout, and choice of identifiers as well as a satisfactory implementation of the requirements above. No marks will be given for comments or the inclusion of extra functionality not described above. Question 5. (Total of 30 marks for this question) (i) Briefly describe two features of Java that make it a suitable choice for developing Web applications. (4 marks) (ii) List five core features of the Java programming language that changed in the major release Java 5. (5 marks) (iii) What is meant by a virtual machine? Explain the role played by bytecode in the JVM. (5 marks) (iv) Give two differences between Java ME and Google Android. (4 marks) (v) What is exception handling? Give two advantages of exception handling over having methods return error codes. (4 marks) (vii) Explain the role played by events and layout managers in GUI programming. Give one example of each. (4 marks) (viii) Give four advantages of using an IDE such as Eclipse or DrJava as opposed to writing the necessary code using a simple text editor and a command-line JDK. (4 marks) Page 8 of 8
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x