(a) This midterm exam is very easy! (b) In Java the return value of a method can be ignored.

Similar documents
(b) This is a valid identifier in Java: _T_R-U_E_. (c) This is a valid identifier in Java: _F_A_L_$_E_

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

Test 1. CSC 121 Lecture Lecturer: Howard Rosenthal. March 4, 2014

Question 2. [5 points] Given the following symbolic constant definition

Computational Expression

CSCI 355 Lab #2 Spring 2007

1. Escape Sequences For each of the following snippets of code write down what will be printed on the screen.

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

CSCI 355 LAB #2 Spring 2004

PROGRAMMING FUNDAMENTALS

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

2. [20] Suppose we start declaring a Rectangle class as follows:

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

Chapter 2: Basic Elements of Java

2.8. Decision Making: Equality and Relational Operators

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Practice Midterm 1. Problem Points Score TOTAL 50

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

Chapter 2: Using Data

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Problem Grade Total

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

G r a d e 1 0 I n t r o d u c t i o n t o A p p l i e d a n d P r e - C a l c u l u s M a t h e m a t i c s ( 2 0 S )

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Computer Science II Data Structures

Activity 3: Data Types

Poster ID 19 Binomial vs. Hypergeometric Yvanny Chang What s the difference?

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Arrays Classes & Methods, Inheritance

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

CSCI 1226 Second Midterm Test

Topics. Chapter 5. Equality Operators

Introduction to Computer Science Unit 2. Notes

Exam 1. CSC 121 Spring Lecturer: Howard Rosenthal. March 1, 2017

17-18 ACP Geometry Final Exam REVIEW

Chapter 5 Lab Methods

Practice Midterm 1 Answer Key

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

Object-Based Programming. Programming with Objects

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Computer Science II (20082) Week 1: Review and Inheritance

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

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

last time in cs recitations. computer commands. today s topics.

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2012

Selection Statements and operators

Programming with Java

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

Review: Geometry. Area Composite Figures Surface Area Volume Fractional Edge Length 3-D Figures and Nets Coordinate Graphing

Introduction to Java Programs for Packet #4: Classes and Objects

Midterm Exam 2 CS 455, Spring 2015

Introduction to Programming Using Java (98-388)

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

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

More on variables and methods

Chapter 02: Using Data

CSE 142 Su01 Final Exam Sample Solution page 1 of 7

AP Computer Science Unit 1. Programs

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

LAB 4.1 Relational Operators and the if Statement

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

Introduction to Computer Science Unit 2. Notes

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

9/1/2015. Chapter 2 Using Objects. Objects and Classes. Using Objects. Using Objects. Using Objects. Classes. Ch. 1/2 Lab Time

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

CS 455 Midterm Exam 1 Spring 2015 [Bono] Thursday, Feb. 19, 2015

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

