1 Definitions & Short Answer (5 Points Each)

Size: px
Start display at page:

Download "1 Definitions & Short Answer (5 Points Each)"

Transcription

1 Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work will receive no credit. 1 Definitions & Short Answer (5 Points Each) 1. Explain the difference between high-level languages and machine language. 2. What is the difference between a compiler and an interpreter? Also, discuss Java s method. 3. Java is a platform-independent language. What is a platform, what does platform-independent mean, and how does Java attain its platform independence? 1

2 4. What are the three types of programming errors? Briefly describe each of them. 5. What is the scope of a method/function parameter? 6. What is method/function overloading? How is it done in Java? 7. What is the difference between a Java applet and a Java application? Specifically, what runs each of them and what is the main coding difference between the two? 2

3 2 Program Traces (15 Points Each) 1. Write the output of the following program for each of the three inputs. 1 import java.util.scanner; 2 3 public class FinalTrace1 { 4 5 public static void main(string[] args) { 6 Scanner keyboard = new Scanner(System.in); 7 System.out.print("Input a b c: "); 8 int a = keyboard.nextint(); 9 int b = keyboard.nextint(); 10 int c = keyboard.nextint(); System.out.printf("%d %d %d \n", a, b, c); 13 System.out.println(a/b); 14 System.out.println(c--); 15 System.out.println(++a); 16 b *= b; 17 System.out.printf("%d %d %d \n", a, b, c); if ((a + b + c) % 2 == 0) 20 System.out.println((a + b + c)/2); c = a b; 23 System.out.printf("%d %d %d \n", a, b, c); 24 } 25 } Program Output Input a b c: Program Output Input a b c: Program Output Input a b c:

4 2. Write the output of the following program for the given input. When you write the output put in a space marker for all spaces, including any beginning or trailing spaces. For example, the input below has no beginning or trailing spaces so it would be written as This is a test. on the other hand if one of the outputs is the word is with a single beginning and single trailing space you should write it as is. 1 import java.util.scanner; 2 3 public class FinalTrace2 { 4 5 public static void main(string[] args) { 6 Scanner keyboard = new Scanner(System.in); 7 System.out.print("Input: "); 8 String s = keyboard.nextline(); 9 10 String s2 = s.substring(s.length()/4, s.length() - s.length()/4); 11 System.out.println(s2); int pos1 = s.indexof("is"); 14 int pos2 = s.indexof("is", pos1 + 1); 15 System.out.println(pos1 + " " + pos2); 16 String s3 = s.substring(pos2); 17 System.out.println(s3); pos1 = s.indexof("is "); 20 pos2 = s.indexof(" is"); 21 System.out.println(pos1 + " " + pos2); 22 s3 = s.substring(pos1, pos2); 23 System.out.println(s3); 24 } 25 } Input: This is a test. Program Output 4

5 3. Write the output of the following program for each of the two inputs. 1 import java.util.scanner; 2 3 public class FinalTrace3 { 4 5 public static int DoSomething(int a, int b, int c){ 6 int d = (a+b+c) % 5; 7 return d; 8 } 9 10 public static int DoSomething(int a, int b){ 11 a = b++; 12 a--; 13 return a; 14 } public static int DoSomething(int a){ 17 return a*a; 18 } public static void main(string[] args){ 21 Scanner keyboard = new Scanner(System.in); 22 System.out.print("Input a b c: "); 23 int a = keyboard.nextint(); 24 int b = keyboard.nextint(); 25 int c = keyboard.nextint(); System.out.println(a + " " + b + " " + c); 28 c = DoSomething(b); 29 System.out.println(a + " " + b + " " + c); 30 b = DoSomething(a, c); 31 System.out.println(a + " " + b + " " + c); 32 a = DoSomething(a, b, c); 33 System.out.println(a + " " + b + " " + c); 34 a = DoSomething(DoSomething(a), DoSomething(a, b), DoSomething(a, b, c)); 35 System.out.println(a + " " + b + " " + c); 36 } 37 } Input a b c: Program Output Program Output Input a b c:

