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

Size: px
Start display at page:

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

Transcription

1 CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2015 Name: Question Value 1 10 Score TOTAL 100 Please answer questions in the spaces provided. If you make a mistake or for some other reason need more space, please use the back of and clearly indicate where the answer can be found. Good luck and best wishes for a wonderful summer!

2 1. ( / 10) What gets printed? Please show output as it will appear, or indicate NO OUTPUT, or show some of the output followed by INFINITE LOOP. int a = 5; Output: do a--; System.out.println(a); while (a >= 6) System.out.println("Done: " + a); Output: for (int a = 4; a > 0; a++) System.out.println(a * 2); System.out.println("Done: " + a); String[] notes = "do", "re", "mi"; for (String st: notes) System.out.println(st + st); Output: System.out.println("Done: "); for(int a = 1; a <= 3; a++) for (int b = 5; b <= 6; b++) System.out.println(a + "\t" + b); Output: System.out.println("Done");

3 2. ( / 10) a) Show what gets printed and rewrite using if/else: char ch = 'n'; System.out.print ("The answer is "); switch(ch) case 'y': System.out.println ("positive."); break; case 'N': System.out.println ("negative."); break; default: System.out.println ("unclear."); Output: Using if/else: 2. Show what gets printed and rewrite using while and if/else (i.e., eliminate the for and conditional operator): for (int a = 0; a < 4; a++) System.out.println(a + (a % 2 == 0? " yes": " no ")); Using while and if/else: Output:

4 3. ( / 10) Consider the following program: import java.util.scanner; import java.io.*; public class FinalS15FileIO public static void main(string[] args) throws IOException Scanner infile; PrintWriter outfile; infile = new Scanner (new File("data-in.txt")); outfile = new PrintWriter("data-out.txt"); while (infile.hasnext()) String line = infile.nextline(); Scanner scan = new Scanner(line); int count = 0; while (scan.hasnext()) String token = scan.next(); count ++; outfile.println(count); outfile.close(); a) Suppose the file data-in.txt is used as the input file. Show the contents of the file data-out.txt after execution of the program. b) List two examples of situations that could cause IOExceptions in the above code. c) Suppose you want to catch and handle the IOExceptions using the following catch clause: catch (IOException e) System.out.println("Warning: problem with IO. Run interactively."); infile = new Scanner(System.in); outfile = new PrintWriter(System.out); (i.e., keep running, but issue a warning and do interactive I/O instead) Show how to incorporate this in the above program: 1) Draw a box around the statements of the above program that you would include in the try block, and 2) mark the position where you would insert the catch code.

5 4. ( / 10) (a) Write a Java method findmax() with one parameter that is a 2D array of double, that finds and returns the largest of all the values in the 2D array. Assume that all the values will be positive. There may be repetitions, but it should not matter, the method should still return a value that is no less than any of the other values. The method should have one parameter (the 2D array of double) and it should return a double, and not print anything. (b) Assume findmax() is defined as a static method in the class below. Complete the code of main() below to use findmax so as to print the largest of the numbers stored in either of the arrays a and b (i.e., the largest number overall). public class ThisIsATest public static void main(string[] args) double[][] a =... (arrays are initialized with some values) double[][] b =... //**** print the largest value stored in either a or b

6 5. ( / 10). (a) Show the output produced by the following code fragment: String mess = ""; char[] grades = 'A', 'B', 'C', 'D', F'; for (char ch: grades) mess = ch + mess; System.out.println (mess); (b) Show the output produced by the following code fragment: char[] grades = 'A', 'B', 'C', 'D', F'; for (char ch: grades) System.out.print ((char) (ch + 1)); (c) Suppose an int array ratings contains values in the range 0-3. Write a code fragment that creates an array count that contains the frequency of occurrences of 0 s, 1 s, 2 s and 3 s in the ratings array, and then prints this information. Example: if the array ratings has these contents: ratings Your code should create the array count with the following contents: count and the output would be: Count for 0: 1 Count for 1: 1 Count for 2: 4 Count for 3: 1 Write your code fragment below. Assume the array ratings is already initialized to some values. Your code should work for any size array.

7 6. ( / 10) Suppose you have a Die class defined as follows: import java.awt.*; public class Die private int facevalue; // current value showing on the die // Constructor: Sets the initial face value. public Die() facevalue = 1; // Rolls the die and returns the result. public int roll() facevalue = (int)(math.random() * 6) + 1; return facevalue; ç Write your answer on facing page (back of previous page). ç // Face value mutator. public void setfacevalue (int value) facevalue = value; // Face value accessor. public int getfacevalue() return facevalue; // Returns a string representation of this die. public String tostring() String result = Integer.toString(faceValue); return result; // Draws the die on page at position x, y. public void draw (Graphics page, int x, int y) page.setcolor (Color.white); page.fillrect (x, y, 30, 30); page.setcolor (Color.black); page.drawstring(integer.tostring(facevalue), x+10, y+20); On the facing page, write the Java code for a driver class that uses the Die class to determine how likely it is to roll snake eyes, i.e., two ones. Use the following approach: Ø Declare and instantiate two Die objects, die1 and die2 Ø Roll them 10,000 times (or some sufficiently large number, specified by a constant in your program) while keeping track of how many times you rolled ones on both dice Ø In the end, print how many times the dice were rolled, the number of snake eyes, and proportion of snake eyes (i.e., probability). Careful: use a cast when dividing integers!

8 7. ( / 10) Suppose you have a Passenger class defined as follows to represent passengers in the Titanic: public class Passenger // instance data private int status; private boolean child; private char sex; private boolean survivor; // constructor public Passenger(int status, boolean child, char sex, boolean survivor) this.status = status; this.child = child; this.sex = sex; this.survivor = survivor; // tostring() returns String description of Passenger public String tostring() String pass = ""; switch (status) case 1: pass += "1st class\t"; break; case 2: pass += "2nd class\t"; break; case 3: pass += "3rd class\t"; break; case 4: pass += "crew\t"; break; pass += (child? "child": "adult") + "\t"; pass += ((sex == 'm')? "male" : "female") + "\t"; pass += (survivor? "survived": "perished"); return pass; On the next page, write the code for a PassengerCollection class to represent the list of passengers of the Titanic and to keep track of total number of passengers and survivors, using an array of Passenger objects. Some bits of the code and comments are already written. Use these comments as guidelines for your code, in the spaces provided on the next page. Note that you only need to implement the constructor and addpassenger() methods, which should initialize and update, respectively, the array and the two counts (i.e., count and numsurvivors).

9 (Question 7, continued) public class PassengerCollection private Passenger[] collection; private int count; private int numsurvivors; // additional count: survivors // // Constructor: Creates an initially empty collection // with space for up to 5000 passengers. // Initializes count and numsurvivors appropriately. // // // Method addpassenger(): Adds a Passenger to the // collection. Update // count and numsurvivors. // public void addpassenger (int status, boolean child, char sex, boolean survivor)

10 8. ( / 10) Construct an algorithm that inputs an integer num and 10,000 other integers and prints a message indicating whether num was found among the 10,000 other integers, followed by a goodbye message. Hint: You need to use a boolean variable found to keep track of whether you found a match. Example: If num (i.e., the first number input) is 1318, and 10,000 other numbers are input after that, none of which is equal to 1318, the algorithm should print: Searching for 1318 Not found Goodbye Alternatively, if the number 1318 occurred one or more times among the other numbers, it should print: Searching for 1318 Found it! Goodbye Directions: Write your algorithm by rearranging and structuring elements chosen from the list below, using indentation to show structure. Do not use anything else and note that not all of these are needed, but you may use one of them more than once, if necessar found = true found = false input num input x count = 1 count = count + 1 x = x + 1 if (x == num) if (found) if (found == true) if (found == false) if (x!=num) else while (count <= 10000) while (num <= 10000) while (count <= num) print Searching for num print x print num print Found it! print Not found print Goodbye

11 9. ( / 20) Write a complete Java program consisting of a datatype Cat and a client CrazyCatLady and draw a UML class diagram for your classes. Example: Ø Name: Henri Ø Age: 7 Ø Lives: 5 a) The Cat class should have the following methods: Constructor: One parameter (for the name). Sets Cat s age to 0 and lives to 9. birthday(): increases age of Cat by 1. death(): decreases the Cat s number of lives by 1. tostring(): returns a String corresponding to this Cat. getage(): returns this Cat s age draw(graphics page, int x, int y): draws this Cat in the current Graphics context at position x, y. Please do not do anything fancy here: just draw a simple shape to represent the cat and add its name nearby.add another feature such as color or different shape to depict the age or number of lives (you only need to do one of them). b) The client CrazyCatLady should implement the following algorithm: o Instantiate three variables of the Cat class named cat1, cat2, cat3 (Kindly make up funny names for them I m spending my holidays grading this exam! J ) o Print the info of cat1, cat2, cat3 Let s pretend that two years have gone by So the Cats ages need to increase. Also, cat3 has done something stupid and loses a life. Write some code that uses the birthday() and death() methods to model this situation. o Print the info of cat1, cat2, cat3 (again). o Calculate and print the average age of the cats. o NOTE: this is not a graphical class, so it does NOT use the draw() method at all. c) Draw a UML class diagram depicting the classes Cat and CrazyCatLady. Write the complete code for the two classes and UML diagram in the next 3 pages. It is NOT necessary to include comments with your code, but be sure to use good indentation. è è è

