Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions
|
|
- Constance Norris
- 6 years ago
- Views:
Transcription
1 Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours Answer all questions Name : Student Id # : Only an unmarked copy of a textbook on Java, your printed class notes (unmarked) will be allowed. No computers or any other electronic devices allowed. Answer all questions. Note that Question 3 has 2 alternatives. You are advised to answer Alternative I of Question 3, which carries 25 marks. If you fail to answer Alternative I of Question 3, you should try answering Alternative II of that question, which carries only 15 marks. The total number of pages in this test is 9. The test will involve regular expressions. A cheat sheet with selected information from the lecture slides on regular expressions is included. When developing a class definition to address the problem in question 3, you must document your class definitions and follow all programming conventions mentioned in the lectures. (Your documentation will be useful if your code is not correct. If your code is incorrect, you will get part marks, if your documentation shows that your approach has some merit). You must not remove any of the staples before you are authorized to remove it and start writing the test. All your responses must be given in this exam booklet. You may request additional sheets of paper as needed. You may make assumptions which do not violate anything I have specified. It is recommended that you ask me to approve any assumptions you make. 1
2 Question 1) Consider the class Q1Mid2 given below. If this application is executed, it displays one or more objects of the JFrame class. Show, using a diagram, all the frames displayed and their contents, AFTER ALL THE STEPS given below are carried out: Step 1: Type in the frame with the title Q1Mid2FrameII and then press the button Press Me. Step 2: Type abcd in the frame with the title Q1Mid2FrameII and then press the button Press Me. Step 3: Type -.45 in the frame with the title Q1Mid2FrameII and then press the button Press Me. (Note that this input starts with a or dash) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Q1Mid2 extends JFrame implements ActionListener{ private int currentresult = 0; private int numberenteredbyuser = 0; private JLabel alabel; private JTextField inputarea; private JButton abutton; private JTextArea outputarea; private Q1Mid2 ptr; public Q1Mid2(){ super("q1mid2framei"); setlayout(new FlowLayout()); outputarea = new JTextArea(10, 10); add(outputarea); setsize(220, 220); setvisible(true); public Q1Mid2(Q1Mid2 ptr){ super("q1mid2frameii"); this.ptr = ptr; setlayout(new FlowLayout()); alabel = new JLabel("type input followed by CR"); inputarea = new JTextField(10); add(inputarea); outputarea = new JTextArea(10, 10); add(outputarea); abutton = new JButton("Press Me"); abutton.addactionlistener(this); add(abutton); setsize(160, 280); setvisible(true); 2
3 public void actionperformed(actionevent e){ String s; double value; s = inputarea.gettext(); inputarea.settext(""); if (valid(s)){ value = Double.parseDouble(s); if (value >= 0){ outputarea.append(value + " is good\n"); else{ outputarea.append(value + " is not good\n"); else { ptr.outputarea.append(s + " is invalid\n"); private boolean valid(string s){ String pattern = "[+-]?\\d*\\.\\d+"; if (s.matches(pattern)){ return true; else { return false; public static void main(string args[]){ Q1Mid2 aframe = new Q1Mid2(); Q1Mid2 bframe = new Q1Mid2(aFrame); Your answer: (Full Marks 20) 3
4 Marking scheme: Two frames with all GUI in the proper positions following the flowlayout scheme: 6 marks. (Note that the JLabel object was not added. If some one includes that, penalty 1 mark. TextField is blank 2 marks. Each line of output -4 marks X 3 = 12 marks Question 2) Consider the following Java application: import java.util.*; import javax.swing.*; // Bonus marks for missing import 1 mark public class Q2Faulty extends JFrame{ private JTextField inputarea; private JLabel citynamelabel; private JLabel outputlabel; private JButton mybutton; private JTextField outputarea; public Q2Faulty(){ super("ques 2"); setlayout(new FlowLayout()); citynamelabel = new JLabel("Type City name"); add(citynamelabel); inputarea = new JTextField(10); add(inputarea); inputarea.addactionlistener(new ActionListener(){ public void actionperformed(actionevent e){ // actionperformed has an // empty body 5 marks ); outputlabel = new JLabel("Message is"); add(outputlabel); outputarea = new JTextField(10); add(outputarea); mybutton = new JButton("Clear all"); // No actionlistener added to // mybutton 5 marks add(mybutton); setsize(230, 140); setvisible(true); 4
5 private boolean validcityname(string cityname){ String cityregularexpression; // must specify an appropriate regular // expression 5 marks if (cityname.matches(cityregularexpression)){ // line 36 return true; else { return false; public static void main(string args[]){ Q2Faulty aframe = new Q2Faulty(); The objective of this application is to initially display an object of class Q2Faulty as shown below. The user is expected to type in the name of a city in inputarea and press Carriage Return. The city name is valid if it contains one, two or three components, where each component starts with an upper case alphabet and contains one or more lower case alphabets. In addition, for city names with two or three components, the first and/or the second component may have a period (i.e., the symbol. ) at the end. If the city name is valid, a message Name is valid should be displayed in output Area as shown below. If the name is invalid, a message Name is not valid should be displayed in output Area as shown below. 5
6 (Note: This name is invalid since it has only one component that ends with a period). When the user presses the button, both inputarea and outputarea should be cleared. Some valid city names in Ontario are as follows: Windsor, St. Catherines, Sault Ste. Marie, Niagara Falls, Prince Edward County Eclipse indicated there is a error/warning in line 36 (a comment indicates which is line 36) and the message was cityregularexpression may not have been initialized. There may be other problems with the code. Your task is to fix all errors in the application run time or compile time. You must not delete any line or part of a line of the above application. You are only allowed to add one or more lines of code or part of lines of code. Hint: Do not stop after correcting the first mistake. One solution: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class Q2 extends JFrame{ private JTextField inputarea; private JLabel citynamelabel; private JLabel outputlabel; private JButton mybutton; private JTextField outputarea; public Q2(){ super("ques 2"); setlayout(new FlowLayout()); citynamelabel = new JLabel("Type City name"); add(citynamelabel); inputarea = new JTextField(10); add(inputarea); inputarea.addactionlistener(new ActionListener(){ public void actionperformed(actionevent e){ String cityname; cityname = inputarea.gettext(); 6 (Full Marks 15)
7 if (validcityname(cityname)){ outputarea.settext( "Name is valid"); else { outputarea.settext("name is not valid"); ); outputlabel = new JLabel("Message is"); add(outputlabel); outputarea = new JTextField(10); add(outputarea); mybutton = new JButton("Clear all"); mybutton.addactionlistener(new ActionListener(){ public void actionperformed(actionevent e){ outputarea.settext(""); inputarea.settext(""); ); add(mybutton); setsize(230, 140); setvisible(true); private boolean validcityname(string cityname){ String cityregularexpression = "([A-Z][a-z]+\\.? ){0,2[A-Z][a-z]+"; // This will point to a // regular expression for valid city names /* St. Catherines Sault Ste. Marie Niagara Falls Prince Edward County Windsor */ if (cityname.matches(cityregularexpression)){ return true; else { return false; public static void main(string args[]){ Q2 aframe = new Q2(); Question 3 alternative a) Consider classes Shape, Rectangle and Interface Sortable given below. You are not allowed to modify these classes in any way. These class definitions have no errors. 7
8 public interface Sortable { public boolean lessthan(sortable x); public abstract class Shape { private String color; public Shape(String color){ this.color = color; public abstract double getarea(); public String getcolor(){ return color; public abstract class Rectangle extends Shape implements Sortable{ private double width; private double height; public Rectangle(double width, double height, String color){ super(color); this.width = width; this.height = height; public String tostring(){ return "Rectangle with width " + width + " and height " + height + " having color " + getcolor(); public double getarea(){ return width * height; public void changewidth(double newwidth){ width = newwidth; public void changeheight(double newheight){ height = newheight; Your task is to define Square - a concrete subclass of Rectangle as follows. An object of class Square represents a special type of rectangle where, by definition, the width is always the same as the height. Class Square should include the following methods: A constructor which has two parameters i) the colour of the square ( a string such as Red or Black ) and ii) the size of the square, specifying both the width and the height of the square. 8
9 A tostring method which describes the size of the square, and the colour. See the testing program for the expected output. A lessthan method satisfying the requirements of the interface Sortable specified in Rectangle. An object O1 of class Square is less than an object O2 of class Square, if the area of O1 is less than that of O2. To compute the area of a square, you must use method getarea() of Rectangle. Feel free to include other methods in Square as needed. You are not allowed to have any instance variable or static variable in Square. A tester program to illustrate features of class Square is given below. public class Q3Tester { public static void main(string args[]){ Square s1, s2; s1 = new Square(10.0, "Black"); s2 = new Square(20.0, "Red"); s1.changewidth(12.0); // Since s1 is pointing at an object of class Square, // both width and height of object s1 are now changed to 12.0 s2.changeheight(15.0); // Similarly both width and height of object s2 are now changed to 15.0 if (s1.lessthan(s2)){ // s1.getarea() returns and s2.getarea() returns 225.0, // so the condition is true System.out.println(s1 + " is less than " + s2); else { System.out.println(s1 + " is not less than " + s2); Output produced: Square with size 12.0 having color Black is less than Square with size 15.0 having color Red One solution: public class Square extends Rectangle{ // 1 mark // Penalty for adding variables 3 marks public Square(double size, String color){// 1 mark super(size, size, color); // 3 marks public String tostring(){ // 1 mark String s; String tokens[]; double width; s = super.tostring(); tokens = s.split(" "); //extracting the value of width may be done in many ways width = Double.parseDouble(tokens[3]); // 4 marks 9 (Full Marks 25)
10 return "Square with size " + width + " having color " + getcolor(); // 2 marks public void changewidth(double newwidth){ // 1 mark super.changewidth(newwidth); // 1 mark super.changeheight(newwidth);// 1 mark public void changeheight(double newheight){ // 1 mark super.changewidth(newheight); // 1 mark super.changeheight(newheight); // 1 mark public boolean lessthan(sortable x){ // 1 mark Rectangle temp; if (x instanceof Rectangle){ // may check for Rectangle or Square and down cast 2 marks temp = (Rectangle) x; // to rectangle or Square 1 mark if (this.getarea() < temp.getarea()){ // check if condition satisfied 1 mark return true; // // if so return true 1 mark return false; // Otherwise return false. 1 mark // I have returned false even if x is not instance of Rectangle. This may be handled // differently since I did not specify that 10
11 Question 3 alternative b) Consider class Person given below. We wish to modify this class to define class SortablePerson, so that an array of objects of class SortablePerson can be sorted, using the year of birth as the primary key and the name as the secondary key, by invoking the method sortanything, that was discussed in class. Interface Sortable is given above and class Sort, which includes static method sortanything is given below. Class PersonTester, given below, may be used to test SortablePerson and obtain a sorted list of objects of class SortablePerson. public class Person { private String name; private int yearofbirth; public Person(String name, int yearofbirth){ this.name = name; this.yearofbirth = yearofbirth; public String tostring(){ return name + " was born in " + yearofbirth; public class Sort { public static void sortanything(sortable objects[], int numobjects){ Sortable temp; for(int i = 0; i < numobjects-1; ++i) for(int j = i+1; j < numobjects; ++j) if(!objects[i].lessthan(objects[j])){ temp = objects[i]; objects[i] = objects[j]; objects[j] = temp; public class PersonTester { public static void main(string args[]){ SortablePerson table[] = new SortablePerson[6]; table[0] = new SortablePerson("John", 1985); table[1] = new SortablePerson("Mary", 1989); table[2] = new SortablePerson("Tom", 1985); table[3] = new SortablePerson("Liz", 1985); table[4] = new SortablePerson("Tony", 1989); table[5] = new SortablePerson("Cathy", 1989); Sort.sortAnything(table, 6); for (SortablePerson p : table){ System.out.println(p); 11
12 The expected output is given below: John was born in 1985 Liz was born in 1985 Tom was born in 1985 Cathy was born in 1989 Mary was born in 1989 Tony was born in 1989 One solution: (Full Marks 15) public class SortablePerson implements Sortable{ // 2 marks private String name; private int yearofbirth; public SortablePerson(String name, int yearofbirth){// 1 mark this.name = name; this.yearofbirth = yearofbirth; public String tostring(){ return name + " was born in " + yearofbirth; public boolean lessthan(sortable x){ // 1 mark SortablePerson temp; temp = (SortablePerson)x; // 3 marks. Students may choose to test first if this casting is valid if (this.yearofbirth < temp.yearofbirth){ // compare on the basis of primary key 4 marks return true; else if (this.yearofbirth > temp.yearofbirth){ return false; else if (this.name.compareto(temp.name) < 0){ // compare on the basis of secondary // key 4 marks return true; else { return false; 12
Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling
Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)
More informationCMP-326 Exam 2 Spring 2018 Total 120 Points Version 1
Version 1 5. (10 Points) What is the output of the following code: int total = 0; int i = 0; while( total < 90 ) { switch( i ) { case 0: total += 30; i = 1; break; case 1: i = 2; total -= 15; case 2: i
More informationMIT AITI Swing Event Model Lecture 17
MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications
More informationRAIK 183H Examination 2 Solution. November 11, 2013
RAIK 183H Examination 2 Solution November 11, 2013 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)
More informationRAIK 183H Examination 2 Solution. November 10, 2014
RAIK 183H Examination 2 Solution November 10, 2014 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)
More informationFirst Name: AITI 2004: Exam 2 July 19, 2004
First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan
More informationFirst Name: AITI 2004: Exam 2 July 19, 2004
First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: JSP Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand
More informationWe are on the GUI fast track path
We are on the GUI fast track path Chapter 13: Exception Handling Skip for now Chapter 14: Abstract Classes and Interfaces Sections 1 9: ActionListener interface Chapter 15: Graphics Skip for now Chapter
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationCMP 326 Midterm Fall 2015
CMP 326 Midterm Fall 2015 Name: 1) (30 points; 5 points each) Write the output of each piece of code. If the code gives an error, write any output that would happen before the error, and then write ERROR.
More informationIntroduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008
Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive
More informationSwing from A to Z Some Simple Components. Preface
By Richard G. Baldwin baldwin.richard@iname.com Java Programming, Lecture Notes # 1005 July 31, 2000 Swing from A to Z Some Simple Components Preface Introduction Sample Program Interesting Code Fragments
More informationCOMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)
1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002 (total 7 pages) Name: TA s Name: Tutorial: For Graders Question 1 Question 2 Question 3 Total Problem 1 (20 points) True or
More informationSystems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid
Systems Programming Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid Leganés, 21st of March, 2014. Duration: 75 min. Full
More informationQueen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb
Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb HAND IN Answers recorded on Examination paper This examination is THREE HOURS
More informationAttempt FOUR questions Marking Scheme Time: 120 mins
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
More informationH212 Introduction to Software Systems Honors
Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,
More informationSE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts
SE1021 Exam 2 Name: You may use a note-sheet for this exam. But all answers should be your own, not from slides or text. Review all questions before you get started. The exam is printed single-sided. Write
More informationSINGLE EVENT HANDLING
SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which
More informationCSE 143 Lecture 20. Circle
CSE 143 Lecture 20 Abstract classes Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; public double area() { return Math.PI * radius * radius; public
More informationParts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.
Parts of a Contract Syntax - Method signature Method name Parameter list Return type Semantics - Comments Preconditions: requirements placed on the caller Postconditions: what the method modifies and/or
More informationGoals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords
Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup
More informationOverview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008
Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object
More informationCMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2
Question 1 30 30 60 60 90 20 20 40 40 60 Question 2 a. b. public Song(String title, String artist, int length, String composer) { this.title = title; this.artist = artist; this.length = length; this.composer
More informationFinal Examination Semester 2 / Year 2011
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
More informationChapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver {
Chapter 21- Using Generics Case Study: Geometric Bunch In this example a class called GeometricBunch is made to wrap around a list of GeometricObjects. Circle and Rectangle are subclasses of GeometricObject.
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
Solution HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2010 FINAL EXAMINATION 2pm to 5pm, 19 APRIL 2010, Dunning Hall Instructor: Alan McLeod
More informationThis exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.
York University AS/AK/ITEC 2610 3.0 All Sections OBJECT-ORIENTED PROGRAMMING Midterm Test Duration: 90 Minutes This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for
More informationJRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();
Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button
More informationG51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread
G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ November Exam
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1016S / 1011H ~ 2009 November Exam Question
More informationGraphics User Defined Forms, Part I
Graphics User Defined Forms, Part I Quick Start Compile step once always mkdir labs javac PropertyTax5.java cd labs mkdir 5 Execute step cd 5 java PropertyTax5 cp /samples/csc/156/labs/5/*. cp PropertyTax1.java
More informationIntroduction This assignment will ask that you write a simple graphical user interface (GUI).
Computing and Information Systems/Creative Computing University of London International Programmes 2910220: Graphical Object-Oriented and Internet programming in Java Coursework one 2011-12 Introduction
More informationMidterm assessment - MAKEUP Fall 2010
M257 MTA Faculty of Computer Studies Information Technology and Computing Date: /1/2011 Duration: 60 minutes 1-Version 1 M 257: Putting Java to Work Midterm assessment - MAKEUP Fall 2010 Student Name:
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the
More informationCSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University
Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides
More informationCSIS 10A Assignment 7 SOLUTIONS
CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationAn array is a type of variable that is able to hold more than one piece of information under a single variable name.
Arrays An array is a type of variable that is able to hold more than one piece of information under a single variable name. Basically you are sub-dividing a memory box into many numbered slots that can
More informationFinal Examination Semester 2 / Year 2010
Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2010 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student
More informationBuilding a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver
Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components
More informationGUI Forms and Events, Part II
GUI Forms and Events, Part II Quick Start Compile step once always mkdir labs javac PropertyTax6.java cd labs Execute step mkdir 6 java PropertyTax6 cd 6 cp../5/propertytax5.java PropertyTax6.java Submit
More informationInterfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics
Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics 1 Collections (from the Java tutorial)* A collection (sometimes called a container) is simply an object that
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003 Name: E-mail Address: TA: Section: You have 3 hours to complete this exam. For coding questions,
More informationProject 1. LibraryTest.java. Yuji Shimojo CMSC 335
Project 1 LibraryTest.java Yuji Shimojo CMSC 335 April 1, 2012 1 Contents 1. Programs... 3 2. Execution Result... 10 3. Class Diagram... 11 4. Operating Instructions & Test Cases... 11 5. Test Data...
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More informationCSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012
CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012 Name: This exam consists of 6 problems on the following 8 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet
More informationGraphical User Interface
Lecture 10 Graphical User Interface An introduction Sahand Sadjadee sahand.sadjadee@liu.se Programming Fundamentals 725G61 http://www.ida.liu.se/~725g61/ Department of Computer and Information Science
More information1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003 Name: E-mail Address: TA: Section: You have 3 hours to complete this exam. For coding questions,
More informationFall 2011 Final Test
60-212 Fall 2011 Final Test Answer all questions You are allowed to bring in one unmarked textbook on Java and the 60-212 lecture slides (unmarked). No other material will be allowed. This test has 11
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationPractice Midterm 1. Problem Points Score TOTAL 50
CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the
More informationINTRODUCTION TO (GUIS)
INTRODUCTION TO GRAPHICAL USER INTERFACES (GUIS) Lecture 10 CS2110 Fall 2009 Announcements 2 A3 will be posted shortly, please start early Prelim 1: Thursday October 14, Uris Hall G01 We do NOT have any
More informationUniversity of Cape Town Department of Computer Science Computer Science CSC1017F
First Name: Last Name: Student Number: University of Cape Town Department of Computer Science Computer Science CSC1017F Class Test 4 - Solutions Wednesday, 17 May 2006 Marks: 40 Time: 40 Minutes Approximate
More informationGUI and its COmponent Textfield, Button & Label. By Iqtidar Ali
GUI and its COmponent Textfield, Button & Label By Iqtidar Ali GUI (Graphical User Interface) GUI is a visual interface to a program. GUI are built from GUI components. A GUI component is an object with
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod If the
More informationLab Assignment 13 (week 13)
Lab Assignment 13 (week 13) In this lab you are going to learn how to use the StringTokenizer class. Please look at the API for StringTokenizer at the below link. http://java.sun.com/j2se/1.4.2/docs/api/java/util/stringtokenizer.html
More informationCS-140 Fall 2018 Test 2 Version A Nov. 12, Name:
CS-140 Fall 2018 Test 2 Version A Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) X T F : A class in Java contains fields, and
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CMPE212, FALL TERM, 2012 FINAL EXAMINATION 18 December 2012, 2pm Instructor: Alan McLeod If the instructor is unavailable
More informationQueens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide
Topics for Exam 2: Queens College, CUNY Department of Computer Science CS 212 Object-Oriented Programming in Java Practice Exam 2 CS 212 Exam 2 Study Guide Linked Lists define a list node define a singly-linked
More information1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'
Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationSwing - JTextField. Adding a text field to the main window (with tooltips and all)
Swing - JTextField Adding a text field to the main window (with tooltips and all) Prerequisites - before this lecture You should have seen: The lecture on JFrame The lecture on JButton Including having
More informationName Section. CS 21a Introduction to Computing I 1 st Semester Final Exam
CS a Introduction to Computing I st Semester 00-00 Final Exam Write your name on each sheet. I. Multiple Choice. Encircle the letter of the best answer. ( points each) Answer questions and based on the
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, FALL TERM, 2013 FINAL EXAMINATION 7pm to 10pm, 18 DECEMBER 2013 Instructor: Alan McLeod If the instructor
More informationLecture 3: Java Graphics & Events
Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new
More informationThe Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324
The Islamic University Gaza Department of Electrical & Computer Engineering Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324 Instructor: Dipl.-Ing. Abdelnasser Abdelhadi Date: 31.03.2013
More informationPoints Missed on Page page 1 of 8
Midterm II - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Name: ID: Problem #1 (8 points) Rewrite the following code segment using a for loop instead of a while loop (that is
More informationCOMP-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 :) )
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 :) ) Course Evaluations Please do these. -Fast to do -Used to
More informationChapter 13 Lab Advanced GUI Applications
Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the
More informationUTM CSC207: Midterm Examination October 28, 2011
UTM CSC207: Midterm Examination October 28, 2011 Student Number: Last Name: First Name: This 110 minute exam consists of 6 double sided pages. You are allowed two 8 1 2 11 double sided aid sheets. 1. [10
More informationChapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus
Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
Solution HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2007 FINAL EXAMINATION 7pm to 10pm, 10 DECEMBER 2007, Jeffery Hall Instructor: Alan McLeod
More informationMultiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)
M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC124, WINTER TERM, 2009 FINAL EXAMINATION 7pm to 10pm, 18 APRIL 2009, Dunning Hall Instructor: Alan McLeod
More informationProctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.
HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2007 FINAL EXAMINATION 7pm to 10pm, 10 DECEMBER 2007, Jeffery Hall Instructor: Alan McLeod If the
More informationPackages: Putting Classes Together
Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic
More informationObject-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09
Object-Oriented Programming: Revision / Graphics / Subversion Inf1 :: 2008/09 Breaking out of loops, 1 Task: Implement the method public void contains2(int[] nums). Given an array of ints and a boolean
More informationLab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in
Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the
More informationJApplet. toy example extends. class Point { // public int x; public int y; } p Point 5.2. Point. Point p; p = new Point(); instance,
35 5 JApplet toy example 5.1 2 extends class Point { // public int x; public int y; Point x y, 5.2 Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 36 5 Point p = new Point();
More informationFinal Examination Semester 3 / Year 2008
Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2008 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE CLASS : CS08-A + CS08-B LECTURER
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ January Exam
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1016S / 1011H ~ 2009 January Exam Question
More informationTo gain experience using GUI components and listeners.
Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both
More informationAbstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof
Abstract Class Lecture 21 Based on Slides of Dr. Norazah Yusof 1 Abstract Class Abstract class is a class with one or more abstract methods. The abstract method Method signature without implementation
More informationIntroduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017
Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 11: Inheritance and Polymorphism Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad
More informationPractice Midterm 1 Answer Key
CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages
More informationLecture 5: Java Graphics
Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,
More informationChapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber
Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the
More informationThe JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class
CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical
More informationOriginal GUIs. IntroGUI 1
Original GUIs IntroGUI 1 current GUIs IntroGUI 2 Why GUIs? IntroGUI 3 Computer Graphics technology enabled GUIs and computer gaming. GUI's were 1985 breakout computer technology. Without a GUI there would
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationMore About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario
More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario The Story So Far... Classes as collections of fields and methods. Methods can access fields, and
More informationJava - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,
Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows
More informationDay before tests of Java Final test. IDM institution of Bandarawela. Project for department of education
Day before tests of Java Final test. IDM institution of Bandarawela Project for department of education import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Doenets extends JApplet
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationUniversity of Cape Town Department of Computer Science. Computer Science CSC117F Solutions
University of Cape Town Department of Computer Science Computer Science CSC117F Solutions Class Test 4 Wednesday 14 May 2003 Marks: 40 Approximate marks per question are shown in brackets Time: 40 minutes
More informationLab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!
Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars
More information