6 4. Write the output of the following program. 1 public class FinalTrace4 { 2 3 public static void printline(){ 4 System.out.println("---"); 5 } 6 7 public static void printblock(int[] A, int[] B){ 8 printarray(a); 9 printarray(b); 10 printline(); 11 } public static void printarray(int [] A){ 14 for (int i = 0; i < A.length; i++){ 15 System.out.print(A[i] + " "); 16 } 17 System.out.println(); 18 } public static void poparray(int [] A){ 21 for (int i = 0; i < A.length; i++){ 22 A[i] = i; 23 } 24 } public static void rpoparray(int [] A){ 27 for (int i = 0; i < A.length; i++){ 28 A[i] = A.length - i; 29 } 30 } public static void DoSomething(int [] A){ 33 for (int i = 0; i < A.length/2; i+=2){ 34 int temp = A[i]; 35 A[i] = A[A.length-i-1]; 36 A[A.length-i-1] = temp; 37 } 38 } public static void DoSomething2(int [] A){ 41 for (int i = 1; i < A.length; i++) 42 A[i] += A[i-1]; 43 } public static void main(string[] args) { 46 int [] A = new int[8]; 47 int [] B = new int[5]; poparray(a); 50 rpoparray(b); 51 printblock(a, B); DoSomething(A); 54 DoSomething(B); 55 printblock(a, B); poparray(a); 58 poparray(b); 59 printblock(a, B); A = B; 62 printblock(a, B); DoSomething2(B); 65 printblock(a, B); A[3] = 17; 68 B[1] = -5; 69 printblock(a, B); poparray(a); 72 printblock(a, B); A = new int[4]; 75 poparray(a); 76 printblock(a, B); 77 } } Program Output 6

7 5. Write the output of the following program. 1 public class FinalTrace5 { 2 3 public static void printline(){ 4 System.out.println("---"); 5 } 6 7 public static void printarray(int [][] A){ 8 for (int i = 0; i < A.length; i++){ 9 for (int j = 0; j < A[0].length; j++){ 10 System.out.print(A[i][j] + " "); 11 } 12 System.out.println(); 13 } 14 } public static void poparray(int [][] A){ 17 for (int i = 0; i < A.length; i++) 18 for (int j = 0; j < A[0].length; j++) 19 A[i][j] = i+j; 20 } public static void opoparray(int [] A){ 23 for (int i = 0; i < A.length; i++){ 24 A[i] = 0; 25 } 26 } public static int[][] DoSomething(int [][] A){ 29 int[][] B = new int[a[0].length][a.length]; 30 for (int i = 0; i < A.length; i++) 31 for (int j = 0; j < A[0].length; j++) 32 B[j][i] = A[i][j]; 33 return B; 34 } public static void DoSomething2(int [] A){ 37 for (int i = 1; i < A.length; i++) 38 A[i] += A[i-1]; 39 } public static void DoSomething3(int [][] A){ 42 int b = A.length-1; 43 for (int i = 0; i < A.length; i++){ 44 int temp = A[i][0]; 45 A[i][0] = A[i][b]; 46 A[i][b] = temp; 47 } 48 } public static void main(string[] args) { 51 int [][] A = new int[3][4]; 52 int [][] B = new int[3][3]; poparray(a); 55 printarray(a); 56 printline(); B = DoSomething(A); printarray(b); 61 printline(); opoparray(a[1]); 64 DoSomething2(A[2]); printarray(a); 67 printline(); B = new int[3][5]; 70 poparray(b); 71 printarray(b); 72 printline(); DoSomething3(B); 75 printarray(b); 76 printline(); 77 } 78 } Program Output 7

8 3 Coding (20 Points Each) 1. Write a program that will take the number of trials as input from the user, then for each trial the program will roll three die and count the number of rolls that exceed 12 and the number of rolls that are less than 5. Have the program output the number of each type of roll along with the probability of each type of roll. Do the rolling of a single die in a method called roll. 8

9 2. Write four methods for the following main program. The methods are stringreverse, removespaces, ispalindrome, and printpalcone. Fron the code of the main program and the three test runs below you should be able to determine the parameter lists and return types that are needed as well as what each method does. Please write the code on the next page. Main Program public static void main(string[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Input a string: "); String str = keyboard.nextline(); String strns = removespaces(str); System.out.println("str: " + str); System.out.println("str no spaces: " + strns); String rstr = stringreverse(strns); System.out.println("rstr: " + rstr); boolean pal = ispalindrome(strns); System.out.println("str is a palindrome: " + pal); if (pal) printpalcone(strns); Program Run Input a string: A Toyota str: A Toyota str no spaces: AToyota rstr: atoyota str is a palindrome: true ATOYOTA TOYOT OYO Y str: A Toyota } System.out.println("str: " + str); Program Run Program Run Input a string: ab cd e dcb a str: ab cd e dcb a str no spaces: abcdedcba rstr: abcdedcba str is a palindrome: true ABCDEDCBA BCDEDCB CDEDC DED E str: ab cd e dcb a Input a string: Not a Palindrome str: Not a Palindrome str no spaces: NotaPalindrome rstr: emordnilapaton str is a palindrome: false str: Not a Palindrome 9

10 Code for stringreverse, removespaces, ispalindrome, and printpalcone 10

11 3. Write either the Bubble Sort, Insertion Sort or Selection Sort (just do one of them) in a method that takes in one parameter only, a one-dimensional integer array named A. 11

12 4. Write a ChristmasList class that stores a person s name in the variable Name, an array of 5 strings called WishList and an array of 5 strings called SantasComments. The class should have five methods, each of them is discussed below. There is also a sample main program and its output that uses this class. Please write the code on the page after the example run. (a) public ChristmasList(String n) The constructor should store the input string in the Name variable and set all of the entries in both string lists to the empty string. (b) public void addtowishlist(int i, String item) This method should add the item into position i of the WishList. Note that the user (you) is going to think the list numbers go from 1 to 5 and not 0 to 4. If the user inputs a position outside the 1 to 5 range the program should print out an error message, like in the example below. If the user inputs a position that is already filled, the program will simply overwrite the old item. Look at the example code and run below. (c) public void addtosantascomments(int i, String comment) This method should add the comment into position i of SantasComments. Note that the user (Santa) is going to think the list numbers go from 1 to 5 and not 0 to 4. If the user inputs a position outside the 1 to 5 range the program should print out an error message, like in the example below. If the user inputs a position that is already filled, the program will simply overwrite the old comment. Look at the example code and run below. (d) public void printchristmaslist() This method prints out the person s name, the number of items in their list and the list along with any of Santa s comments. For the number of items the method must call the numberitems method below. The list should only print out the items that have been input. So if the person has input items in positions 1, 3, and 5 then the printed list should only list items 1, 3, and 5 and skip items 2 and 4. Santa s comments for an item should only print out if the user has input an item in that position. That is, if Santa puts in a comment in position 2 and the person does not have an item in position 2 then Santa s comment will not be printed. Also, if the person has an item in a position but there is no comment then only the item is printed. If Santa does have a comment for an item, his comment should print out on the same line as the item with three dashes between the item and the comment. Look at the example code and run below. (e) public int numberitems() This method returns the number of items in the person s Christmas list. This should only count the items that have been input, for example, if the person has input items in positions 1, 3, and 5 then the number of items is 3 and not 5. 12

13 Main Program public class ChristmasListMain { } public static void main(string[] args) { ChristmasList mylist = new ChristmasList("Don Spickler"); mylist.printchristmaslist(); mylist.addtowishlist(1, "New Car"); mylist.addtosantascomments(1, "Due to extensive budget cuts this will not be possible."); mylist.printchristmaslist(); mylist.addtowishlist(5, "ipad"); mylist.addtowishlist(3, "Sabbatical"); mylist.printchristmaslist(); mylist.addtosantascomments(5, "Get a real tablet, Android."); mylist.addtosantascomments(2, "Nothing here????"); mylist.printchristmaslist(); mylist.addtosantascomments(3, "You got it, Fall 2014 and Spring 2015!!!"); mylist.printchristmaslist(); mylist.addtowishlist(6, "Puppy"); mylist.addtosantascomments(6, "Error 404"); } Program Run Christmas List for Don Spickler Number of Christmas List items is 0 Christmas List for Don Spickler Number of Christmas List items is 1 List New Car --- Due to extensive budget cuts this will not be possible. Christmas List for Don Spickler Number of Christmas List items is 3 List New Car --- Due to extensive budget cuts this will not be possible. Sabbatical ipad Christmas List for Don Spickler Number of Christmas List items is 3 List New Car --- Due to extensive budget cuts this will not be possible. Sabbatical ipad --- Get a real tablet, Android. Christmas List for Don Spickler Number of Christmas List items is 3 List New Car --- Due to extensive budget cuts this will not be possible. Sabbatical --- You got it, Fall 2014 and Spring 2015!!! ipad --- Get a real tablet, Android. Cannot add to list, index is out of range. Cannot add comment, index is out of range. 13

14 ChristmasList Class Code 14

15 5. Below is the beginning of an applet and several screen-shots of its run are on the right. When the program starts the applet looks like the top image, as you can see from the paint method. If the user clicks inside either the green rectangle or the blue square the applet will look like the second image. That is, the green rectangle is filled in with red and still has a green boarder and the blue square is filled in with yellow and still has its blue boarder. If the user clicks anywhere outside these two rectangles the applet will look like the third image. That is, the outside of the two rectangles will be red and the two rectangles will be filled with white. Note that in this situation the rectangles still have their green and blue boarders and the screen still has its black boarder. Write the needed code for the mouseclicked event to add this functionality to the program. Please write the code on the next page. 1 import java.awt.*; 2 import javax.swing.japplet; 3 import java.awt.event.*; 4 import javax.swing.*; 5 6 public class FinalApplet extends JApplet implements MouseListener { 7 private int drawwidth = 400; 8 private int drawheight = 300; 9 10 public void init() { 11 addmouselistener(this); 12 } public void paint(graphics g) { 15 super.paint(g); 16 g.setcolor(color.white); 17 g.fillrect(0, 0, drawwidth, drawheight); 18 g.setcolor(color.black); 19 g.drawrect(0, 0, drawwidth, drawheight); g.setcolor(color.green); 22 g.drawrect(150, 100, 100, 75); g.setcolor(color.blue); 25 g.drawrect(300, 200, 50, 50); 26 } public void mouseclicked(mouseevent evt) { <<< Insert Code Here >>> } public void mousepressed(mouseevent evt) { 35 } public void mousereleased(mouseevent evt) { 38 } public void mouseentered(mouseevent evt) { 41 } public void mouseexited(mouseevent evt) { 44 } 45 } FinalApplet Run 15

16 mouseclicked Code 16

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) Name: Write all of your responses on these exam pages. 1 Short Answer (10 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss how Java accomplishes this task. 2.

More information

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

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. Name: Write all of your responses on these exam pages. 1 Short Answer (5 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. 2. Java is a platform-independent

More information

2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter?

2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter? COSC 117 Final Exam Spring 2011 Name: Part 1: Definitions & Short Answer (3 Points Each) 1. What do CPU and ALU stand for? 2. What are the two main components to the CPU and what do each of them do? 3.

More information

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

It is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff(); COSC 117 Exam 3 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. A method in a class that has no return type and the same name as the class is called what? How is this type of method

More information

1 Short Answer (7 Points Each)

1 Short Answer (7 Points Each) 1 Short Answer ( Points Each) 1. Write a linear search method for an integer array that takes in an array and target value as parameters and returns the first position of the target in the array. If the

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. Write a declaration of an array of 300 strings. String strarray[] = new String[300];. Write a method that takes in an integer n as a parameter and returns one half of

More information

1 Definitions & Short Answer (4 Points Each)

1 Definitions & Short Answer (4 Points Each) Fall 013 Exam #1 Key COSC 117 1 Definitions & Short Answer ( Points Each) 1. Explain the difference between high-level languages and machine language. A high-level language is human readable code that

More information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions 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!=

More information

1 Short Answer (15 Points Each)

1 Short Answer (15 Points Each) COSC 7 Exam # Solutions Spring 08 Short Answer (5 Points Each). Write a method called RollCount that takes in two integer parameters rolls and target. The method should simulate the rolling of two die,

More information

1 Short Answer (2 Points Each)

1 Short Answer (2 Points Each) Fall 013 Exam # Key COSC 117 1 Short Answer ( Points Each) 1. What is the scope of a method/function parameter? The scope of a method/function parameter is in the method only, that is, it is local to the

More information

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

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each CS 120 Fall 2008 Practice Final Exam v1.0m Name: Model Solution True/False Section, 20 points: 10 true/false, 2 points each Multiple Choice Section, 32 points: 8 multiple choice, 4 points each Code Tracing

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) COSC 117 Exam # Solutions Fall 01 1 Short Answer (10 Points Each) 1. Write a declaration for a two dimensional array of doubles that has 1 rows and 17 columns. Then write a nested for loop that populates

More information

1 Short Answer (15 Points Each)

1 Short Answer (15 Points Each) Name: Write all of your responses on these exam pages. If you need extra space please use the backs of the pages. 1 Short Answer (15 Points Each) 1. Write the following Java declarations, (a) A double

More information

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

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What

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

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) COSC 117 Exam #1 Solutions Fall 015 1 Short Answer (5 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. A compiler will take a program written in

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) 1 Short Answer (10 Points Each) 1. For the following one-dimensional array, show the final array state after each pass of the three sorting algorithms. That is, after each iteration of the outside loop

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

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

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would

