Problem 1 (Exercise R4.9)
Friday, May 30, 2008
Week 6 Problem 1
W6 Problem 2 (R4.12)
How do you get the first character of a string? The last character? How do you remove the first character? The last character?
W6 Problem 3
Problem 3 (R4.16)
Note: Appendix E of the textbook contains a chart showing the order of precedence of Java operators.
What are the values of the following expressions? In each line assume that
double x = 2.5;
double y = -1.5;
int m = 18;
int n = 4;
String s = “Hello”;
String t = “World”;
- x + n * y – ( x + n ) * y
- m / n + m % n
- 5 * x – n / 5
- Math.sqrt(Math.sqrt(n))
- (int) Math.round(x)
- (int) Math.round(x) + (int) Math.round(y)
- s + t
- s + n
- 1 – ( 1 – ( 1 – ( 1 – ( 1 – n ))))
- s.substring(1,3)
- s.length() + t.length()
W6 Problem 4
Problem 4 (uses StampMachine class as defined on page 157, step 5, of Big Java book)
Write a main method that prompts a user for the following information and reads the user response from the keyboard:
- 16 digit credit card number, read as a string
- Month/year from the credit card, in the format MM/YY, read as a string
- a dollar amount to be spent on a stamp purchase, read as a double
Using the StampMachine class, the method should then determine and display the following information to the user:
· the number of first class stamps purchased
· the number of penny stamps purchased
· the credit card information, in the following format, showing only the last 4 digits of the card number:
Card: XXXXXXXXXXXX1234 Month: 10 Year: 09