CSIS 10A Practice Final Exam Solutions

Similar documents
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

1 Definitions & Short Answer (5 Points Each)

User interfaces and Swing

PESIT Bangalore South Campus

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Chapter 1 GUI Applications

Dartmouth College Computer Science 10, Fall 2015 Midterm Exam

UCLA PIC 20A Java Programming

CS 101 Spring 2007 Midterm 2 Name: ID:

COMP 102: Test 2 Model Solutions

EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS

Happy Cinco de Mayo!!!!

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

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

Computer Science 210: Data Structures. Intro to Java Graphics

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Happy Cinco de Mayo!!!!

H212 Introduction to Software Systems Honors

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

McGill University School of Computer Science COMP-202A Introduction to Computing 1

GUI in Java TalentHome Solutions

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

CS 101 Exam 2 Spring Id Name

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1)

NITI NITI I PRIORITET

Chapter 10. Further Abstraction Techniques

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

University of Palestine. Mid Exam Total Grade: 100

I. True/False: (2 points each)

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

Sample Examination Paper Programming and Software Development

1. Find the output of following java program. class MainClass { public static void main (String arg[])

THE UNIVERSITY OF AUCKLAND

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

Lecture 13: Two- Dimensional Arrays

SCOPE. public class ABC { public static void main( String args [ ] ) { Not accessible outside the block. Local to this block; accessible within it

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

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

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

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

1 Short Answer (5 Points Each)

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Java Programming Unit 4. Abstract Classes, Interfaces, Polymorphism

1 Short Answer (10 Points Each)

BLOCK STRUCTURE. class block main method block do-while statement block if statement block. if statement block. Block Structure Page 1

Notes on Chapter Three

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

CS 101 Fall 2006 Midterm 3 Name: ID:

Programming Languages and Techniques (CIS120)

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

CSE 11 Midterm Fall 2008

CSC142, Computer Science II, Project 5 (2 nd submission)

Review of Object-Oriented Concepts in JAVA

AP COMPUTER SCIENCE A

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

Admin. CS 112 Introduction to Programming. Recap: OOP Analysis. Software Design and Reuse. Recap: OOP Analysis. Inheritance

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

Some Sample AP Computer Science A Questions - Solutions

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

Chapter 4: Control structures. Repetition

Give one example where you might wish to use a three dimensional array

REVIEW EXERCISES. Draw an inheritance diagram that shows the relationships between these classes.

1 Short Answer (10 Points Each)

Course Outline. Introduction to java

CSIS 10A Assignment 4 SOLUTIONS

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST

Programming Languages and Techniques (CIS120)

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Loops. CSE 114, Computer Science 1 Stony Brook University

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

class objects instances Fields Constructors Methods static

Programming Languages and Techniques (CIS120)

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

STUDENT LESSON A12 Iterations

EXAMINATIONS 2008 END-OF-YEAR COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

APCS Semester #1 Final Exam Practice Problems

PASS4TEST IT 인증시험덤프전문사이트

javax.swing.jbutton upbutton = new javax.swing.jbutton("up"); upbutton.addactionlistener(new UpListener(_drawing)); row.

Solutions to the 2005 exam

University of Massachusetts Amherst, Electrical and Computer Engineering

Chapter 4: Control structures

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Conditionals, Loops, and Style

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Practice Midterm 1. Problem Points Score TOTAL 50

BBM 102 Introduction to Programming II Spring Abstract Classes and Interfaces

It is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff();

Transcription:

CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!= 8 && b > 5) c = 8; // false // true // true System.out.println(a + " " + b + " " + c); OUTPUT: 2 8 8 2) (5 points) Complete the next 4 lines of the trace table for the following code: int sum = 0, m = 10; for (int k=0; k<10; k=k+2){ sum = sum + m; m = m - 2; sum m k k<10 0 10 0 T 10 8 2 T 18 6 4 T 24 4 6 T 28 2 8 T 3) (10 points) What will be displayed on the terminal by the following nested loop? for (int k = 1; k < 3; k ++ ){ for (int m = 0; m < k ; m ++){ System.out.print( m ); System.out.println(); A trace is a good way to do this. Here is what happens in the loop: k k<3 m m<k Print Therefore the 1 T 0 T 0 output is: 2 T 1 F new line 0 0 T 0 01 1 T 1 2 F new line

4) (20 points) Here is a class for representing Employees at a work place. Complete the constructor and the three methods indicated according to the javadoc comments provided. You don't have to write the javadocs Constructor Summary Employee(String name, double wage) creates a new Employee object with a given name, and hourly wage. Method Summary String getname() returns the name of the employee void setwage(int newwage) changes the wage to newwage double calcpaycheck(double hours) returns the pay check for an employee based on the hourly wage times the number of hours public class Employee { // instance variables private String name; // employee name private double hourlywage; // employee wage // constructor public Employee(String name, double wage){ this.name = name; hourlywage = wage; // getname public String getname(){ return name; // setwage public void setwage(int newwage){ hourlywage = newwage; // calcpaycheck public double calcpaycheck(int hours){ return hours*hourlywage; 4) (5 points) Complete the folowing test app to print out the pay check for Employee e (just 2 lines of code) public class EmployeeApp { public static void main(string [] args){ Employee e = Employee("Ben", 25); double pay; // a)calculate pay given that Ben worked 10 hours and store in pay pay = e.calcpaycheck(10); // b)print the pay for Ben System.out.pritln("Pay = " + pay);

6) (10 points) Draw a map of memory after the following statements execute: Employee a = new Employee("Gil", 25); Employee b = new Employee("Jan",30); Employee c = b; c.setwage(40); 7) (10 points) Suppose that a company has 500 employees and that information about all the employees has already been stored in an array Employee [] workers = new Employee[500]; Write a code segment that will: a) Print the names of all the employees in the company for (int k = 0; k < workers.length; k++) System.out.println( workers[k].getname() ); b) Compute and print the sum of all pay checks for the entire company, assuming everyone worked 40 hours. Print just one number, the sum of all the paychecks. double sum = 0; for (int k = 0; k < workers.length; k++) sum = sum + workers.calcpaycheck(40); System.out.println("total payroll = " + sum); 8) (10 points) Suppose we have an array of int declared with the following values: int [] data = {7, 5, 1, 2, 4, 5, 3, 6; and, we execute the statements: for (int k = 0; k<7 ; k++) { data[k] = data[k+1]; Please draw the data array after the statements have completed: When k = 0 we have data[0] = data[1] // cell 0 gets 5 (value in cell 1) When k = 1 we have data[1] = data[2] // cell 1 gets 1 (value in cell 2) continuing until k = 6 we have data[6] = data[7] // cell 6 gets 6 (value in cell 7) so the array has become: 5 1 2 4 5 3 6 6

9) (10 points) We've created a 2D array of integers int[][] table = new int[3][4]; Fill in the values contained in the table after the following statements execute: for (int row=0; row<3; row++){ for (int col=0; col<4; col++){ if (col == 2) table[row][col] = 7; else table[row][col] = 0; table

10) (15 points) Complete the following short applet. When it starts up, the applet should display the message "Falling" at location 100,100. Whenever the user clicks on the applet, the message should move down the screen 10 pixels. Use the paint() method to display the message. You will need to add an instance variable to keep track of the vertical location of the message. class Falling extends Applet implements MouseListener { private int ymessage; // the y value for the message public void init() { ymessage = 100; // start message with a 100 pixel off from top addmouselistener(this); public void paint(graphics g) { g.drawstring("falling",100,y); ; public void mousepressed(mouseevent evt) { ymessage = ymessage + 10; // moves down 10 pixels repaint(); ; public void mousereleased(mouseevent evt) { // Junk required by public void mouseclicked(mouseevent evt) { // the MouseListener public void mouseentered(mouseevent evt) { // interface. public void mouseexited(mouseevent evt) { // end class Falling