Attempt FOUR questions Marking Scheme Time: 120 mins

Similar documents
Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications

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

Layouts and Components Exam

More Swing. CS180 Recitation 12/(04,05)/08

H212 Introduction to Software Systems Honors

JLayeredPane. Depth Constants in JLayeredPane

CSIS 10A Assignment 7 SOLUTIONS

A Simple Text Editor Application

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Java Project P6 Event Handling

RAIK 183H Examination 2 Solution. November 11, 2013

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

Window Interfaces Using Swing Objects

JAVA NOTES GRAPHICAL USER INTERFACES

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

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

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

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

University of Cape Town Department of Computer Science Computer Science CSC1017F

RAIK 183H Examination 2 Solution. November 10, 2014

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

Window Interfaces Using Swing Objects


Building Graphical User Interfaces. GUI Principles

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

Building Graphical User Interfaces. Overview

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Implementing Graphical User Interfaces

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Project 1. LibraryTest.java. Yuji Shimojo CMSC 335

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Swing Programming Example Number 2

CSCI 201L Written Exam #1 Fall % of course grade

CSCI 201L Written Exam #1 - SOLUTION Fall % of course grade

Lab Assignment 13 (week 13)

Part 3: Graphical User Interface (GUI) & Java Applets

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

Java Programming Lecture 6

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

Swing from A to Z Some Simple Components. Preface

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

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

Programming graphics

Graphical User Interface

Chapter 6: Graphical User Interfaces

DM503 Programming B. Peter Schneider-Kamp.

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Starting Out with Java: From Control Structures Through Objects Sixth Edition

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

Inheritance (cont) Abstract Classes

We are on the GUI fast track path

Event Driven Programming

Today. cisc3120-fall2012-parsons-lectiii.3 2

Graphical User Interfaces. Comp 152

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

CMP 326 Midterm Fall 2015

2110: GUIS: Graphical User Interfaces

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

AP CS Unit 11: Graphics and Events

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

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

Lösningsförslag till exempeldugga

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

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

University of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ November Exam

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

PRÁCTICO 1: MODELOS ESTÁTICOS INGENIERÍA INVERSA DIAGRAMAS DE CLASES

encompass a group of features for building Graphical User Interfaces (GUI).

Based on slides by Prof. Burton Ma

INTRODUCTION TO (GUIS)

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

CS 180 Final Exam Review 12/(11, 12)/08

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education

RobotPlanning.java Page 1

Swing - JLabel. Adding a text (and HTML) labels to a GUI

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

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

Introduction to the JAVA UI classes Advanced HCI IAT351

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

1005ICT Object Oriented Programming Lecture Notes

Chapter 7: A First Look at GUI Applications

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

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

Graphics User Defined Forms, Part I

Final Examination Semester 3 / Year 2008

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

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

CS 3331 Advanced Object-Oriented Programming Final Exam

Transcription:

