Problem Grade Total

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

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

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

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

CS 113 MIDTERM EXAM 2 SPRING 2013

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

AP CS Unit 3: Control Structures Notes

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Practice Midterm 1 Answer Key

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

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

Introduction to Computer Science Unit 2. Notes

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

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

Introduction to Computer Science Unit 2. Notes

Java Identifiers, Data Types & Variables

Practice Midterm 1. Problem Points Score TOTAL 50

Supplementary Test 1

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

PROGRAMMING FUNDAMENTALS

Selected Questions from by Nageshwara Rao

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

University of Massachusetts Amherst, Electrical and Computer Engineering

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

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

I. True/False: (2 points each)

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

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

CS 177 Spring 2010 Exam I

CS 101 Fall 2005 Midterm 2 Name: ID:

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

b. Suppose you enter input from the console, when you run the program. What is the output?

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

Programming with Java

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

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

Computational Expression

University of Palestine. Mid Exam Total Grade: 100

CS 101 Exam 2 Spring Id Name

Computer Programming, I. Laboratory Manual. Final Exam Solution

NATIONAL UNIVERSITY OF SINGAPORE

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

Introduction to Computer Science Unit 2. Exercises

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

CS 101 Spring 2007 Midterm 2 Name: ID:

Following is the general form of a typical decision making structure found in most of the programming languages:

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

1 Short Answer (10 Points Each)

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Use the scantron sheet to enter the answer to questions (pages 1-6)

Lab5. Wooseok Kim

Assignment 1 due Monday at 11:59pm

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

