## Any Java Experts? More Help!

Moderator: Baseball Moderators

### Re: Any Java Experts?

Art Vandelay wrote:I saw the thread title and got all excited thinking I'd finally be able to put my degree in South Pacific Studies to use, but alas, you're talking about the computer program. I don't know anything about computers, but if anyone has any questions about the most heavily populated island in the world, let me know.

what is Indonesia's GDP
Dan Lambskin
Hall of Fame Hero

Posts: 10110
(Past Year: -115)
Joined: 20 Mar 2005
Home Cafe: Baseball

### Re: Any Java Experts?

Last year it was just over \$500 billion, what's interesting, though, is that the per capita GDP is less than \$4,000 (in US dollars). Indonesia's economy was making some huge strides under Yudhoyono before the global economic downturn slowed things down quite a bit. A major problem has been that prices of some of Indonesia's main exports--principally rubber, coffee, peanuts, and palm oil--have really been hard hit by the economic crisis, while prices of its major imports have been steadily increasing (fuel and food).
Art Vandelay
Hall of Fame Hero

Posts: 5254
(Past Year: -11)
Joined: 12 Mar 2005
Home Cafe: Baseball

### Re: Any Java Experts? Part 2!

sox 06 wrote:
public static int determineWinner(Card [] h1, Card [] h2) - This method should determine the winner of the game and return the win/loss amount based on the following rules:

If the user (hand h1) has blackjack (see method below), the return value is 15.
If the first hand (h1) has over 21, the return value is -10.
If the second hand has over 21, the return amount is 10.
If the first hand is higher than the second (but neither has busted), the return value is 10.
If the second hand is higher than the first (but neither has busted). the return value is -10.
If the first and second hand have the same value, no money is exchanged. The return value is 0

One quick suggestion before the rest, run your card ranks 1-13 and not 2-14. You will need a lot fewer checks later down the road if everything >= 10 is worth ten (not having to worry about the ace as much). Might not be a big deal in a small program like this, but would be much bigger headache if it grew beyond the simple stuff.

For the rest of it I'm not sure where you are having problems here. This is really basic logic. You will need to call a function to check the user hand for blackjack (doesnt appear they want you to check h2), if not then call a function to add each array up to give you the hand total variable (h1_total and h2_total or whatever you want to call it).After that it will be a if-elseif to go through the possible remaining results.

if(isBlackJack(h1)){ varResult = 15;
} //end blackjack checks
else {
// check non-blackjack results .. first setup hand totals
h1_total = getHandTotal(h1);
h2_total = getHandTotal(h2);
if(h1_total > 21)
{
varResult = -10;
}
else if( h2_total > 21)
{
varResult = 10;
}
else if(blah)
{
//blah
}
} // end non blackjack checks
return varResult;

public static int getHandTotal(Card [] h) - This method should return the total value of the hand passed into it. Various cards have the following values:

2 - 10: Two through ten points each respectively
Jack, Queen, or King: Ten points each
Ace: Eleven points (this differs from a regular Blackjack game where the value could be 1 or 11)

Loop through the array values, if its an ace add 11 to the total, if 10-K add 10, anything else add face value. Return the total.

public static boolean isBlackjack(Card [] h) - This method tests whether the hand passed in is a Blackjack hand. A Blackjack hand is any hand that sums to 21 with two cards. This requires that one be an ace and the other have a value of 10. This method will be used to determine the appropriate payout in the determineWinner() method.

Here is one that is much easier if you took my rerank suggestion earlier.

if( (h[0] == ace || h[1] == ace) && (h[0] == facecard || h[1] == facecard){
return TRUE; // blackjack
}
return FALSE; // everything else is not blackjack
Bury me a Royal.
Tavish
Mod in Retirement

Posts: 10554
(Past Year: -510)
Joined: 3 May 2004
Home Cafe: Baseball

### Re: Any Java Experts? Part 2!

I saw the thread title and I thought that it was about coffee. I love coffee.

I know nothing about programming except that it makes porn machines work.
Mookie4ever

Posts: 19019
(Past Year: -416)
Joined: 17 Dec 2003
Home Cafe: Baseball
Location: Hakuna, Montana

### Re: Any Java Experts? Part 2!

Look at your code for the golf game. You will use the same type of while loop to print the menu and ask for the user input.

Code: Select all
`if(determineWinner(userHand, cpuHand) >= 0){//comparing handsSystem.out.println("User Has Won");}else{System.out.println("CPU Has Won");}}int h1_total;int h2_total;if(isBlackJack(h1)){//if hand one is BlackJack...return 15;///...return 15} //end blackjack checks`

I'm assuming all the hand comparisons should be inside a function you are calling "determineWinner". determineWinner will return the value you want to change the players money by so set up a variable and make its value what is returned.

Code: Select all
`int handResult = determineWinner(userHand, cpuHand); // returned valueif(handResult >= 0){//comparing handsSystem.out.println("User Has Won");}else{System.out.println("CPU Has Won");}userMoney += handResult;  //win or lose you add the value to the player's money pool}public static int determineWinner(Card[] h1, Card[]h2){int h1_total;int h2_total;if(isBlackJack(h1)){//if hand one is BlackJack...return 15;} //end blackjack checks`
Bury me a Royal.
Tavish
Mod in Retirement

Posts: 10554
(Past Year: -510)
Joined: 3 May 2004
Home Cafe: Baseball

### Re: Any Java Experts? More Help!

Something like this?

Code: Select all
`public class FibonacciSum {      static final long FINAL_SUM = 4000000;              public static void main(String[] args) {          long i = 1;          long j = 2;          long k = j;               long sum = 0;                    if( k%2 == 0) {                  sum = sum + k;          }          k = i + j;                        while(k < FINAL_SUM) {              if( k%2 == 0) {                  sum = sum + k;              }              k = i + j;              i = j;              j = k;                    }                           System.out.println(" the sum is "+sum);      }              } `
The Artful Dodger
Chief Wikitect

Posts: 21871
(Past Year: 370)
Joined: 3 Feb 2006
Home Cafe: Baseball