Assignment #4

Due: Friday, June 11

From the textbook, do Exercises 7.15 and 7.27 (also note extra instructions below).



Filenames should be

For these exercises, your programs should get any user inputs and print results using the JOptionPane class so that they work with a basic GUI interface. See Deitel examples in chapters 2, 4-7

Extra Instructions

  1. For 7.15, write this program as an application with a GUI interface (not as an applet). Instead of rolling the dice 36000 times, ask the user to input how many times they want to roll the dice. In addition to displaying the number of times each sum appears, also display the percentage of total rolls that each sum accounts for. And display the total number of rolls at the bottom. Ignore the instruction about the JButton, but do display your results in a JTextArea (using an "information message" JOptionPane). Here's an example of what your results might look like:
      Sum     # of times      Percentage
    
      2       285             2.85 %
      3       514             5.14 %
      4       869             8.69 %
      5       1091            10.91 %
      6       1457            14.57 %
      7       1647            16.47 %
      8       1342            13.42 %
      9       1116            11.16 %
      10      843             8.43 %
      11      568             5.68 %
      12      268             2.68 %
    
      Total # of rolls: 10000
    
    For large numbers of rolls, you'll find the percentages should be similar each time, if you are computing the die rolls correctly. (Remember, we are rolling 2 six-sided dice -- this is NOT the same as just picking a random number from 2 through 12).
     
  2. For 7.27, this will be very similar to problem 6.26 in assignment 2, in terms of your results. The difference is that this one should be in a basic GUI interface, and you are to use an array to figure out the primes (not the "prime" function of exercise 6.26).

    Use JOptionPane to ask the user for the input of a number N. As in ex. 6.26, you will compute and print all the prime numbers less than or equal to N (instead of using 1000, as stated in the problem). However, use the process described in 7.27 (array of booleans) to figure the primes. As before, the output of your results should be 10 numbers per line. However, the results should be displayed in a JTextArea (using an "information message" JOptionPane). Also, make this text area scrollable (i.e. use JScrollPane).

    HINT: Remember that Fig. 5.19 from Deitel shows a good example of a scrollable text area.
     


Submitting:

Pack up your files with jar. For this one, you only need to pack up your source code files (Dice.java and Primes.java) into one jar file called hw4.jar. This does not need to be a "runnable" jar file (so no manifest addition needed).

E-mail this jar file to me (myers@cs.fsu.edu) by the due date. Your e-mail subject should be HW4-SUBMIT. Include your name and section in the e-mail body. Please only submit ONCE, unless you make a mistake and need to correct it (before the due date) -- and minimize this. Only the last submission will be graded.