( &% class MyClass { }

COE 211 Computer Programming. Welcome to Exam I Tuesday March 13, 2018

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

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

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

I. True/False: (2 points each)

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CS 177 Week 15 Recitation Slides. Review

CMP 326 Midterm Fall 2015

Part I. Multiple Choice Questions (2 points each):

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Midterm Examination (MTA)

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

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz

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

CS164: Midterm I. Fall 2003

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2009

Final Exam Practice. Partial credit will be awarded.

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

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

public class SomeClass OtherClass SomeInterface { }

CS 1331 Exam 1 ANSWER KEY

CS 302: INTRODUCTION TO PROGRAMMING IN JAVA. Lecture 16

Java Classes: Math, Integer A C S L E C T U R E 8

Introduction to Programming Using Java (98-388)

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

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

AP Computer Science Unit 1. Programs

CS18000: Problem Solving And Object-Oriented Programming

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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.

CS 113 PRACTICE FINAL

I. True/False: (2 points each)

Transcription:

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 of the test. The test is a total of 104 points. Good luck! Problem Grade 1 2 3 4 5 6 7 8 9 10 Total

1. (8 pts) Write a method public static void printasterisks(int[] ar) which accepts the parameter ar, an array of integers, and prints out for each value stored in the array at index index, a line of ar[index] asterisks. For example, if ar holds the array {3,4,5,0,1, the output to the screen should be *** **** ***** *

2. (8 pts) Consider the following (partially defined) class Vec, which represents a vector in 3-space with coordinates x, y, z: public class Vec{ private double x,y,z; public Vec(double a, double b, double c){ x = a; y = b; z = c; public String tostring(){ return "(" + x + "," + y + "," + z + ")"; public double dot(vec w){/* Fill in */ public Vec cross(vec w){/* Fill in */ Below, implement the methods dot and cross, which represent the dot product and cross product of the two vectors. Here are the formulas: the dot product of two vectors (x, y, z) and (x, y, z ) is a real number given by (x, y, z) (x, y, z ) = xx + yy + zz. On the other hand, the cross product of the same two vectors is another vector given by (x, y, z) (x, y, z ) = (yz zy, zx xz, xy yx ).

3. (8 pts) Design and implement an application that reads a string from the user (using a Scanner), and prints it one character per line. (Recall the String class has a method charat(i) which returns the character at the i th place in the string.)

4. (6 pts) Write a loop which prints out every other capital letter of the alphabet, starting at A. The output to the screen should be ACEGIKMOQSUWY. You must write a loop, not simply print this string to the screen. 5. (6 pts) What is the output to the screen of the following code fragment? int a[][] = {{2,3,6,{0,4,5,{1,7,9; for (int i=0; i<3; i++){ for (int j=0; j<3; j++) System.out.print(a[j][i] + "\t"); System.out.println(); Output:

6. (10 pts) Write a java program CommandLine.java which accepts parameters in the command line in the following format: the first parameter (passed in as args[0]) is the name of a student, while all the following parameters are integer grades of tests. Store the name in an appropriate String, and then store the rest of the commandline parameters in an int array grades. The output of your program should print out the name and the sum of the grades. (Recall that the method Integer.parseInt converts a number in String format to its int value.) Here is a sample run: To compile the program, type javac CommandLine.java Then to run it, type java CommandLine John 70 80 90 95 60 In this case, the output should be The sum of John s grades is 395.

7. (10 pts) What is the output to the screen? public class P{ public static void main(string[] args){ int[] a = {1,3,7,9,10; int[] b = {2,7,13,14; ff(a); ff(b); ff(a); public static void ff (int[] ar){ for (int i=0; i<ar.length; i++){ if (ar[i]%2 == 0) System.out.print(ar[i]+" "); else ar[i] += 3; System.out.println(); Output:

8. (10 pts) Consider the following class BankAccount public class BankAccount{ private double balance; private int id; public BankAccount(double b, int i){ balance = b; id = i; public void deposit(double amount){ balance += amount; public void withdrawal(double amount){/*fill in*/ public boolean overdraft(double amount){/*fill in*/ public String tostring(){ return id + "\t" + balance; Below, write the methods overdraft and withdrawal. The overdraft method should return true if the account balance will become negative upon withdrawing the amount (and it should return false otherwise). The withdrawal method should call the overdraft method to determine its action: If there is no overdraft, simply withdraw the amount from the balance; while if there is an overdraft, do not perform the withdrawal, but print an error message to the screen.

9. (8 pts) Consider a class Point which has two private double data members x and y (these represent the coordinates of a point in the plane). Write two constructors for this class public Point (double a, double b) // creates a new Point // object with coordinates (a,b) and public Point (Point p) // creates a new Point object with the // same coordinates as the Point p

10. (30 pts) Circle the Roman numeral of the answer (a) Which one of the following is not an example of software? i. operating system ii. interpreter iii. RAM iv. Java applet (b) Which of the following is equal to the double value 2.5 in Java? i. 10/4 ii. 2+1/2 iii. (double)(5/2) iv. 5.0/2.0 (c) What does the expression (int)(math.random()*6) represent? i. a random integer between 0 and 5 inclusive ii. a random integer between 1 and 6 inclusive iii. a random floating point number between 0.0 and 6.0 iv. this always evaluates to 0 (d) If s and t are String objects, then which of the following is a boolean expression tests to see if s and t represent the same word? i. s==t ii. s=t iii. s.equals(t) iv. s+t (e) Which of the following is an infinite loop? i. while (x>0); {x--; ii. while (x>0) {x--; iii. for (int a=1; a<15; a+=2){x+=3; iv. do{x=x+i; i++; while(x>15 && i<20);

(f) What is the value of Math.pow(2,3)? i. 6.0 ii. 8.0 iii. 9.0 iv. 5.0 (g) What is the output to the screen? boolean b = true; int x = 5; do{ System.out.print((x+2)+" "); b = (x==5); x++; while (b); i. 7 7 ii. 7 8 iii. 7 iv. nothing (h) If b is an int variable with value 10, and c is a boolean variable with value true, which of the following boolean expressions is false? i.!c ii. b<10 c iii. b==10 iv. b>=5 && c (i) Which statement instantiates a new Scanner object which scans input from the user? i. Scanner scan = new Scanner (System.in); ii. new Scanner = User.input; iii. Scanner = new Scanner (System.in); iv. Scanner scan = Scanner.getNewSystemInput(); (j) Which char value is equal to Z +2? i. A ii. B iii. Z iv. none of the above