Ahmadu Bello University Department of Computer Science Second Semester Examinations August 2017 COSC212: Object Oriented Programming II Marking Scheme Attempt FOUR questions Marking Scheme Time: 120 mins 1. (a). [12 Marks]. Suppose a call to the sortlist(int array[]) method from the code below is made with values {5, 2, 9, 4, 1, 3, 6, 0 write in the table below each pass of the value i. Solution public static void sortlist(int array[], Comparator c){ int temp; for(int i = 0; i<array.length;i++){ int min_index = i; for(int j = i+1; j< array.length; j++){ if(c.compare(array[j], array[min_index])<0) temp = array[i]; min_index = j; array[i] = array[min_index]; array[min_index] = temp; System.out.println(i+" "+Arrays.toString(array)); Pass i = 0 0 2 9 4 1 3 6 5 Pass i = 1 0 1 9 4 2 3 6 5 Pass i = 2 0 1 2 4 9 3 6 5 Pass i = 3 0 1 2 3 9 4 6 5 Pass i = 4 0 1 2 3 4 9 6 5 Pass i = 5 0 1 2 3 4 5 6 9 Pass I = 6 0 1 2 3 4 5 6 9 Pass I = 7 0 1 2 3 4 5 6 9

(b). [8 Marks]. Examine the program source code below and write the outputs: import java.util.arrays; public class SearchClass { public static void main(string args[]) throws Exception { int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 ; Arrays.sort(array); printarray("sorted array", array); int index = Arrays.binarySearch(array, -3); System.out.println("Found -7 @ " + index); private static void printarray(string message, int array[]){ System.out.println(message + ": [length: " + array.length + "]"); for (int i = 0; i < array.length; i++) { if(i!= 0) { System.out.print(", "); System.out.print(array[i]); System.out.println(); Solution: Sorted array : [length: 10] -9, -7, -3, -2, 0, 2, 4, 5, 6, 8 Found -7 @ 2

2. [20 Marks]. Study the following program source code and answer questions i-vi below. import java.util.*; public class Book { private String author; private String title; private int bookno; ArrayList<Book> books; static ListIterator it; public Book(String author, String title, int bookno){ this.author = author; this.title = title; this.bookno = bookno; public Book(){ books = new ArrayList<Book>(); it = books.listiterator(); public String getauthor(){ return author; public String gettitle(){ return title; public int getbookno(){ return bookno; public void setauthor(string newauthor){ if(!newauthor.equals("")) author = newauthor; public void settitle(string newtitle){ if(!newtitle.equals("")) title = newtitle; public void setbookno(int newbookno){ if(newbookno > 0) bookno = newbookno; public String tostring(){ return String.format("Author: %s\ntitle: %s\nbook No.: %05d",author,title,bookNo); public static void main(string[] args){ Book bb = new Book(); // methods calls // end of class Book i. [4 Marks]. Write a static method createbook()that will create two books and add them to ArrayList as declared in the above program.

public static void createbook(){ Book book = new Book(); book.books.add(new Book("Othman Aliyu","Java How to Program",00001)); book.books.add(new Book("Aisha Aliyu","Object Oriented Programming in C",00002)); ii. [3 Marks] Write a static method showallbooks()that will display all the books added to the ArrayList. public static void ShowAllBooks(){ while(it.hasnext()){ System.out.println(it.next()); iii. [3 Marks] Write a static method nextbook()that will display the next book from the ArrayList. public static void nextbook(){ if(it.hasnext()){ System.out.println(it.next()); iv. [3 Marks] Write a static method previousbook()that will display the previous book from the ArrayList. public static void previousbook(){ if(it.hasprevious()){ System.out.println(it.previous()); v. [4 Marks] Write a static method updatebook()that will change the authors of the books to Ahmadu Bello University, Zaria. for any bookno greater than 10 public static void updatebook(){ while(it.hasnext()){ Book book = (Book)it.next(); if(book.getbookno()>10) book.setauthor("ahmadu Bello University");

vi. [4 Marks] Write a static method removebook()that will remove all the books with bookno less than 0 from the ArrayList. public static void removebook(){ while(it.hasnext()){ Book book = (Book)it.next(); if(book.getbookno() < 0) books.remove(); 3. [20 Marks] Write a GUI class (Account.java) that will display the window shown in Figure 1.1. The window (JFrame) has a fixed size of 500 by 200 pixels. Create a menu called File with two items namely Open and Save. The first row has a label (JLabel) and a text box (JTextField) for which it should be wide enough for at least ten characters. The second row has a label (JLabel) and two radio buttons (JRadioButton) marked Male and Female, the third row has a label (JLabel) and a text area (JTextArea) with 5 rows and 10 columns, and the last row has two buttons (JButton), one marked Clear which will clear the contents of the text field and text area. The other button marked Create Account which will display the text from the text field in the text area. Note: the two radio buttons for gender should be mutually exclusive Figure 1.1

import java.awt.event.*; import java.awt.*; import javax.swing.*; public class Account extends JFrame{ private JButton btncreate; private JButton btnclear; private JTextField txtname; private JTextArea txtdisplay; public Account(){ super("sign Up Form"); JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("File"); filemenu.setmnemonic('f'); JMenuItem open = new JMenuItem("Open"); JMenuItem save = new JMenuItem("Save"); filemenu.add(open); filemenu.add(save); menubar.add(filemenu); setjmenubar(menubar); add(new JLabel("Full Name: ")); add(txtname = new JTextField(10)); add(new JLabel("Gender:")); JPanel panel = new JPanel(); JRadioButton rbmale; JRadioButton rbfemale; panel.add(rbmale = new JRadioButton("Male",true)); panel.add(rbfemale = new JRadioButton("Female")); ButtonGroup grp = new ButtonGroup(); grp.add(rbfemale); grp.add(rbmale); add(panel); add(new JLabel("Display: ")); add(txtdisplay= new JTextArea(5,10)); JScrollPane scroll = new JScrollPane(txtDisplay); add(scroll); btnclear = new JButton("Clear"); add(btnclear); btncreate = new JButton("Create Account"); add(btncreate); setlayout(new GridLayout(5,2)); setsize(500,200); setresizable(true); setvisible(true); btncreate.addactionlistener(new Handler()); btnclear.addactionlistener(new Handler()); // end constructor public class Handler implements ActionListener{ public void actionperformed(actionevent ae){ if(ae.getsource() == btnclear){ txtname.settext(""); txtdisplay.settext(""); if(ae.getsource() == btncreate){ txtdisplay.settext(txtname.gettext()); public static void main(string[] args){ Form Account = new Account(); form.setdefaultcloseoperation(jframe.exit_on_close);