Final Examination Semester 2 / Year 2012

Similar documents
Final Examination Semester 2 / Year 2011

Final Examination Semester 2 / Year 2010

Final Examination Semester 3 / Year 2008

Final Examination Semester 3 / Year 2010

Final Examination Semester 3 / Year 2012

Final Examination Semester 3 / Year 2012

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Final Examination Semester 2 / Year 2011

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Final Examination Semester 3 / Year 2012

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

CP122 Computer Science I. Chapter 2: Using Objects

H212 Introduction to Software Systems Honors

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Instruction to students:

Dr. Hikmat A. M. AbdelJaber

Object-oriented programming in Java (2)

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

2. (True/False) All methods in an interface must be declared public.

Final Examination Semester 2 / Year 2010

CSE wi Final Exam 3/12/18 Sample Solution

Assignment 2. Application Development

Graphical User Interfaces 2

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Final Examination Semester 3 / Year 2007

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

First Name: AITI 2004: Exam 2 July 19, 2004

CS 11 java track: lecture 3

MIT AITI Swing Event Model Lecture 17

First Name: AITI 2004: Exam 2 July 19, 2004

CS 113 PRACTICE FINAL

Full file at Chapter 2 - Inheritance and Exception Handling

Shared Collection of Java Course Materials: New Topics Covered. Agenda

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

Final Examination Semester 2 / Year 2010

Final Examination Semester 3 / Year 2010

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Graphic User Interfaces. - GUI concepts - Swing - AWT

This exam is open book. Each question is worth 3 points.

Java for Non Majors Spring 2018

We are on the GUI fast track path

CIS 162 Project 1 Business Card Section 04 (Kurmas)

RAIK 183H Examination 2 Solution. November 10, 2014

CSE wi Final Exam 3/12/18. Name UW ID#

Questions Answer Key Questions Answer Key Questions Answer Key

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

More on Exception Handling

Section Basic graphics

AP CS Unit 12: Drawing and Mouse Events

More on Exception Handling

CSE 331 Final Exam 6/7/16

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

CS 209 Programming in Java #10 Exception Handling

Final Examination Semester 2 / Year 2012

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

1 Short Answer (10 Points Each)

RAIK 183H Examination 2 Solution. November 11, 2013

Programming II (CS300)

Exception-Handling Overview

G51PRG: Introduction to Programming Second semester Applets and graphics

Fundamentals of Object Oriented Programming

Object Orientated Programming in Java. Benjamin Kenwright

import javax.swing.*; import java.awt.*; import java.awt.event.*;

CSCI 355 LAB #2 Spring 2004

Announcements. Java Graphics. Exceptions. Java Odds & Ends

Encapsulation in Java

Programming II (CS300)

Final Examination Semester 3 / Year 2010

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

TWO-DIMENSIONAL FIGURES

An exception is simply an error. Instead of saying an error occurred, we say that an.

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name: KEY. Question Value Score

Chapter 2 Using Objects. Types. Number Literals. A type defines a set of values and the operations that can be carried out on the values Examples:

CMP 326 Midterm Fall 2015

Reviewing OO Concepts

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

ECE 122. Engineering Problem Solving with Java

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Control Statements: Part Pearson Education, Inc. All rights reserved.

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

CSSE 220. Intro to Java Graphics. Check out IntroToJavaGraphics and BiggestFan projects from SVN

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

UNIVERSITI SAINS MALAYSIA. CIT502 Object-Oriented Programming and Software Engineering

User interfaces and Swing

Graphical User Interface (GUI)

ICOM 4015: Advanced Programming

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CSCI 355 Lab #2 Spring 2007

Transcription:

Final Examination Semester 2 / Year 2012 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student s ID : Batch No. : Notes to candidates: 1) The question paper consists of 7 pages Section A: 10 questions (20 marks) Section B: 2 questions (20 marks) Section C: 3 questions (60 marks) 2) Answer all questions. 3) Write your answer for Section A and Section B in answer booklet. 4) Save your answer for question in Section C and submit your answer in softcopy to Southern College E-Learning System.

