Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Quiz 2 Worksheet - Object Oriented Programming I | CMSC 131, Quizzes of Computer Science

Material Type: Quiz; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Fall 2004;

Typology: Quizzes

Pre 2010

Uploaded on 02/13/2009

koofers-user-uvx
koofers-user-uvx 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Quiz 2 Worksheet - Object Oriented Programming I | CMSC 131 and more Quizzes Computer Science in PDF only on Docsity!

CMSC 131 Quiz 2 Worksheet

The second Quiz of the course will be on Monday, Sept 20 during your lab session (either at 10 am or 11 am). The following list provides more information about the quiz:

  • You will have 15 minutes to complete the quiz.
  • It will be a written quiz (not using any computer).
  • It will be closed-book, closed-notes, and no calculator is allowed.
  • Answers must be neat and legible. We recommend that you use pencil and eraser.
  • The quiz will be based on the exercises you will find below. None of the classes associated with the picture library (i.e., cmsc131PictureLib) will be part of the quiz.

The following exercises cover the material to be covered in Quiz #2, Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and instructors during office hours. When asked to write a Java application, you should give the entire class definition, not just the main method.

1. From Lewis & Loftus

a. Page 199-200 (“exercises”) 3.8, 3.9, 3.12, 3.14, 3.17, 3. b. Page 201 (“programming projects”) 3.4, 3.

2. Which of the following represent valid Java identifiers? a. $5$x b. _8&house c. Pressure% d. while e. do f. theHouseFarFromHere 3. Using parentheses indicate the order in which each of the following expressions will be evaluated or whether the expression represents an invalid expression. You can assume all the variables are of type int.

a. x / y * z % w b. x++ + y++ c. x + y + z – w % p * 2 d. x < y || z > m && y <= 4

4. The factorial of a positive integer n is the product of all integer values from 1 up to n. (The factorial of 0 is defined to be 1.) Write a Java Program that reads a nonnegative integer value from the user (using a JOptionPane) and computes the factorial of that value.

5. Write a Java program that “simulates” the reading password process you go through while logging into a computer account. The program will ask for a password, compare that value against two possible passwords, and print “Welcome” if any of the provided passwords is valid. Otherwise, “Invalid Password” should be printed. Your program will allow a maximum of three opportunities in order for the user to provide a correct password. Your program must end if after three attempts the user has not provided a correct password. You must use a do-while statement for this problem. 6. Implement Problem (5), but this time using a while statement.