Friday, May 30, 2008

Week 6 Problem 1

Problem 1 (Exercise R4.9)

Explain the differences between 2, 2.0, ‘2’, “2”, and “2.0”.

W6 Problem 2 (R4.12)

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”;

  1. x + n * y – ( x + n ) * y

  1. m / n + m % n

  1. 5 * x – n / 5

  1. Math.sqrt(Math.sqrt(n))

  1. (int) Math.round(x)

  1. (int) Math.round(x) + (int) Math.round(y)

  1. s + t

  1. s + n

  1. 1 – ( 1 – ( 1 – ( 1 – ( 1 – n ))))

  1. s.substring(1,3)

  1. 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

Wednesday, May 28, 2008

Upcomming Test

Here is the link to the study guide for the up coming test.