12

13

14

15

16

17

CSC 1051 Algorithms and Data Structures I. Final Examination December 17, Name:

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

More information

CSC 1051 Algorithms and Data Structures I. Final Examination December 18, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination December 18, Name: CSC 1051 Algorithms and Data Structures I Final Examination December 18, 2015 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

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

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2016 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

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name: KEY. Question Value Score CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name: KEY 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

More information

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

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: Question Value Score CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2016 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

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

CSC 1051 Algorithms and Data Structures I. Final Examination December 20, Name: KEY. Question Value Score CSC 1051 Algorithms and Data Structures I Final Examination December 20, 2016 Name: KEY 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

More information

Happy Cinco de Mayo!!!!

Happy Cinco de Mayo!!!! CSC 1051 Algorithms and Data Structures I Happy Cinco de Mayo!!!! Final Examination May 5, 2018 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1 CSC 1051 Algorithms and Data Structures I Midterm Examination February 24, 2014 Name: KEY 1 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

More information

Happy Cinco de Mayo!!!!

Happy Cinco de Mayo!!!! CSC 1051 Algorithms and Data Structures I Happy Cinco de Mayo!!!! Final Examination May 5, 2018 Name: KEY Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY CSC 1051 Algorithms and Data Structures I Midterm Examination October 9, 2014 Name: KEY 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

More information

// constructor: takes a String as parameter and creates a public Cat (String x) { name = x; age = 0; lives = 9; // cats start out with 9 lives }

// constructor: takes a String as parameter and creates a public Cat (String x) { name = x; age = 0; lives = 9; // cats start out with 9 lives } Quiz 6 Name: 1. Suppose you have a class Cat defined as shown below. Fill in the code for the indicated methods, following guidelines given through comments. public class Cat // instance variables String

More information

Assignment 1 due Monday at 11:59pm

Assignment 1 due Monday at 11:59pm Assignment 1 due Monday at 11:59pm The heart of Object-Oriented Programming (Now it gets interesting!) Reading for next lecture is Ch. 7 Focus on 7.1, 7.2, and 7.6 Read the rest of Ch. 7 for class after

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A CSC 1051 Algorithms and Data Structures I Midterm Examination February 25, 2016 Name: KEY A 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

More information

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name: CSC 1051-001 Algorithms and Data Structures I Midterm Examination February 25, 2016 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

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key CSC 1051 Algorithms and Data Structures I Midterm Examination February 26, 2015 Name: Key Question Value 1 10 Score 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

More information

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1 Designing Classes Where do objects come from? 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/

More information

Where do objects come from? Good question!

Where do objects come from? Good question! Designing Classes 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/ Where do objects

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 7, 2013 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

More information

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Designing Classes 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/ Where do objects

More information

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

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Designing Classes 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/ Where do objects

More information

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. 1 COE 212 Engineering Programming Welcome to Exam II Thursday April 21, 2016 Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY CSC 1051 Algorithms and Data Structures I Midterm Examination October 11, 2018 Name: KEY Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make

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

Recitation: Loop Jul 7, 2008

Recitation: Loop Jul 7, 2008 Nested Loop Recitation: Loop Jul 7, 2008 1. What is the output of the following program? Use pen and paper only. The output is: ****** ***** **** *** ** * 2. Test this program in your computer 3. Use "for

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 6, 2016 Name: Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make a

More information

Selection Statements and operators

Selection Statements and operators Selection Statements and operators 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/

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination March 2, 2017 Name: Question Value Score 1 10 2 10 3 20 4 20 5 20 6 20 TOTAL 100 Please answer questions in the spaces provided. If you make

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are

More information

Introduction to the Java Basics: Control Flow Statements

Introduction to the Java Basics: Control Flow Statements Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared

More information

Designing Classes part 2

Designing Classes part 2 Designing Classes part 2 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/ Getting

More information

Chapter 4: Writing Classes

