Review Sheet for Midterm 1
This review sheet is not complete. All material covered in class or in
reading assignments through the end of class on Monday, Sept 29, will be
covered on the test.
1. Write a line of code that creates an object that can be used to write text to the file "numbers.dat".
2. What is a checked exception? How do we advertise that our code might throw an exception (if we don't intend to handle it)?
3. Write a Java program that reads 100 integers and prints the min, max and average to the screen.
4. Write a program that takes a sentence from the command line (ie, 0
or more command line arguments) and prints the reversed sentence to the
5. Write a program that reads an input file "test.txt" and prints each floating-point token to the screen.
6. Write a class that represents a Point in 2-dimensional space. The
class should store the point's x and y coordinates. Include methods
- compute and return the point's distance from the origin (0,0)
- getter methods
- setter methods
- override the toString(), clone() and equals() methods from the Object class
- constructor that takes the point's x and y coordinates
- constructor that creates a point that represents the origin
8. Write a Java program that reads the name of a file from the user,
and prints the number of lines in the file that contain the word
9. Declare and initialize a constant the represents the median price of a house in Austin.
10. Give an example of an explicit cast, and explain when it is necessary to use an explicit cast.
11. Explain the difference between comparing 2 strings with == and the
equals() method. Does it make sense to compare two floating-point
values with ==?
12. For your class Point in #6, write a subclass called XAxisPoint that represents points with y-coordinate equal to 0.
13. What is the value and type of the result?
d. Math.pow(3, 5)
g. 15 + 2 + " hellos"
h. 15 * 2 / 4
i. (5 < 4) || Character.isDigit(2)
14. Write Java code that prints the characters in an array
String words = ...; // assume words has been initialized
to the screen, one character per line.
15. Review the online notes we've covered in class and re-work the examples.
16. Give an example illustrating the use of the canRead() method in the File class.