Java programming with bluej | Computer Science homework help

 

Task #1 The Dice Game

  1. Write a TwoDice class with instance variables face, a two-element array to hold values you can roll with a pair of dice.
    1. Default constructor places random values 1..6 on each face
    2. Constructor with parameters n, m for the initial face values. Validate the parameters to allow only 1..6.
    3. Accessors getFace1( ), getFace2( ) and getTotal( ) which returns an integer.
    4. Mutators setFace1( ), setFace2( ) to set each to only 1..6 
    5. Mutator roll( ) which randomize the numbers on face1 and face2 to 1..6
    6. toString( ) method to return a string like “3, 4” or “6, 5”
    7. equals( ) method to compare a pair of dice with another pair of dice. Return true if they have the same face values.
    8. printMe( ) method for DEBUG. This should simply print the value in toString( ).
  2. Write a client DiceClient1YOURNAME.
    1. Instantiate and initialize a pair of dice
    2. Instantiate score, a 20 element integer array of integers and initialize it to all 0.
    3. Write a play( ) method for a new game, it should reset the game and then continuously roll the dice until you win or lose or the array is full.
    4. Each roll is entered in the array until you win, lose, or the array is full.
    5. Write a printArray( ) method to print the score array on ONE line. Make it easy to read by adding a ” – ” after every 5 scores e.g.

      4  8  9  8  5   –  7  0  0  0  0  –   0  0  0  0  0  –   0  0  0 0  0 

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

The rules of the game: A player rolls the two dice and adds the number shown on them.

  1. Roll the two dice up to 20 times and save the total in the array.
  2. If the total is 7 or 11, you win. Put this in the array, report the results and exit the game.
  3. If the total is 2, 3, or 12, you lose. Put this in the array, report the results and exit the game.
  4. If the total is anything else, save the total as the “goal”. put it in the array, and you get to roll again.
  5. The new objective is to roll the same total as the “goal”.
    • You keep rolling until you either get “goal” or a 7. Show the array.
    • If you roll “goal”, you win. Put this in the array, report the results and exit the game.
    • If you roll a 7, you lose. Put this in the array, report the results and exit the game.
    • Sample Terminal:

You win:   10 10 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0 
You win:   7 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0  
You win:   8 11 8 0 0 – 0 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0  
You lose:  6 3 3 7 0 – 0 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0  
You lose:  4 5 5 12 9 – 6 6 7 0 0 – 0 0 0 0 0 – 0 0 0 0 0  
You win:   8 8 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0 – 0 0 0 0 0  

Task #2 Arrays of Objects Copy the files Song.java, CompactDiscYOURNAME.java and ClassicSongs.java as directed by your instructor. Song.java will be completed in class. ClassicSongs.java is the data file that will be used by CompactDiscYOURNAME.java, the file you will be editing. 

CompactDiscYOURNAME.javaPreview the document

ClassicSongs.javaPreview the document

Song.javaPreview the document

  1. In CompactDisc.java, there are comments indicating where the missing code is to be placed. Declare an array of Songs, called cd, with a size of 6. 
  2. Fill the array by creating a new song with the title and artist and storing it in the appropriate position in the array. 
  3. Print the contents of the array to the console. 
  4. Compile, debug, and run. Your terminal output should be: 

Contents of Classics: 

Ode to Joy by Bach 

The Sleeping Beauty by Tchaikovsky 

Lullaby by Brahms Canon by Bach 

Symphony No. 5 by Beethoven 

The Blue Danube Waltz by Strauss