Computer Science II - Test 1

Size: px
Start display at page:

Download "Computer Science II - Test 1"

Transcription

1 Computer Science II - Test 1 Question 1. (15 points) a) For each of the access modifier keywords, what does each of them signify? public - private - protected - b) For each of the following programming constructs, which access modifier do we normally use and why? class - instance variable - method - c) For each of the following programming constructs, under what circumstances would we use a different access modifier that in part (b)? class - instance variable - method - 1

2 Question 2. (15 points) For each pair of concepts, briefly explain what they have in common and how they differ from each other. Be clear and concise in your answers. If it helps your answer, you may refer to specific examples in the code at the end of the exam. a) class vs. object b) class variable vs. instance variable c) extends vs. implements d) final vs. static e) behavior vs. implementation 2

3 Question 3. (5 points) What is the concept of information hiding? How does Java help us to implement the concept? Question 4. (5 points) What do we mean when we talk about Event-Driven Programming? Briefly discuss how event-driven programming was used in the CannonGame. Question 5 (10 points) Complete the following Java program that reads integers from the command-line and prints their sum to System.out. Recall that Integer.parseInt( ) can be used to convert from a String to an integer. The program would be run as java CalculateSum and print The sum is 28 to System.out. public class CalculateSum { public static void main( String[] args ) { // end main // end CalculateSum 3

4 Question 6. (25 points) Attached is my MyMemoDatebase solution to homework #3. When loading from the file, it calls the insert( ) method for each Key>>Value pair. If the Key is already in the database, the Key>>Value pair read from the file is thrown away. Below you are to rewrite the load method so that any duplicate Keys causes the corresponding Key>>Value pairs to be printed to a file named duplicates.dat. In other words, the load method will work the same, but it will generate a file containing Key>>Value pairs for Keys that are already in the datebase. 4

5 Question 7. (25 points) Attached is the code discussed in class for the CannonBall and CannonWorld. For the following two modifications, you do not have to completely rewrite the classes. Instead, you may: 1. write additional code on the existing code, and/or 2. write additional code for the class below, indicate in a comment for each block of code whether it replaces existing code or is added to existing code, and where the new code would go in the current code. a) Modify the class CannonBall so that the ball is colored blue when the ball is moving upward, and colored red when the ball is descending. b) Modify the CannonWorld program so that it maintains both a count of the number of balls fired and the number of times the target was hit. Display both of these values in the message area, as well as the angle of the cannon. 5

