hts.StevenWood.com

Exercise 4-2-2a

Home ] Up ] InitArray.java ] InitArray1.java ] InitArray2.java ] SumArray.java ] SumArray1.java ] SumArray2.java ] Exercise 4-2-1 ] [ Exercise 4-2-2 ] Exercise 4-2-3 ] Labs ] Rubric ][ Last Page ]

Exercise 4-2-2a

This assignment will be handed in by the due date listed on the term outline. 
(14 marks)

You may create the code in NetBeans but you MUST write out the answers by hand and submit them for grading. Label your work carefully for parts a, b, c, and d. 

Note: Declare any 'new' variables that are required in the section of code that they pertain to. Variables and objects declared or created in a previous section of the question do not have to be declared or created again (you can still use them). 

If a particular section requires a loop you must give the code for the loop. In other words, you cannot say "this code goes inside the loop from part b" and get full marks. 

  1. For an array named diceRolls:
    1. Declare and allocate memory for the array. It has "x" elements and must be suitable for the items described in part (b) below. The value of "x" will be entered from the keyboard. (Get the size of the array, then use the line of code to set up the array with the correct size.) (2 marks)
    2. Assume that the above item has been completed in another section of code.
      Set each element of diceRolls equal to a random number representing the roll 2 dice. Each die has the possible rolls of 1, 2, 3, 4, 5, or 6. (Therefore, the possible rolls are 2, 3, 4, ... 11, 12.) (2 marks)
    3. Assume that the above items have been completed in other sections of code.
      Find and display the value of the average roll. The answer should be without decimals. (2 marks)
    4. Assume that the above items have been completed in other sections of code.
      Add code that will count how many 5s were rolled. Count how many 7s were rolled. Count how many 12s were rolled. Display the 3 answers in a table format AND have your code display a statement indicating which on has the highest number of rolls. (e.g. You rolled more 12s.) (2 marks)
  2. For an array named life:
    1. Initialize, using a list, an array named life with these values:
      true, false, false, true   (1 mark)
    2. Assume that the above item has been completed in another section of code.
      Declare and allocate memory for another array named death of the same type and size as life. (1 mark)
    3. Assume that the above items have been completed in other sections of code.
      Use a for loop to set the values in death to be the opposite of the values in life. For example life[0] = true therefore set death[0] = false, etc.   (2 marks)
    4. Assume that the above items have been completed in other sections of code.
      Display the values of both arrays in a nicely titled table:
        (2 marks)
 

Check the Late Submissions policy.

Home ] Up ] InitArray.java ] InitArray1.java ] InitArray2.java ] SumArray.java ] SumArray1.java ] SumArray2.java ] Exercise 4-2-1 ] [ Exercise 4-2-2 ] Exercise 4-2-3 ] Labs ] Rubric ][Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+