Chapter 4: Writing Classes Chapter 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Writing Classes We've been using predefined classes. Now we will learn to write our own

More information

Selection and Repetition Revisited

Selection and Repetition Revisited Selection and Repetition Revisited 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/

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

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

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max

More information

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday

More information

Java I/O and Control Structures

Java I/O and Control Structures Java I/O and Control Structures CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A CSC 1051 Algorithms and Data Structures I Midterm Examination March 1, 2018 Name: KEY A Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make

More information

Anatomy of a Class Encapsulation Anatomy of a Method

Anatomy of a Class Encapsulation Anatomy of a Method Writing Classes Writing Classes We've been using predefined classes. Now we will learn to write our own classes to define objects Chapter 4 focuses on: class definitions instance data encapsulation and

More information

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,

More information

CS1083 Week 2: Arrays, ArrayList

CS1083 Week 2: Arrays, ArrayList CS1083 Week 2: Arrays, ArrayList mostly review David Bremner 2018-01-08 Arrays (1D) Declaring and using 2D Arrays 2D Array Example ArrayList and Generics Multiple references to an array d o u b l e prices

More information

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects Writing Classes 4 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Writing Classes We've been using predefined

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

Java I/O and Control Structures Algorithms in everyday life

Java I/O and Control Structures Algorithms in everyday life Introduction Java I/O and Control Structures Algorithms in everyday life CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Source: http://xkcd.com/627/

More information

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1 Designing Classes Where do objects come from? 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/

More information

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018 1 COE 212 Engineering Programming Welcome to Exam II Tuesday November 28, 2018 Instructors: Dr. Dima El-khalil Dr. Jawad Fahs Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

More information

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation. Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop

More information

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.

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. Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following

More information

University of Massachusetts Amherst, Electrical and Computer Engineering

University of Massachusetts Amherst, Electrical and Computer Engineering University of Massachusetts Amherst, Electrical and Computer Engineering ECE 122 Midterm Exam 1 Makeup Answer key March 2, 2018 Instructions: Closed book, Calculators allowed; Duration:120 minutes; Write

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

CPSC 219 Extra review and solutions

CPSC 219 Extra review and solutions CPSC 219 Extra review and solutions Multiple choice questions: Unless otherwise specified assume that all necessary variable declarations have been made. For Questions 1 6 determine the output of the print()

More information

Chapter 3. Selections

Chapter 3. Selections Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of

More information

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

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Test 2 Question Max Mark Internal

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

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

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

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

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 ); Sample Final Exam 1. Evaluate each of the following expressions and show the result and data type of each: Expression Value Data Type 14 % 5 1 / 2 + 1 / 3 + 1 / 4 4.0 / 2.0 Math.pow(2.0, 3.0) (double)(2

More information

Selection Statements and operators

Selection Statements and operators Selection Statements and operators 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/

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

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations. Data Structures 1 Data structures What is a data structure? Simple answer: a collection of data equipped with some operations. Examples Lists Strings... 2 Data structures In this course, we will learn

More information

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

Section 002 Spring CS 170 Exam 1. Name (print): Instructions: CS 170 Exam 1 Section 002 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012 1 COE 211/COE 212 Computer/Engineering Programming Welcome to Exam II Thursday December 20, 2012 Instructor: Dr. George Sakr Dr. Wissam F. Fawaz Dr. Maurice Khabbaz Name: Student ID: Instructions: 1. This

More information

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination Monday, March 9, 2009 Examiners: Mathieu Petitpas [Section 1] 18:30

More information

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

AP COMPUTER SCIENCE A

AP COMPUTER SCIENCE A AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks

More information

CSE 1223: Exam II Autumn 2016

CSE 1223: Exam II Autumn 2016 CSE 1223: Exam II Autumn 2016 Name: Instructions: Do not open the exam before you are told to begin. This exam is closed book, closed notes. You may not use any calculators or any other kind of computing

More information

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops. CSE 114, Computer Science 1 Stony Brook University Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?

More information

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013 1 COE 212 Engineering Programming Welcome to Exam II Monday May 13, 2013 Instructors: Dr. Randa Zakhour Dr. Maurice Khabbaz Dr. George Sakr Dr. Wissam F. Fawaz Name: Solution Key Student ID: Instructions:

More information

Selection and Repetition Revisited

Selection and Repetition Revisited Selection and Repetition Revisited 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/

More information

Problem Grade Total

Problem Grade Total CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) 1 Short Answer (10 Points Each) 1. Write a for loop that will calculate a factorial. Assume that the value n has been input by the user and have the loop create n! and store it in the variable fact. Recall

