Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Can someone programme for me?

1. Can someone programme for me?

Problem Description
Helen likes to have the occasional flutter (bet) on the horses. She likes to be able to see
what her winnings would be for various scenarios. You are to design and develop a bet
winnings calculation program for her.

The program should ask the user for the following information:
• The total stake (the amount bet)
• The name of the horse
• Whether the bet is for an outright win or it is an each-way bet
• The betting odds in this way:
o Enter the betting odds (X/Y)…
 Enter X > 11
 Enter Y > 10
o Odds are 11/10.
• The number of runners in the race
• The finishing position of the horse

There are some rules to consider when calculating the winnings:
• If there are 7 horses or less in the race, then only the first 2 places are considered for
each-way bets
• If there are between 8 and 20 horses in the race, then the first 3 places are
considered for each-way bets
• If there are more than 20, then the first 4 places are considered for each-way bets
Winnings are calculated as follows:
• Outright win bets: the winnings are the original stake + the odds multiplied by the
original stake
o Example: 5 euro win bet placed on a horse at 11/10
o = €5 + ( €5 * 11/10 ) = €10.50
• Each-way bets: Half of the stake is a standard outright win bet and is calculated as
above, e.g. a €5 each-way bet involves 2 x €5. The other half is applied in the
following way:
o If there are 2 places considered (see rules above), then half the odds are used
if the horse finishes first or second
o If there are 3 places considered, then a third of the odds are used if the horse
finishes first, second or third
o If there are 4 places considered, then a quarter of the odds are used if the
horse finishes first, second, third or fourth
o If the horses places, but does not win, then half the original stake is returned
along with the winnings
o If the horse wins, then the entire stake (i.e. both the win and place portions)
are returned along with the winnings

• You must format your output, e.g. winnings of zero as €0.00 or 5.3 as €5.30.
• The horse’s name must be output in all capitals.
• You must display 1st, 2nd, 3rd, 4th, etc. 10 would be 10th, 20 would be 20th, etc.
• You should include basic validation for all input – see the last example for checking
the finishing position; should also check that bet type is ‘E’ or ‘W’; should ensure that
the finishing position is not greater than the number of horses in the race.

Everything I have so far:
import java.util.Scanner;

public class part1 {

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double stake;
String horsesName;
double outrightWinOrEachWay;
double outrightWin;
double eachWay;
double OddsX;
double OddsY;
double totalOdds;
double eachWayOdds;
double runners;
double finishingPosition;
double winnings;
double win;
double place;

while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
stake = keyboard.nextFloat();

horsesName = keyboard.nextLine();

while ( horsesName.isEmpty() )

{
horsesName = keyboard.nextLine();
}

System.out.println("Enter the betting odds (x/y)");
System.out.println("X=");

while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
OddsX = keyboard.nextFloat();

System.out.println("Y=");
while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
OddsY = keyboard.nextFloat();

totalOdds = (OddsX/OddsY);

System.out.println("How many runners are in the race?");
while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
runners = keyboard.nextFloat();

while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
finishingPosition = keyboard.nextFloat();

System.out.println("(1) Outright Win");
System.out.println("(2) Eachway");
while (! keyboard.hasNextDouble() )
{
keyboard.nextLine();
}
outrightWinOrEachWay = keyboard.nextFloat();

if (outrightWinOrEachWay == 1)
{
if (finishingPosition == 1)
{
winnings = stake + (totalOdds * stake);
System.out.println(horsesName + " finished 1st out of " + runners + " runners");
System.out.println("You have won \u20ac" + winnings);
}

if (finishingPosition > 1)
{
System.out.println("Sorry you didn't win");
}
}

if (outrightWinOrEachWay == 2)
{
if (runners < 7)
{

eachWayOdds = (totalOdds/2);

if (finishingPosition == 1)
{
win = stake + (totalOdds * stake);
place = stake + (eachWayOdds * stake);
winnings = win + place;
System.out.println(horsesName + " finished 1st out of " + runners + " runners");
System.out.println("You have won \u20ac" + winnings);
}

if (finishingPosition ==2)
{
winnings = stake + (eachWayOdds * stake);
System.out.println(horsesName + " finished 1st out of " + runners + " runners");
System.out.println("You have won \u20ac" + winnings);
}

if (finishingPosition> 2){
System.out.println("Sorry you didn't win");
}

if (runners > 8)
{

}
}

}

}
}

2. Re: Can someone programme for me?

[code=java]
[/code]
to get highlighting and preserve formatting.

No.

4. Re: Can someone programme for me?

Originally Posted by chemical_dog
No.
Good luck.

5. Re: Can someone programme for me?

Did I do good?

7. Re: Can someone programme for me?

Originally Posted by Norm
No problems, I was just wondering if somebody would be ever so kind as to finish it for me? I would be forever in there debt.

8. Re: Can someone programme for me?

Sounds like you want to hire a programmer. I'll move this thread to another section.

Most sections here are for students trying to learn java programming.

9. Re: Can someone programme for me?

Thank you Mr. Norm.

--- Update ---

I wasn't planning on paying anyone for it though, just thought they'd do it out of the kindness of there hearts...

10. Re: Can someone programme for me?

To be blunt: this smells like homework, in which case it smells like academic dishonesty. Don't let someone else take take away the fun of doing it (as well as take away your education). If you're stuck, then post again with a specific question regarding where you are stuck. I am locking this thread.