Assignment 3

Due before class on Friday, April 24th

  1. a) Explain the difference between primitive types and reference types.
    b) Describe the two different ways Java uses to pass parameters and state which way applies to each of the types described above in (a).
  2. Exercise 5.17 If you don't frequent gambling halls (and thus might not be intimately familiar with the game of "craps"), you can read a description of the game in the textbook in section 4.8. There's also source code for an applet which plays craps (Figure 4.9), but you won't need much of what's in Figure 4.9, because you don't need any user input. (You can write either an applet or an application for this exercise.)

    If you write an applet, you can save yourself some trouble by using System.out.println() to print out results, instead of the drawString() method. If you use System.out.println(), you'll see the results either in the Messages window (in Visual Cafe) or in the Java console of the browser (either Netscape or Explorer). Neither browser displays the Java console by default, so you'll have to ask to see it. In Netscape use the Communicator menu and choose Java Console. In Explorer, use either Java Console (Windows) or Java Messages (Mac) under the View menu.

  3. Exercise 5.20 For this exercise you should write an applet. Your applet should have text fields for a user to enter a salesperson number (1-4), a product number (1-5) and total sales for that person. The lower portion of the applet should then update the table which shows sales totals (broken down by salesperson and total).

    A fairly bare interface (which is fine) might look like below:

    As you work in this problem, here are some things to think about:

  4. OPTIONAL If you prefer, you can solve this problem, rather than the previous one.

    Write an applet which displays a Label object with the text of your choice. Your applet should change the foreground and background colors of the label as the user moves the mouse over the label -- every mouse position (over the label) should have a unique foreground and background color combination. (If you want to randomly generate the color combinations, that's okay, but every possible color combination be included in your random generation i.e., if you used the applet for long enough, you'd see all the possible color combinations.) Once the user moves the mouse off the label, the colors should stop changing until the mouse moves back over the label.

    Here are a few tips: