Final Examination Semester 2 / Year 2011

Similar documents
Final Examination Semester 2 / Year 2012

Final Examination Semester 2 / Year 2010

Final Examination Semester 3 / Year 2012

Final Examination Semester 3 / Year 2008

Final Examination Semester 3 / Year 2012

Final Examination Semester 3 / Year 2010

Final Examination Semester 2 / Year 2011

Final Examination Semester 3 / Year 2007

Final Examination Semester 3 / Year 2010

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 2010

Final Examination Semester 3 / Year 2012

Final Examination Semester 3 / Year 2010

Final Examination Semester 2 / Year 2010

H212 Introduction to Software Systems Honors

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

Final Examination Semester 1 / Year 2011

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

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

Assignment 2. Application Development

MIT AITI Swing Event Model Lecture 17

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

Instruction to students:

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

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

Final Examination Semester 2 / Year 2011

Introduction to the JAVA UI classes Advanced HCI IAT351

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

Graphical User Interfaces. Comp 152

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

Java Programming Lecture 6

Chapter 12 Advanced GUIs and Graphics

CSE wi Final Exam 3/12/18 Sample Solution

Midterm assessment - MAKEUP Fall 2010

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

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

Graphics User Defined Forms, Part I

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

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Graphical User Interface (GUI)

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

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

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

Window Interfaces Using Swing Objects

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

Window Interfaces Using Swing Objects

We are on the GUI fast track path

Packages: Putting Classes Together

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

PIC 20A GUI with swing

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Graphical User Interfaces 2

AP CS Unit 11: Graphics and Events

AP CS Unit 12: Drawing and Mouse Events

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Dr. Hikmat A. M. AbdelJaber

2IS45 Programming

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

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

FirstSwingFrame.java Page 1 of 1

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Graphical User Interface (GUI)

CompSci 230 S Programming Techniques. Basic GUI Components

Section Basic graphics

User interfaces and Swing

Object-oriented programming in Java (2)

Programmierpraktikum

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 :) )

Final Examination Semester 3 / Year 2008

CS 251 Intermediate Programming GUIs: Components and Layout

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.

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

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

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

CS 11 java track: lecture 3

Graphical User Interfaces

CP122 Computer Science I. Chapter 2: Using Objects

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Java Just in Time: Collected concepts after chapter 18

Lecture 5: Java Graphics

CS 180 Fall 2006 Exam II

Reviewing OO Concepts

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Unit 7: Event driven programming

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

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

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Lecture 3: Java Graphics & Events

To gain experience using GUI components and listeners.

G51PRG: Introduction to Programming Second semester Applets and graphics

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

CIS 162 Project 1 Business Card Section 04 (Kurmas)

Lecture 18 Java Graphics and GUIs

Transcription:

Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE COURSE CODE TIME DEPARTMENT LECTURER : JAVA PROGRAMMING : PROG1114 : 2 1/2 HOURS : COMPUTER SCIENCE : LIM PEI GEOK Student s ID Batch No. : : Notes to candidates: 1) The question paper consists of 8 pages Section A: 10 questions (20 marks) Section B: 2 questions (20 marks) Section C: 2 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. A class, method or data is accessible to all clients. A method or data is only accessible inside the class. a. public, private b. public, protected c. private, public d. none, none 2. Identify which of the following is the concept of constructors? a. Constructors of superclass are inherited in the subclass. b. The return type of constructor is void. c. Constructor is invoke using the new operator when an object is created. d. A constructor called default constructor is provided automatically for all classes. 3. Which of the following is NOT a reserved word in Java? a. constant b. double c. class d. final 4. Which of the following method use to return a new String object that remove all white-space character in the String s? a. s.remove() b. s.trim() c. s.remove(, ) d. s.trim(, ) 5. Which of the following is a NOT javax.swing component? a. JLabel b. JPanel c. JFrame d. Button 6. Which of the following is not a method of class JTextField? a. addactionlistener b. settext c. setvisible d. seteditable 7. Which of the following is NOT kind of layout manager? a. GridLayout b. BorderLayout c. FlowLayout d. TableLayout 1/7

8. Which of the following is NOT correct about the Graphics components? a. Each component has its own coordinate system with the origin (0,0). b. The coordinate system located at the upper-right corner of the window. c. Import the java.awt.graphics to draw the graphics components such as polygon, rectangles and so on. d. Override the paintcomponent method to tell the container how to draw things. 9. Which of the following events will be trigger if mouse is pressed, released, clicked, entered and exited? a. addmousemotionlistener() b. addactionlistener() c. MouseExited() d. MouseClose() 10. 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 2/7

SECTION B: SHORT QUESTIONS (20 MARKS) Question 1 (12 Marks) a) What is displayed on the console when the following program is executed? (4 Marks) public static void main(string[] args) { String s1 = new String("Thank you"); String s2 = thank you"; if(s1.equals(s2)){ System.out.println("s1 and s2 have the same content"); else{ System.out.println("s1 and s2 do not have the same content"); if(s1 == s2){ System.out.println("s1 and s2 have the same reference"); else{ System.out.println("s1 and s2 do not have the same reference"); b) What is the output for the following codes? (You no need to show the actual position of the graphic components. You just need to sketch out what is display and how it look like when the following codes is executed.) (4 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.drawstring(""good luck!", 40, 60); 3/7

c) Show the output for the following program. (4 Marks) public static void main (String[] args) { String s = "Hello+!Nice+to-meet+you."; StringTokenizer st = new StringTokenizer(s, "+!"); while (st.hasmoretokens()){ System.out.println(st.nextToken() + " "); Question 2 (8 Marks) a. Suppose that s1 and s2 are two Strings. Which of the following statements or expression are incorrect? State the line number of the incorrect statements or expression. (3 Marks) 1 String s = new String( new string ); 2 String s3 = s1 + s2; 3 String s4 = s1 s2; 4 s1 == s2 5 s1 >= s2 6 int i = s1.length(); 7 char c = s1(0); b. There are two errors in the following classes. Identify the problems and rewrite the statement with correct codes. (5 Marks). 1 class Rectangle{ 2 private double length; 3 private double width; 4 public Rectangle(double length, double width){ 5 this.length = length; 6 this.width = width; 7 8 double findarea(){ 9 return length * width; 10 11 class Box extends Rectangle{ 12 private double height; 13 public double findarea(){ 14 return findarea()*height; 15 16 public Box(double length, double width ){ 17 Rectangle(length, width); 18 19 4/7

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 FixedInvestment contains: (1 Mark) a) A double data field name depositamount that specifies the investment amount (default 1000). (1 Mark) b) A double data field name annualinterestrate that specifies the fixed interest rate (default 5%). (1 Mark) c) An int data field named numberofyears that specifies the investment duration (default 1). (1 Mark) d) A no-arg constructor that creates a default instance. (2 Marks) e) A constructor that creates an instance with the specified depositamount, annualinterestrate and numberofyears. (4 Marks) f) The accessor methods for depositamount, numberofyears, and annualinterestrate. (3 Marks) g) The mutator method for numberofyears. (1 Mark) h) A method named gettotalreturn() that returns the investment return after the specified number of years. (6 Marks) The total return can be computed using the following formula: numberofyears * 12 totalreturn = investmentamount x (1 + montlyinterestrate) Write a test program named as TestFixedInvestment that creates a FixedInvestment object with a deposit amount of 10000 and an annual interest rate of 8.5% for 5 years. Your program is then display the investment return for the year 1 to year 5 based on the investment duration. The output as follow: (5 Mark) Years Investment return 1 10883.9091 2 11845.9476 3 12893.0217 4 14032.6475 5 15273.0060 Question 2(35 Marks) Write a program to perform account registration. This account registration system requires the bank staff to enter the customer account number, first name, last name and the balance. The system should able to check the user input to ensure that the correct information was entered by the bank staff user. The account number should only consist of integer value and the balance should be a double value. The bank staff can click the Save to File button to save the account record to a file. You need to complete the following specifications: a) Create a user interface as show in figure 1. (10 Marks) 5/7

b) Write the exception handler to handle the number format of account number and balance. You need to display the error message as show in figure 2 when it is appropriate. (5 Marks) c) Save the customer information which include account number, first name, last name and balance into a file when user click on Save to File button. The name of the file should be same as the account number such as 123456.txt for account 123456. The format of file should same as the output as show in figure 3. (12 Mark) d) You are required to write a status message to tell the user about the records saving status. The message Records was save successfully! when the records was saved successfully into the file. The message Duplicate account number is not allowed! is shown when the same account number exists. If this case happened, user will stop the process and display the error message. Figure 4 and 5 show the example output of error message. (8 Marks). Figure 1: User interface Figure 2: Dialog box is displayed when user entered incorrect number format either on account number or balance textfields. 6/7

Figure 3: Output of record.txt file. Figure 4: Example of status message when file was saved sucessfully. Figure 5: Example of status message when the account number was duplicated. 000 7/7