CSC 101, Summer 2001, Turner. Practice Midterm questions. TIPS for taking my midterm: a. Review the quizzes. Be prepared to "explain" all the T/F questions, make SURE you understand any mistakes you made on them! b. Notice any questions I repeat on quizzes, they will likely show up in some form on the midterm. c. Carefully review all the "Summary of Key Concepts" sections in chapters 1 - 4 in the text, look over the start of chapter 5, too. d. Answer the "Self Review" questions in each of the chapters covered. AFTER you have written them up, check your answers against the answers in the text. e. NOTICE the differences in emphasis in my own lectures and the chapters in the book. Be sure you can explain the reasons (even if you do not agree) I would emphasize the things I do. f. Work through these practice questions carefully and in detail. Do it with other students in a group and discuss alternative answers and probable wrong answers. PRACTICE QUESTIONS. 1. What is a "class"? What is an "object"? What is a "method"? What is the relationship between them? 2. Write a java program that uses two nested FOR loops and the modulus operator (%) to detect and print prime numbers (integer numbers that are not evenly divisible by any other numbers except for 1 and the number itself.) 3. Transform a WHILE loop into a FOR loop and then into a DO loop (here is a simple one): int i = 1; while (i < 20) { i++; System.out.println (i); } 4. Think about representing an alarm clock as a software object. List some characteristics of the object that represent its state; list the primary data and methods of the object. (The clock is an example of what might be asked about some other real world "object"). 5. Write a java boolean expression for the following English sentences: - The int x is larger than 5 - The int j is neither 2 nor 7 - The char op is not '=' and the boolean variable "error" is not true 6. What is the output of the code fragment if the variable A contains 7 and B contains 7: if (A <= 7) if (B > 9) if (A == 7) System.out.println("1st branch"); else System.out.println("2nd branch"); 7. Recall that we discussed in class that variables contain either primitive values or references (to objects). Now, consider the following code and tell me the output (and why). String s1 = new String("this is a string"); String s2 = new String("this is a string"); String s3 = new String("This is a String"); if (s1 == s2) System.out.println("s1 and s2 are the same."); else System.out.println("s1 and s2 are different."); if (s1.equalsIgnoreCase(s3)) System.out.println("s1 and s3 are the same (mod case)"); else System.out.println("s1 and s3 are different (mod case)"); 8. Consider the following declarations and tell me if the assignment is valid and the result: int i; char c; boolean b; i = 6 * 6 / 9 + 2 b = true || false b = b || !b c = 2.0 / 2.0