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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Can someone programme for me?

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy 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

    Additional Notes
    • 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;
     
     
     
    				System.out.println("Please enter your stake:");
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				stake = keyboard.nextFloat(); 
     
     
    				horsesName = keyboard.nextLine(); 
     
    				while ( horsesName.isEmpty() ) 
     
    				{ 
    				 System.out.print("What is your horses name?"); 
    				 horsesName = keyboard.nextLine(); 
    				} 
     
    				System.out.println("Enter the betting odds (x/y)");
    				System.out.println("X=");
     
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				OddsX = keyboard.nextFloat(); 
     
    				System.out.println("Y=");
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				OddsY = keyboard.nextFloat(); 
     
    				totalOdds = (OddsX/OddsY);
     
    				System.out.println("How many runners are in the race?");
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				runners = keyboard.nextFloat(); 
     
    				System.out.println("What is your finishing position?");
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				finishingPosition = keyboard.nextFloat(); 
     
    				System.out.println("Is your bet a:");
    				System.out.println("(1) Outright Win");
    				System.out.println("(2) Eachway");
    				while (! keyboard.hasNextDouble() ) 
    				{  
    				 keyboard.nextLine(); 
    				 System.out.print("Please try again "); 
    				} 
    				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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,106
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Can someone programme for me?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Add some comments or specific questions about the problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can someone programme for me?

    No.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,106
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Can someone programme for me?

    Quote Originally Posted by chemical_dog View Post
    No.
    Good luck.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can someone programme for me?

    Did I do good?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,106
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Can someone programme for me?

    Add some comments or specific questions about the problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can someone programme for me?

    Quote Originally Posted by Norm View Post
    Add some comments or specific questions about the problems you are having.
    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. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,106
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default 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.

Similar Threads

  1. Java programme design help
    By dulitul in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 29th, 2013, 06:06 PM
  2. Help with designing a library programme
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 8th, 2012, 04:40 AM
  3. please correct my programme on swings
    By jeevan reddy mandali in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 6th, 2012, 02:32 AM
  4. [SOLVED] I have a problem with this Joption programme.
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 12th, 2011, 03:31 AM
  5. help with bookfinder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 01:15 PM

Tags for this Thread