More information

5. What is a block statement? A block statement is a segment of code between {}.

5. What is a block statement? A block statement is a segment of code between {}. COSC 117 Exam 1 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. What does CPU stand for? Central Processing Unit 2. Explain the difference between high-level languages and machine language.

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

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

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

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

CSC 1051 Data Structures and Algorithms I

CSC 1051 Data Structures and Algorithms I Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

More information

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

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 73 12 12.1 15 15 ( 12.1.1) 16 15 15 12.1.1: 15 15 (x, y) x y 0 3 0 0 (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 74 12 Program 12.1.1 Piace.java import java.awt.*; public class Piece { private

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

More information

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

5. What is a block statement? A block statement is a segment of code between {}.

5. What is a block statement? A block statement is a segment of code between {}. COSC 117 Exam 1 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. What does CPU stand for? Central Processing Unit 2. Explain the difference between high-level languages and machine language.

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

UCLA PIC 20A Java Programming

UCLA PIC 20A Java Programming UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

More information

CSC 1051 Data Structures and Algorithms I

CSC 1051 Data Structures and Algorithms I Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

More information

Intro to Programming in Java Practice Midterm

Intro to Programming in Java Practice Midterm 600.107 Intro to Programming in Java Practice Midterm This test is closed book/notes. SHORT ANSWER SECTION [18 points total] 1) TRUE/FALSE - Please circle your choice: Tr for true, Fa for false. [1 point

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

SAMPLE EXAM Final Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 16 December 2010

SAMPLE EXAM Final Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 16 December 2010 SAMPLE EXAM Final Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 16 December 2010 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your

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

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

4. Java language basics: Function. Minhaeng Lee

4. Java language basics: Function. Minhaeng Lee 4. Java language basics: Function Minhaeng Lee Review : loop Program print from 20 to 10 (reverse order) While/for Program print from 1, 3, 5, 7.. 21 (two interval) Make a condition that make true only

More information

CS141 Programming Assignment #10

CS141 Programming Assignment #10 CS141 Programming Assignment #10 Due Sunday, May 5th. 1) Write a class with the following methods: a) max( int [][] a) Returns the maximum integer in the array. b) min(int [][] a) Returns the minimum integer

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

University of Palestine. Mid Exam Total Grade: 100

University of Palestine. Mid Exam Total Grade: 100 First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

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

CSE 1223: Introduction to Computer Programming in Java Chapter 6 Arrays

CSE 1223: Introduction to Computer Programming in Java Chapter 6 Arrays CSE 1223: Introduction to Computer Programming in Java Chapter 6 Arrays 1 A New Problem Consider the following task: Input N real numbers representing temperature measurements and compute the following:

More information

Final Exam Practice. Partial credit will be awarded.

Final Exam Practice. Partial credit will be awarded. Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the

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

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

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

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

Using Graphics. Building Java Programs Supplement 3G

Using Graphics. Building Java Programs Supplement 3G Using Graphics Building Java Programs Supplement 3G Introduction So far, you have learned how to: output to the console break classes/programs into static methods store and use data with variables write

More information

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

EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS Q1(a) Corrected code is: EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS 01 #include 02 using namespace std; 03 04 class Question1 05 06 int a,b,*p; 07 08 public: 09 Question1(int

More information

CS141 Programming Assignment #5

CS141 Programming Assignment #5 CS141 Programming Assignment #5 Due Wednesday, Nov 16th. 1) Write a class that asks the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using switch statement. Solution 1:

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

CSE Fall 2015 Section 002 Exam 2, Time: 80 mins

CSE Fall 2015 Section 002 Exam 2, Time: 80 mins CSE 1310 - Fall 2015 Section 002 Exam 2, Time: 80 mins Name:. Student ID:. Total exam points: 100. Question Points Out of 1 20 2 20 3 20 4 20 5 20 6 20 Total 100 SOLVE 5 OUT 6 PROBLEMS. You must specify

More information

Sample Paper of Computer for Class 10

Sample Paper of Computer for Class 10 General Instructions: Sample Paper of Computer for Class 10 1. Answers to this Paper must be written on the paper provided separately. 2. You will not be allowed to write during the first 15 minutes. 3.

More information

Unit 4: Classes and Objects Notes

Unit 4: Classes and Objects Notes Unit 4: Classes and Objects Notes AP CS A Another Data Type. So far, we have used two types of primitive variables: ints and doubles. Another data type is the boolean data type. Variables of type boolean

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value

More information

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

Exam: Applet, Graphics, Events: Mouse, Key, and Focus Exam: Applet, Graphics, Events: Mouse, Key, and Focus Name Period A. Vocabulary: Complete the Answer(s) Column. Avoid ambiguous terms such as class, object, component, and container. Term(s) Question(s)

More information

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this. CS 201, Fall 2013 Oct 2nd Exam 1 Name: Question 1. [5 points] What output is printed by the following program (which begins on the left and continues on the right)? public class Q1 { public int x; public

More information

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can

More information

CIS November 14, 2017

CIS November 14, 2017 CIS 1068 November 14, 2017 Administrative Stuff Netflix Challenge New assignment posted soon Lab grades Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the

More information

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Administrative Stuff CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the

More information

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I Graphics Janyl Jumadinova 7 February, 2018 Graphics Graphics can be simple or complex, but they are just data like a text document or sound. Java is pretty good at graphics,

More information

COE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015

COE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015 1 COE 212 Engineering Programming Welcome to the Final Exam Tuesday December 15, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.

More information

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

Arrays. Eng. Mohammed Abdualal

Arrays. Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays

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

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

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasketEnhanced { public static void main(string[]

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

Building Java Programs

Building Java Programs Building Java Programs Supplement 3G: Graphics 1 drawing 2D graphics Chapter outline DrawingPanel and Graphics objects drawing and filling shapes coordinate system colors drawing with loops drawing with

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Chapter 1 Introduction to Java

Chapter 1 Introduction to Java Chapter 1 Introduction to Java Lesson page 0-1. Introduction to Livetexts Question 1. A livetext is a text that relies not only on the printed word but also on graphics, animation, audio, the computer,

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

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

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Spring 2007 Midterm 2 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

Java Identifiers, Data Types & Variables

Java Identifiers, Data Types & Variables Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays WIT COMP1000 Arrays Arrays An array is a list of variables of the same type, that represents a set of related values For example, say you need to keep track of the cost of 1000 items You could declare

More information

System.out.printf("Please, enter the value of the base : \n"); base =input.nextint();

System.out.printf(Please, enter the value of the base : \n); base =input.nextint(); CS141 Programming Assignment #6 Due Thursday, Dec 1st. 1) Write a method integerpower(base, exponent) that returns the value of base exponent For example, integerpower(3, 4) calculates 34 (or 3 * 3 * 3

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

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013 CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Lecture 8 " INPUT " Instructor: Craig Duckett

Lecture 8  INPUT  Instructor: Craig Duckett Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

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. 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

Name CIS 201 Midterm II: Chapters 1-8

Name CIS 201 Midterm II: Chapters 1-8 Name CIS 201 Midterm II: Chapters 1-8 December 15, 2010 Directions: This is a closed book, closed notes midterm. Place your answers in the space provided. The point value for each question is indicated.

More information

Place your name tag here

Place your name tag here CS 170 Exam 1 Section 001 Spring 2015 Name: Place your name tag here Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with

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

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

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

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

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

More information