Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008, 02:15 AM
Member
 
Join Date: Apr 2008
Posts: 4
Snowboardmylife is on a distinguished road
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();




}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-16-2008, 11:52 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Hmmmhhh!!!
You should be the one to write that method implementation....

make methods first and post it if you have problems about it... that's the right time to ask....

kind regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Couple of Problems joz_12345 Java 2D 2 03-06-2008 05:13 PM
Java assignment xtianah77 New To Java 1 02-18-2008 12:54 AM
java assignment, need help bad. carlos123 New To Java 1 11-06-2007 05:53 PM
Help with my assignment java toby New To Java 1 08-07-2007 06:59 AM
I can't figure this out silvia New To Java 3 07-20-2007 05:38 AM


All times are GMT +3. The time now is 04:07 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org