Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Quiz; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Fall 2004;
Typology: Quizzes
1 / 2
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:
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.