More information

Selection and Repetition

Selection and Repetition Selection and Repetition Revisited 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/

More information

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 3 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

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

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Supplementary Examination Question

More information

Advanced Java Concept Unit 1. Mostly Review

Advanced Java Concept Unit 1. Mostly Review Advanced Java Concept Unit 1. Mostly Review Program 1. Create a class that has only a main method. In the main method create an ArrayList of Integers (remember the import statement). Add 10 random integers

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

CS 101 Exam 2 Spring Id Name

CS 101 Exam 2 Spring Id Name CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

Instance Method Development Demo

Instance Method Development Demo Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write

More information

Controls Structure for Repetition

Controls Structure for Repetition Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power

More information

Last Class. While loops Infinite loops Loop counters Iterations

Last Class. While loops Infinite loops Loop counters Iterations Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();

More information

CSCI 1226 Sample Midterm Exam

CSCI 1226 Sample Midterm Exam CSCI 1226 Test #1 February 2017 General Instructions CSCI 1226 Sample Midterm Exam (A bit long since it combines parts of three earlier tests) Read and follow all directions carefully. Name: Student #:

More information

Name: Checked: Preparation: Investment Calculator with input and output to text files Submit through Blackboard by 8:00am the morning of Lab.

Name: Checked: Preparation: Investment Calculator with input and output to text files Submit through Blackboard by 8:00am the morning of Lab. Lab 14 Name: Checked: Objectives: Practice handling exceptions and writing text files. Preparation: Investment Calculator with input and output to text files Submit through Blackboard by 8:00am the morning

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

CMP 326 Midterm Fall 2015

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

Principles of Computer Science I

Principles of Computer Science I Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120A - Fall 2004 Lecture Unit 7 Review Chapter 4 Boolean data type and operators (&&,,) Selection control flow structure if, if-else, nested

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

WES-CS GROUP MEETING #9

WES-CS GROUP MEETING #9 WES-CS GROUP MEETING #9 Exercise 1: Practice Multiple-Choice Questions 1. What is output when the following code executes? String S1 = new String("hello"); String S2 = S1 +! ; S1 = S1 + S1; System.out.println(S1);

More information

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 There are 5 problems on the exam, with 56 points total available. There are 10 pages to the exam (5 pages

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

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CS212 Midterm. 1. Read the following code fragments and answer the questions. CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");

More information

Name: Checked: Preparation: Write the output of DeckOfCards.java to a text file Submit through Blackboard by 8:00am the morning of Lab.

Name: Checked: Preparation: Write the output of DeckOfCards.java to a text file Submit through Blackboard by 8:00am the morning of Lab. Lab 14 Name: Checked: Objectives: Practice handling exceptions and writing text files. Preparation: Write the output of DeckOfCards.java to a text file Submit through Blackboard by 8:00am the morning of

More information

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

COE 212 Engineering Programming. Welcome to Exam II Friday November 27, 2015

COE 212 Engineering Programming. Welcome to Exam II Friday November 27, 2015 1 COE 212 Engineering Programming Welcome to Exam II Friday November 27, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

More information

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius

More information

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise Tutorial # 4 Q1. Evaluate the logical (Boolean) expression in the following exercise 1 int num1 = 3, num2 = 2; (num1 > num2) 2 double hours = 12.8; (hours > 40.2) 3 int funny = 7; (funny!= 1) 4 double

More information

Name:... ID:... class A { public A() { System.out.println( "The default constructor of A is invoked"); } }

Name:... ID:... class A { public A() { System.out.println( The default constructor of A is invoked); } } KSU/CCIS/CS CSC 113 Final exam - Fall 12-13 Time allowed: 3:00 Name:... ID:... EXECRICE 1 (15 marks) 1.1 Write the output of the following program. Output (6 Marks): class A public A() System.out.println(

More information

This exam is open book. Each question is worth 3 points.

This exam is open book. Each question is worth 3 points. This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or

More information

Algorithms and Conditionals

Algorithms and Conditionals Algorithms and Conditionals 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/

More information

Practice Problems: Instance methods

Practice Problems: Instance methods Practice Problems: Instance methods Submit your java files to D2L. Late work will not be acceptable. a. Write a class Person with a constructor that accepts a name and an age as its argument. These values

More information

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully. General Instructions Read and follow all directions carefully. CSCI 1226 A Test #1 Wednesday, 10 October, 2018 Name: Student #: When writing programs or program segments, use the conventions used in the

More information