6 MyMemoDatabase: import java.io.*; import java.util.stringtokenizer; public class MyMemoDatabase implements MemoDatabase { private int MAX_SIZE = 100; // max. # of array elements private int memocount = 0; // count of the number of // MemoAssociations in the database private MemoAssociation [] associations; // reference to the array // containing the database // constructs an empty database public MyMemoDatabase() { Initialize(); // end MyMemoDatabase constructor // constructs an empty database with a max. size that's specified by // 'arraysize' public MyMemoDatabase( int arraysize ) { MAX_SIZE = arraysize; Initialize(); // end MyMemoDatabase constructor // helper method to aid in construction of a MyMemoDatabase private void Initialize() { associations = new MemoAssociation[MAX_SIZE]; memocount = 0; System.out.println("constructing a MyMemoDatabase object"); // end MyMemoDatabase constructor // Uses the 'savetofile' as the name of a file to write all of the // MemoAssociations in associations in the form key>>value. public void save( String savetofile ) throws IOException { PrintWriter outputfile = new PrintWriter( new FileWriter(saveToFile )); System.out.println("Saving to <" + savetofile + ">"); for (int i = 0; i < memocount; i++) { outputfile.println(associations[i].key()+ ">>" + associations[i].value()); System.out.println(associations[i].key()+ ">>" + associations[i].value()); // end for outputfile.flush(); outputfile.close(); // end save 6

7 // Uses the 'loadfromfile' as the name of a file to read into the // "associations" array. The 'loadfromfile' is assumed to be lines in the // form key>>value. Only entries with new keys from the file are added to the // array. public void load( String loadfromfile ) throws IOException { BufferedReader inputfile = new BufferedReader( new FileReader(loadFromFile) ); String buffer = null; String delimiters = ">"; while( true ) { buffer = inputfile.readline(); if ( buffer == null ) break; buffer = buffer.tolowercase(); StringTokenizer words = new StringTokenizer( buffer, delimiters ); String key = words.nexttoken(); String value = words.nexttoken(); if (words.hasmoreelements() ) { System.out.println("Invalid entry when loading from file " + loadfromfile + " Entry: " + buffer); else { insert(new MemoAssociation(key, value)); // end if // end while(true)... // end load // if newentry's key is already in the database or the database is full, // then the database is unmodified and 'false' is returned; // otherwise the 'newentry' is added to the database and 'true' is // returned. public boolean insert( MemoAssociation newentry ) { if ( memocount < MAX_SIZE && // if enough room and locatekey(newentry.key()) == -1 ) { // key not found associations[memocount] = newentry; memocount++; return true; else { return false; // end if // end insert // If 'key' is in the database, the associated 'value' is returned; // otherwise 'null' is returned. public String find( String key ) { int keyindex = locatekey( key ); if ( keyindex == -1) { return null; else { return associations[keyindex].value(); // end if // end find 7

8 // If 'key' is in the database, it is deleted and returns 'true'; // otherwise it returns 'false' and the array in unmodified. public boolean remove( String key ) { int keyindex = locatekey( key ); if (keyindex == -1) { // key not found return false; else { // slide associations over to remove the deleted key for (int i = keyindex+1;i < memocount; i++) { associations[i-1] = associations[i]; // end for memocount--; return true; // end if // end remove // returns 'true' if key is in the array; otherwise it returns 'false' public boolean containskey( String key ) { return (locatekey(key)!= -1); // end containskey // (a helper function) returns the index of the key if it is in // the array; otherwise it returns -1 private int locatekey( String key ) { for (int i = 0; i < memocount; i++) { if (key.equals(associations[i].key())) { return i; // end if // end for return -1; // end containskey // end class MyMemoDatabase 8

9 CannonGameDriver: public class CannonGameDriver { public static void main ( String[] args ) { CannonWorld world = new CannonWorld( ); world.show(); CannonWorld: import java.awt.*; import java.awt.event.*; public class CannonWorld extends Frame { public static final int FrameWidth = 600; public static final int FrameHeight = 400; private int angle; private String message; private CannonBall cannonball; private Scrollbar slider; public CannonWorld() { setsize ( FrameWidth, FrameHeight ); settitle( "Cannon Game" ); angle = 45; message = "Angle: " + angle; cannonball = null; slider = new Scrollbar( Scrollbar.VERTICAL, angle, 5, 0, 90 ); slider.addadjustmentlistener( new ScrollBarListener() ); add( "East", slider ); Button fire = new Button( "fire" ); fire.addactionlistener( new FireButtonListener() ); add( "North", fire ); // end CannonWorld constructor public static int dy( int y ) { return FrameHeight - y; // end dy public void paint( Graphics g ) { drawcannon ( g ); drawtarget ( g ); drawcannonball( g ); writemessage ( g ); // end paint /* helper methods */ protected void drawcannon( Graphics g ) { int x = 20; int y = 15; double radianangle = angle * Math.PI / 180.0; int lv = (int) (30 * Math.sin(radianAngle)); int lh = (int) (30 * Math.cos(radianAngle)); int sv = (int) (10 * Math.sin(radianAngle + Math.PI/2)); int sh = (int) (10 * Math.cos(radianAngle + Math.PI/2)); g.setcolor(color.green); g.drawline(x, dy(y), x+lh, dy(y+lv)); 9

10 g.drawline(x+lh, dy(y+lv), x+lh+sh, dy(y+lv+sv)); g.drawline(x+lh+sh, dy(y+lv+sv), x+sh, dy(y+sv)); g.drawline(x+sh, dy(y+sv), x, dy(y)); g.drawoval(x-8, dy(y+10), 12, 12); // end drawcannon protected void drawtarget( Graphics g ) { g.setcolor(color.red); g.fillroundrect( FrameWidth-100, dy(12), 50, 10, 6, 6 ); // end drawtarget protected void drawcannonball( Graphics g ) { if ( cannonball!= null ) { cannonball.move(); cannonball.paint( g ); try { Thread.sleep( 40 ); catch (InterruptedException e) { System.exit( 0 ); if ( dy(cannonball.y()) > 0 ) repaint(); else { int targetx = FrameWidth - 100; if ( (cannonball.x() > targetx) && (cannonball.x() < (targetx + 50)) ) message = "You Hit It!"; else message = "Missed!"; cannonball = null; // end if // end if // end drawcannonball protected void writemessage( Graphics g ) { g.drawstring( message, FrameWidth/2, FrameHeight/2 ); // end writemessage /* inner classes */ private class FireButtonListener implements ActionListener { public void actionperformed( ActionEvent e ) { double radianangle = angle * Math.PI / 180.0; double sinangle = Math.sin( radianangle ); double cosangle = Math.cos( radianangle ); cannonball = new CannonBall ( 20 + (int) (30 * cosangle), dy(5+(int) (30 * sinangle)), 5, 12 * cosangle, -12 * sinangle ); repaint(); // end actionperformed // end inner class FireButtonListener private class ScrollBarListener implements AdjustmentListener { public void adjustmentvaluechanged (AdjustmentEvent e) { angle = slider.getvalue(); message = "Angle: " + angle; repaint(); // end adjustmentvaluechanged // end inner class ScrollBarListener // end class CannonWorld 10

11 CannonBall: public class CannonBall extends MovableBall { public CannonBall (int sx, int sy, int r, double dx, double dy) { super(sx, sy, r, dx, dy); public void move () { setmotion( xmotion(), ymotion() ); super.move(); MovableBall: public class MovableBall extends Ball { private double dx; private double dy; public MovableBall( int x, int y, int r, double dx, double dy ) { super( x, y, r ); this.dx = dx; this.dy = dy; public void move() { region().translate( (int) dx, (int) dy ); protected void setmotion( double ndx, double ndy ) { dx = ndx; dy = ndy; protected double xmotion() { return dx; protected double ymotion() { return dy; // end MovableBall 11

12 Ball: import java.awt.color; import java.awt.graphics; import java.awt.rectangle; public class Ball { private Rectangle location; private Color color; public Ball( int x, int y, int r ) { location = new Rectangle( x-r, y-r, 2*r, 2*r ); color = Color.blue; public void paint( Graphics g ) { g.setcolor( color ); g.filloval( location.x, location.y, location.width, location.height ); public void setcolor( Color newcolor ) { color = newcolor; public Color color() { return color; protected int radius() { return location.width / 2; protected int x() { return location.x + radius(); protected int y() { return location.y + radius(); protected Rectangle region() { return location; protected void moveto( int x, int y ) { region().setlocation( x, y ); // end class Ball 12

Computer Science II - Test 2

Computer Science II - Test 2 Computer Science II - Test 2 Question 1. (15 points) The MouseListener interface requires methods for mouseclicked, mouseentered, mouseexited, mousepressed, and mousereleased. Java s MouseAdapter implements

More information

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1 Block I Unit 2 Basic Constructs in Java M301 Block I, unit 2 1 Developing a Simple Java Program Objectives: Create a simple object using a constructor. Create and display a window frame. Paint a message

More information

An Exercise. public class MovableBall extends Ball { private double dx; private double dy;

An Exercise. public class MovableBall extends Ball { private double dx; private double dy; An Exercise Suppose that we are writing a new program using objects from our Ball hierarchy. In this program, some MovableBalls must decelerate. Every time one of these decelerating balls moves, its speed

More information

Options for User Input

Options for User Input Options for User Input Options for getting information from the user Write event-driven code Con: requires a significant amount of new code to set-up Pro: the most versatile. Use System.in Con: less versatile

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice 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 information

Input from Files. Buffered Reader

Input from Files. Buffered Reader Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads

More information

4. Finding & Displaying Record of Salesman with minimum net income. 5. Finding & Displaying Record of Salesman with maximum net income.

4. Finding & Displaying Record of Salesman with minimum net income. 5. Finding & Displaying Record of Salesman with maximum net income. Solution of problem#55 of Lab Assignment Problem Statement: Design & Implement a java program that can handle salesmen records of ABC Company. Each salesman has unique 4 digit id #, name, salary, monthly

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

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

Name 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 information

Practice Midterm 1 Answer Key

Practice 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 information

Case Study: Savings Account Interest

Case Study: Savings Account Interest ecture 8 Loops: recap + example. Files: abstracting from a specific devise. Streams and Tokens. Examples. Material from the second half of Holmes Chapter 4. 1 w do you add up a sequence of numbers? = 1;

More information

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

CS 180 Final Exam Review 12/(11, 12)/08 CS 180 Final Exam Review 12/(11, 12)/08 Announcements Final Exam Thursday, 18 th December, 10:20 am 12:20 pm in PHYS 112 Format 30 multiple choice questions 5 programming questions More stress on topics

More information

Java - Dates and Threads

Java - Dates and Threads Java - Dates and Threads Thread example Java uses threads to allow 1 event to break into another. If an action is to occur a number of times with a loop or to occur until some condition is satisfied then

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

????? An Exercise. Suppose that we have written a class named Play that has a String instance variable named filename.

????? An Exercise. Suppose that we have written a class named Play that has a String instance variable named filename. An Exercise Suppose that we have written a class named Play that has a String instance variable named filename. A Plays respond to a startswith( char initial ) message by returning the number of Strings

More information

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2 CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,

More information

HST 952. Computing for Biomedical Scientists Lecture 8

HST 952. Computing for Biomedical Scientists Lecture 8 Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 8 Outline Vectors Streams, Input, and Output in Java

More information

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

Introduction 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 information

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,

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, 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 information

Final Exam May 21, 2003

Final Exam May 21, 2003 1.00 Introduction to Computers and Engineering Problem Solving Final Exam May 21, 2003 Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need

More information

Answer Key. 1. General Understanding (10 points) think before you decide.

Answer Key. 1. General Understanding (10 points) think before you decide. Answer Key 1. General Understanding (10 points) Answer the following questions with yes or no. think before you decide. Read the questions carefully and (a) (2 points) Does the interface java.util.sortedset

More information

RAIK 183H Examination 2 Solution. November 10, 2014

RAIK 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 information

Topic 8 Graphics. Margaret Hamilton

Topic 8 Graphics. Margaret Hamilton Topic 8 Graphics When the computer crashed during the execution of your program, there was no hiding. Lights would be flashing, bells would be ringing and everyone would come running to find out whose

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

CS193k, Stanford Handout #16

CS193k, Stanford Handout #16 CS193k, Stanford Handout #16 Spring, 99-00 Nick Parlante Practice Final Final Exam Info Our regular exam time is Sat June 3rd in Skilling Aud (our regular room) from 3:30-5:30. The alternate will be Fri

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - 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 information

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features: Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of

More information

CS61B Lecture #12. Today: Various odds and ends in support of abstraction.

CS61B Lecture #12. Today: Various odds and ends in support of abstraction. CS61B Lecture #12 Today: Various odds and ends in support of abstraction. Readings: At this point, we have looked at Chapters 1 9 of Head First Java. Today s lecture is about Chapters 9 and 11. For Friday,

More information

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using Java Provided Classes In this lesson we'll focus on using the Graphics class and its capabilities. This will serve two purposes: first

More information

A sample print out is: is is -11 key entered was: w

A sample print out is: is is -11 key entered was: w Lab 9 Lesson 9-2: Exercise 1, 2 and 3: Note: when you run this you may need to maximize the window. The modified buttonhandler is: private static class ButtonListener implements ActionListener public void

More information

H212 Introduction to Software Systems Honors

H212 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 information

CSPP : Introduction to Object-Oriented Programming

CSPP : Introduction to Object-Oriented Programming CSPP 511-01: Introduction to Object-Oriented Programming Harri Hakula Ryerson 256, tel. 773-702-8584 hhakula@cs.uchicago.edu August 7, 2000 CSPP 511-01: Lecture 15, August 7, 2000 1 Exceptions Files: Text

More information

M257 Past Paper Oct 2007 Attempted Solution

M257 Past Paper Oct 2007 Attempted Solution M257 Past Paper Oct 2007 Attempted Solution Part 1 Question 1 The compilation process translates the source code of a Java program into bytecode, which is an intermediate language. The Java interpreter

More information

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

First 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 information

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron Name: CSC143 Exam 1 1 CSC 143 Exam 1 Write also your name in the appropriate box of the scantron Name: CSC143 Exam 1 2 Multiple Choice Questions (30 points) Answer all of the following questions. READ

More information

A Simple Text Editor Application

A Simple Text Editor Application CASE STUDY 7 A Simple Text Editor Application To demonstrate the JTextArea component, fonts, menus, and file choosers we present a simple text editor application. This application allows you to create

More information

Preview from Notesale.co.uk Page 12 of 78

Preview from Notesale.co.uk Page 12 of 78 In JAVA run time environment, to perform any kind of operation or task or an action that will be performed with respect to either class or an interface. Whenever we pass invalid data as an input to the

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

Do not turn to the next page until the start of the exam.

Do not turn to the next page until the start of the exam. Principles of Java Language with Applications, PIC20a E. Ryu Winter 2017 Final Exam Monday, March 20, 2017 3 hours, 8 questions, 100 points, 11 pages While we don t expect you will need more space than

More information

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

Queens 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 information

Decisions: Logic Java Programming 2 Lesson 7

Decisions: Logic Java Programming 2 Lesson 7 Decisions: Logic Java Programming 2 Lesson 7 In the Java 1 course we learned about if statements, which use booleans (true or false) to make decisions. In this lesson, we'll dig a little deeper and use

More information

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

University of Cape Town ~ Department of Computer Science. Computer Science 1011H/1016S ~ 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 1011H/1016S ~ 2008 January Exam Question Max

More information

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

First 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 information

Your Final Bow. They would like to be able to combine tests, such as count all the 5-letter words that start with t.

Your Final Bow. They would like to be able to combine tests, such as count all the 5-letter words that start with t. Your Final Bow Last week, we learned about the Strategy pattern as a way to implement a Play class that can count the words in its text that satisfy an arbitrary test. The test is passed as an argument

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

Course overview: Introduction to programming concepts

Course overview: Introduction to programming concepts Course overview: Introduction to programming concepts What is a program? The Java programming language First steps in programming Program statements and data Designing programs. This part will give an

More information

Classes Basic Overview

Classes Basic Overview Final Review!!! Classes and Objects Program Statements (Arithmetic Operations) Program Flow String In-depth java.io (Input/Output) java.util (Utilities) Exceptions Classes Basic Overview A class is a container

More information

CSE 142 Sp02 Final Exam Version A Page 1 of 14

CSE 142 Sp02 Final Exam Version A Page 1 of 14 CSE 142 Sp02 Final Exam Version A Page 1 of 14 Basic reference information about collection classes that you may find useful when answering some of the questions. Methods common to all collection classes

More information

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything. Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access

More information

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 2 2 Develop the layout of those elements 3 3 Add listeners to the elements 9 4 Implement custom drawing 12 1 The StringArt Program To illustrate

More information

Topic 8 graphics. -mgrimes, Graphics problem report 134

Topic 8 graphics. -mgrimes, Graphics problem report 134 Topic 8 graphics "What makes the situation worse is that the highest level CS course I've ever taken is cs4, and quotes from the graphics group startup readme like 'these paths are abstracted as being

More information

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 3 2 Develop the layout of those elements 4 3 Add listeners to the elements 12 4 Implement custom drawing 15 1 The StringArt Program To illustrate

More information

Java Help Files. by Peter Lavin. May 22, 2004

Java Help Files. by Peter Lavin. May 22, 2004 Java Help Files by Peter Lavin May 22, 2004 Overview Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML

More information

CS 251 Intermediate Programming Java I/O Streams

CS 251 Intermediate Programming Java I/O Streams CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package

More information

ICS 4U. Introduction to Programming in Java. Chapter 10 Notes

ICS 4U. Introduction to Programming in Java. Chapter 10 Notes ICS 4U Introduction to Programming in Java Chapter 10 Notes Classes and Inheritance In Java all programs are classes, but not all classes are programs. A standalone application is a class that contains

More information

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file?

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file? CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7 Question 1. (2 points) What is the difference between a stream and a file? A stream is an abstraction representing the flow of data from one place to

More information

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes

Department of Civil and Environmental Engineering, Spring Semester, ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Department of Civil and Environmental Engineering, Spring Semester, 2013 ENCE 688R: Midterm Exam: 1 1/2 Hours, Open Book and Open Notes Name : Question Points Score 1 30 2 30 3 40 Total 100 1 Question

More information

Appendices Attached (2 pages) Two Hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM

Appendices Attached (2 pages) Two Hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM Appendices Attached (2 pages) COMP27010 Two Hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM Object Oriented Programming 2 Date: Monday 19

More information

Binghamton University. CS-140 Fall Data Types in Java

Binghamton University. CS-140 Fall Data Types in Java Data Types in Java 1 CS-211 2015 Example Class: Car How Cars are Described Make Model Year Color Owner Location Mileage Actions that can be applied to cars Create a new car Transfer ownership Move to a

More information

Chapter 4: Loops and Files

Chapter 4: Loops and Files Chapter 4: Loops and Files Chapter Topics Chapter 4 discusses the following main topics: The Increment and Decrement Operators The while Loop Using the while Loop for Input Validation The do-while Loop

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

//Initializes the variables that will hold the eventual final new versions of the string String pluralextension; String secondwordextension;

//Initializes the variables that will hold the eventual final new versions of the string String pluralextension; String secondwordextension; /* Jackson Baker Rogers High School Vowels-R-Us Final Project 12/15/14 */ import java.io.*; import java.util.stringtokenizer; public class Vowels //Variables needed for inputting outside file private static

More information

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently. UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING 1. What are Threads? A thread is a single path of execution of code in a program. A Multithreaded program contains two or more parts that can run concurrently.

More information

Midterm assessment - MAKEUP Fall 2010

Midterm 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 information

Garfield AP CS. Graphics

Garfield AP CS. Graphics Garfield AP CS Graphics Assignment 3 Working in pairs Conditions: I set pairs, you have to show me a design before you code You have until tomorrow morning to tell me if you want to work alone Cumulative

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: variables inside the object behavior: methods inside

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: Variables inside the object. behavior: Methods inside

More information

RAIK 183H Examination 2 Solution. November 11, 2013

RAIK 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 information

Input & Output in Java. Standard I/O Exception Handling

Input & Output in Java. Standard I/O Exception Handling Input & Output in Java Standard I/O Exception Handling Java I/O: Generic & Complex Java runs on a huge variety of plaforms to accomplish this, a Java Virtual Machine (JVM) is written for every type of

More information

Chapter 12: Inheritance

Chapter 12: Inheritance Chapter 12: Inheritance Objectives Students should Understand the concept and role of inheritance. Be able to design appropriate class inheritance hierarchies. Be able to make use of inheritance to create

More information

Chapter 3: Inheritance and Polymorphism

Chapter 3: Inheritance and Polymorphism Chapter 3: Inheritance and Polymorphism Overview Inheritance is when a child class, or a subclass, inherits, or gets, all the data (properties) and methods from the parent class, or superclass. Just like

More information

Do not turn to the next page until the start of the exam.

Do not turn to the next page until the start of the exam. Principles of Java Language with Applications, PIC20a E. Ryu Fall 2017 Final Exam Monday, December 11, 2017 3 hours, 8 questions, 100 points, 9 pages While we don t expect you will need more space than

More information

CN208 Introduction to Computer Programming

CN208 Introduction to Computer Programming CN208 Introduction to Computer Programming Lecture #11 Streams (Continued) Pimarn Apipattanamontre Email: pimarn@pimarn.com 1 The Object Class The Object class is the direct or indirect superclass of every

More information

Control Structures (Deitel chapter 4,5)

Control Structures (Deitel chapter 4,5) Control Structures (Deitel chapter 4,5) 1 2 Plan Control Structures ifsingle-selection Statement if else Selection Statement while Repetition Statement for Repetition Statement do while Repetition Statement

More information

Streams and File I/O

Streams and File I/O Chapter 9 Streams and File I/O Overview of Streams and File I/O Text File I/O Binary File I/O File Objects and File Names Chapter 9 Java: an Introduction to Computer Science & Programming - Walter Savitch

More information

IT101. File Input and Output

IT101. File Input and Output IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents

More information

Model Solutions. COMP 102: Test 1. 6 April, 2016

Model Solutions. COMP 102: Test 1. 6 April, 2016 Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 102: Test

More information

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG 11 2013 6 25 11.1.............................. 11 1 11.2.............................. 11 2 11.3................................... 11 5 11.4.............................. 11 6 11.5.......................................

More information

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight. If you spend more than the

More information

Lecture 3: Java Graphics & Events

Lecture 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 information

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so. CSE 143 Sp04 Midterm 2 Page 1 of 10 Reference information about some standard Java library classes appears on the last pages of the test. You can tear off these pages for easier reference during the exam

More information

RobotPlanning.java Page 1

RobotPlanning.java Page 1 RobotPlanning.java Page 1 import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; * * RobotPlanning - 1030 GUI Demonstration.

More information

) / Java ( )

) / Java ( ) 2002 3 2003.1.29 1 3 ( ) ( ) / Java ( ) 1 ( )? ( ) 2 (3 ) 3 Java Java Java (dynamic dispatch) ( ) import java.awt.*; import java.awt.event.*; public class Sample30 extends Frame { boolean go; double time;

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 9: Writing Java Applets Introduction Applets are Java programs that execute within HTML pages. There are three stages to creating a working Java

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

Chapter 4: Loops and Files

Chapter 4: Loops and Files Chapter 4: Loops and Files Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 4 discusses the following main topics: The Increment and Decrement

More information

F I N A L E X A M I N A T I O N

F I N A L E X A M I N A T I O N Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student

More information

Programming Assignment Comma Separated Values Reader Page 1

Programming Assignment Comma Separated Values Reader Page 1 Programming Assignment Comma Separated Values Reader Page 1 Assignment What to Submit 1. Write a CSVReader that can read a file or URL that contains data in CSV format. CSVReader provides an Iterator for

More information

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types Classes and objects A foundation for programming any program you might want to write objects functions and modules build even bigger programs and reuse code http://www.flickr.com/photos/vermegrigio/5923415248/

More information

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

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!

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! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

Java Primer. CITS2200 Data Structures and Algorithms. Topic 0

Java Primer. CITS2200 Data Structures and Algorithms. Topic 0 CITS2200 Data Structures and Algorithms Topic 0 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies and Interfaces Exceptions Generics Reading: Lambert

More information

package As7BattleShip;

package As7BattleShip; package As7BattleShip; Program: BattleshipBoard.java Author: Kevin Nider Date: 11/18/12 Description: Assignment 7: Runs the battleship game Input: ship placement board files and computer player type Output:

More information

Java Event Handling -- 1

Java Event Handling -- 1 Java Event Handling -- 1 Event Handling Happens every time a user interacts with a user interface. For example, when a user pushes a button, or types a character. 2 A Typical Situation: Scrollbar AWTEvent

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information