CS 101 Exam 1 Spring 200 Id Name

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Computer Components. Software{ User Programs. Operating System. Hardware

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

Introduction to Java Applications

COS 126 Midterm 1 Written Exam Fall 2011

Computer Programming, I. Laboratory Manual. Final Exam Solution

Chapter. Let's explore some other fundamental programming concepts

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

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

I. True/False: (2 points each)

Computer Components. Software{ User Programs. Operating System. Hardware

COS 126 Midterm 1 Written Exam Fall 2012

Section 2.2 Your First Program in Java: Printing a Line of Text

ing execution. That way, new results can be computed each time the Class The Scanner

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Introduction to Java Unit 1. Using BlueJ to Write Programs

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Midterm Exam 2 CS 455, Spring 2013

Unit 1: Area Find the value of the variable(s). If your answer is not an integer, leave it in simplest radical form.

Full file at

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

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Transcription:

ComS 207: Programming I Midterm 1, Tue. Sep 18, 2007 Student Name: Student ID Number: Recitation Section: 1. True/False Questions (10 x 1p each = 10p) (a) This midterm exam is very easy! (b) In Java the return value of a method can be ignored. (c) Each Java method must use all of its input arguments. (d) A class can have more than one constructor with the same name. (e) The new operator can be used to create a reference variable to a primitive data type such as int. (f) The Scanner class is located in the java.scan library. (g) A Java Class can be named Class. (h) System.in is a reserved word in Java. (i) Both a char and a String can be used to store the letter C. (j) For each class the programmer must define a tostring() method. 1

2. Short Answer Questions (5 x 2p each = 10p) (a) What is a Java class? (b) What is instance data? (c) What is the difference between float and double? (d) What is the difference between a compiler and an interpreter? (e) What is the meaning of this code snippet? Grade mygrade = new Grade("ComS 207", "F"); 2

3. Arithmetic Expressions (5 x 3p each = 15p) Rewrite the following arithmetic expressions using snippets of Java code. You can assume that the named variables have already been defined to be of type double. (a) z = x 2 + y 2 (b) z = 4 3 πr3 (c) z = 1 c x 3 (d) z = 1 + tan 2 (x) m)2 (e) z = 1 exp (x 2s 2 2πs 2 3

4. Bug Chase (5p + 10p = 15p) Find all bugs in the following programs. Circle the location of each bug and write with words what is wrong with the code at that location. (a) (5p) ======= File: byte.java ======== Public classs byte { Private int maine (String args) { String = new Strong("Jonathan "Jon" Smith"); system.out.println("my name is ", s.substring(1, s.lenght()))); (b) (10p) ======= File: pizza.java ======== Public classs pizza { Private name, address; void pizza(string pname, paddress) { pname = name; paddres = address return name; Private deliver() { system.out.println("deliver 1 ", pname, "to this address ", paddress); ) ========= File: pizzaria.java ========== Public classs piazzaria; { Private int maine (String args) { pizza Pizza = new Pizza("Pepperoni"): pizza.delivery("100 Tornado Street"); 4

5. Expressions and Assignments (10 x 2p each = 20p) For each of the following, write down the value that will be stored in result double result; int num1 = 4, num2 = 11, num3 = 3; double val1 = 3.0, val2 = 10.0, val3 = 2.0; (a) result = num2%num1; (b) result = (int)val3 - num2+num1; (c) result = num3 / val2+num1; (d) result = num2%num3/num1; (e) result = val2 / num1 + num2*num3; (f) result = (float) (val2/ (num1 - num3)*num1); (g) result = ( (int)val2- (num1 % num2))/num3; (h) result = val3 * ((num1 + num2)* num3); (i) result = 1.0*num2 / --num3; (j) result = (num1++ / --num2)/val1; 5

6. Programming Projects (4 x 15p each = 60p) (a) Metric System (15p) Write a complete Java program which asks the user to enter a double value which represents kilometers per second (km/s). The program must then convert this value to miles per hour (miles/hour) and print that on the screen. Round your result so that there are no decimal points. Hint: 1 mile = 5280ft, 1km = 1000m, 1m = 3.28ft Sample output: Please enter km/s : 0.04 This is equal to 89 miles/hour. 6

(b) Painting Problem (15p) Write a complete Java program which calculates how much paint is required in order to paint a room. The program must prompt the user to enter the width, length, and height of the room (in feet) as well as the average paint coverage (in sq ft/gallon). The program must then calculate and print the following values: 1) room volume (in cubic feet); 2) total wall area (in sq feet); 3) gallons of paint required to paint all six walls; and 4) number of five-gallon containers that you must purchase to finish the job. 7

(c) Phone Numbers (15p) Write a complete Java program that asks the user to enter a 10 digit phone number. You can assume that the user will always enter the ten digits without any spaces or punctuation signs (e.g., 5152945555). The program must then format and print three different instances of this number: 1) full number with the area code separated by ( and ) and a dash between the next three digits and the last four; 2) local number - no area code but with a dash between the first three and the last four digits; 3) campus number - only the last 5 digits with a dash after the first one. Sample output: Please Enter a 10 digit phone number: 5152945555 Full : (515) 294-5555 Local : 294-5555 Campus : 4-5555 8

(d) Powerball Lottery (15p) Powerball is a lotto game which is a combined large jackpot game and a cash game. We draw five white balls out of a drum with 55 balls and one red ball out of a drum with 42 red balls. [From www.powerball.com] Write a complete Java program which draws random numbers for the Powerball lottery for a random day of the year. You can assume that all months have at most 28 days. Also, you can assume that its is OK if one and the same number is drawn more than once. Print the numbers on one line in the following format: Sample Output: Draw Date: 9/15/2007 Numbers: 13, 16, 27, 48, 51 Powerball: 21 9

That s it. Good Luck! Question Max Score True/False 10 Short Answer 10 Arithmetic Expressions 15 Bug Chase 15 Expressions 20 Metric System 15 Painting Problem 15 Phone Numbers 15 Powerball Lottery 15 TOTAL: 130 10