Results 1 to 2 of 2
 04162008, 01:15 AM #1Member
 Join Date
 Apr 2008
 Posts
 4
 Rep Power
 0
Java assignment  couple methods don't know how to figure out
Hi. I've got problem with couple methods for any help i'll be very appriciate. It's a game Dicey.
First method:
This method should check each of the dice values to see how many of the dice
are the same value as the value to match (the first parameter), e.g.
getHowManyMatch(5, 4, 5, 2, 5, 6);
The above method call should return the value 2 because two of the dice match the first parameter value, 5.
Return type
an int: the number of dice which match the int passed in as the first
parameter.
private int getHowManyMatch(int numberToMatch, int d1, int d2, int d3, int d4, int d5) {
int numberOfMatches = 0;
return numberOfMatches;
}
Second method:
This method should check how many dice have the value 1, then the method
should check how many dice have the value 2, etc. The method returns the
maximum number of matches found, e.g.
getMaxNumberOfMatches(6, 5, 6, 5, 6);
should return the value 3 because there are 3 sixes.
Note: this method should make use of the method defined in method one. above e.g.,
int maxMatchesSoFar = getHowManyMatch(1, dice1, dice2, dice3,
dice4, dice5);
Return type
an int: the maximum number of matches.
private int getMaxNumberOfMatches(int d1, int d2, int d3, int d4, int d5) {
int numberToMatch = 1;
int numberOfMatches1 = 0;
int numberOfMatches2 = 0;
return Math.max(numberOfMatches1, numberOfMatches2);
}
Third method
This method should check how many dice with the value 1, there are. If there are two dice with the value 1, then the method should return 1. If not, this method should then check how many dice with the value 2 there are. If there are two dice with the value 2, then the method should return 2, and so on, e.g.
getDiceNumberWithTwoMatches(4, 5, 6, 5, 6);
should return the value, 5 as there are two dice with the value 5.
Note: this method should make use of the method defined in method one. above e.g.,
int valueToTest = 1;
int numberOfMatches = getHowManyMatch(valueToTest, dice1,
dice2, dice3, dice4, dice5);
Note: if, at any time, the method finds that there are exactly 2 matches, then the method can immediately return the dice number, e.g.
int valueToTest = 1;
numberOfMatches = …
if (numberOfMatches == 2) {
return valueToTest;
}
…
Return type
an int: the dice value which has EXACTLY two matches, the method returns 0 if there are no dice values with exactly two matches.
private int getDiceNumberWithTwoMatches(int d1, int d2, int d3, int d4, int d5) {
int numberToMatch = 1;
int numberOfMatches;
return 0;
}
method four
This method should print a message containing the parameter dice value. Note: there are eight spaces before the String, "Two" is printed, e.g. if the parameter
value is 4, this method should print:
Two 4’s. Roll the remaining 3 dice.
private void printTwoMatchesMessage(int diceValue) {
}
method five
This method should print a message containing the parameter dice value. Note: there are eight spaces before the String, "Two" is printed, e.g. if the parameter value is 4, this method should print:
Two 4’s. Roll the remaining 3 dice.
Return type
void
private void printTwoMatchesMessage(int diceValue) {
}
method six
Note: this method should use the getMaxNumberOfMatches() method from
method five above.
Return type
an int: the value 5 if the maximum number of matches is 5,
the value 4 if the maximum number of matches is 4,
the value 3 if the maximum number of matches is 3.
The method should return 0 in all other cases.
private int getScore(int d1, int d2, int d3, int d4, int d5) {
return 0;
}
method seven
This method should print a blank line and, on the next line, the String, "Round ",
followed by the number passed as a parameter to the method e.g.
Round 3
Return type
void
private void printRoundNumber(int roundNumber) {
}
method eight
This method should print a message similar to the following (depending on the
player names and the player scores) followed by a single blank line:
Round 3: Anna has 4 points, and Jim has 8 points
Return type
void
private void printRoundResults(int roundNumber, String player1Name, int player1Score, String player2Name, int player2Score) {
}
Method nine
This method should print a blank line and, on the next line, one of the following:
e.g.
If the result is a tie and both players have the same score, the method
should print the message: "The result is a tie"
If the result is not a tie, this method should print the String
"Congratulations to " and the name of whichever player
has the higher score.
Return type
void
private void printFinalResult(String player1Name, int player1Score, String player2Name, int player2Score) {
System.out.println();
}
 04162008, 10:52 AM #2
Similar Threads

Couple of Problems
By joz_12345 in forum Java 2DReplies: 2Last Post: 03062008, 05:13 PM 
Java assignment
By xtianah77 in forum New To JavaReplies: 1Last Post: 02182008, 12:54 AM 
java assignment, need help bad.
By carlos123 in forum New To JavaReplies: 1Last Post: 11062007, 05:53 PM 
Help with my assignment java
By toby in forum New To JavaReplies: 1Last Post: 08072007, 05:59 AM 
I can't figure this out
By silvia in forum New To JavaReplies: 3Last Post: 07202007, 04:38 AM
Bookmarks