SECTION A: MULTIPLE CHOICE QUESTION (10 X 2 = 20 MARKS) Please choose most appropriate answer. State the answer in the answer booklet. 1. When is a finally{ block executed? a. Only when an exception is thrown by a try block. b. Only when there are no exceptions thrown. c. At the end of a program. d. Always after the execution of a try block, regardless of whether or not an exception is thrown. 2. If a negative value is used for an array index,. a. the last index of the array is automatically accessed instead b. an IndexOutOfBoundsException is thrown c. the program termates immediately d. a NumberFormatException is thrown 3. Which of the following is NOT a reserved word in Java? a. finally b. class c. constant d. private 4. Which of the following is used to initialize a string with 987? a. String[] str = { 9, 8, 1 ; b. String[] str = {9, 8, 7; c. String str = new String( 987 ); d. String str = 987; 5. Which of the following is not a method of class JTextField? a. addactionlistener b. settext c. setvisible d. seteditable 6. Which of the following method is used to catch an error that occurs when opening a file? a. OpenFileException b. FileException c. FileOpenException d. IOException 1/6

7. Which of the following is NOT correct about the Graphics components? a. Import the java.awt.graphics to draw the graphics components such as polygon, rectangles and so on. b. Override the paintcomponent method to tell the container how to draw things. c. The coordinate system located at the upper-right corner of the window. d. Each component has its own coordinate system with the origin (0,0). 8. Suppose s1 and s2 are two strings. Which of the following is NOT correct expression? a. String s3 = s1 + s2 b. String s3 = s1 s2 c. if(s1 == s2) d. int i = s2.length(); 9. A subclass inherits from its superclasses. a. private data b. protected data c. public data d. b and c 10. Which of the following is INCORRECT statements? a. The contents of a string can be partially changed. b. You can add, insert, or delete characters from a string buffer c. You can create a string buffer from a string d. You can convert a string buffer into a string. 2/6

SECTION B: SHORT QUESTIONS (20 MARKS) Question 1 (10 Marks) a) What is displayed on the console when the following program is executed? (5 Marks) public static void main (String[] args) { String s = "Good luck*for your*final*examination"; StringTokenizer st = new StringTokenizer(s, "*", true); while (st.hasmoretokens()){ System.out.println(st.nextToken()); b) What is the output for the following codes? (You are not required to show the actual position of the graphic components. You just need to sketch out what is display and how it looks like when the following codes are executed.) (5 Marks) import javax.swing.*; import java.awt.*; public class DrawGraphic extends JPanel{ public static void main(string[] args) { JFrame frame = new JFrame("Draw Graphic"); frame.add(new DrawGraphic()); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setsize(300, 200); frame.setvisible(true); protected void paintcomponent(graphics g) { super.paintcomponent(g); g.drawrect(10,10, 110,110); g.drawline(20, 90, 90, 90); g.drawline(60, 20, 90, 90); g.drawline(20, 90, 60, 20); 3/6

Question 2 (10 Marks) JAVA PROGRAMMING a. In the following code, classes A and B are in the same package. What are the possible values can be replaced in the question marks? (5 Marks) package p1; public class A{?(i) int i;?(ii) void m(){ (a) package p1; public class B extends A{ public static void main (String[] args) { System.out.println(i); m(); (b) b. There are two errors in the following classes. Identify the problems and rewrite the statement with correct codes. (5 Marks). 1 public class Test{ 2 String test; 3 public void Test(String s){ 4 this.test = s; 5 6 public static void main(string[] args) { 7 Test test = new Test("A"); 8 System.out.println(test); 9 10 4/6

SECTION C: CODING QUESTIONS (60 MARKS) Submit your answer in softcopy and upload it to Southern E-Learning System. Question 1 (25 Marks) Design a class named BMI contains: (1 mark) a) A double data field name weight that specifies the weight of the person in kilogram. (1 mark) b) A double data field name height that specifies the height of the person in centimeter. (1 mark) c) An int data field named name that specifies the name of the person. (1 mark) d) A no-arg constructor that creates a default instance. (2 marks) e) A constructor that creates an instance with the specified name, weight and height. (3 marks) f) The accessor and mutator methods for all the data fields. (3 marks) g) A method named calculatebmi() that returns the the BMI value. (5 marks) h) A method named tostring() that return a string description for the name, weight, height and BMI of the person. (3 marks) Write a test program named as TestBMI that creates a BMI object with a name (Alex Tan), weight (60Kg) and height (160cm). Your program is then display the BMI object by invoking their tostring method. (5 marks) Question 2(24 Marks) You need to create an application that allows user to enter an integer number. The application will display a multiplication table that shows a result of multiplying the user entered number by numbers 1 through 9. If the number entered by user is not an integer number then you need to show an error message in the label (as shown in figure 3). You need to work on the application as follows: a) Create a user interface as show in figure 1. (8 marks) Figure 1: User interface 5/6

b) Write the function for showing the multiplication table when user types an integer number in the text box. In figure 2, it will show the multiplication result in label while user enters number 8. (8 marks) c) Write the exception handler function to handle the number format. If user enters an input which is not an integer number, then the application should display the error message as show in figure 3. (5 marks) d) Write the function for exit button. (3 marks) Figure 2: While user enters number 8 in the textbox, it will show the multiplication result in the label. Figure 3: While user enters a letter a, it will show an error message in the label. Question 3 (11 Marks) For this question, you need to download a text file which named as number.txt from e-learning system. The downloaded text file contains an unspecified number of scores. Write a program that reads the scores from the file and display their total and average. 000 6/6