Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    TheFlash

    Join Date
    Oct 2018
    Country
    Posts
    4
    Thanked
    5
    Thanks
    2
    I have an assignment for Java due 22hours from when I post this, this assignment should be fairly easy to an experienced Java programmer. I guess what I'm' asking is for someone to complete the project and show me theirs so I can continue where I got stuck and see what I'm doing wrong (I'm stuck on question 5). If you see this post after its due and feel like doing it please go ahead, the more help the better. The assignment goes as followed.

    For this assignment, you will write a program to compile the statistics of baseball players. For simplicity, we will not read the data from the user, but just hardcode it in our program. Here is what the output of your program would look like (Joe and Jerry are 2 baseball players here):

    Statistics for Joe
    atBats=11 hits=3 home_runs=1 avg=0.273
    Statistics for Jerry
    atBats=6 hits=3 home_runs=1 avg=0.500
    Jerry (0.500) has a better average than Joe (0.273)
    Number of Home Runs for Joe: 1
    Number of Home Runs for Joe after the change: 0

    Steps:
    1. Create 2 classes: one driver class (with the main method) and one class named “BaseballPlayerStats”.

    2. Add the following instance variables to your BaseballPlayerStats class: • Name of the player • Number of times at bats • Number of hits • Number of home runs • Number of games played

    3. Add a constructor that initializes the name to the one passed in the parameters, and resets all other variables to zero.

    4. Add a method “playGame” that will be used to update the statistics based on a new game played. This method should have the following parameters: number of times at bats for that game, as well the number of those that were hits and the number of those that were home runs (note: a home run counts both as home run and a hit). Your method should take these 3 numbers and increase the respective instance variable by such numbers. Your method should also add 1 to the number of games played. There is nothing returned by this method.

    5. In the main method, create an object representing the baseball player Joe. Make him play 3 games, with the following statistics:
    Game 1: at bats = 4; hits = 2; home runs = 0
    Game 2: at bats = 3; hits = 0; home runs = 0
    Game 3: at bats = 4, hits = 1; home runs = 1

    6. Add an accessor method for the name variable in the BaseballPlayerStats class. In the main method, call this method and use its result to print the first line of output above.

    7. Add a method “calculateAverage” in the BaseballPlayerStats class, with no parameter. In this method, calculate the average for the player as the number of hits divided by the number of times at bats. Note: type cast one of your variable to a double in order to force the use of the regular division, not the integer one (which would always return 0 as a result here!). Return the result.

    8. Add a method “printAllStats” in the BaseballPlayerStats class, with no parameters and returning nothing. Make this method print a line like the second one in the expected output above. Of course, you should use the values stored in the instance variables, not just printing that exact string! For the average part, you should first get it by calling the calculateAverage method. You should also print it with exactly 3 decimal places. Finally, the whole line is indented using one tab at the beginning. In your main method, add a line of code to call this printAllStats method.

    9. In the main method, create a second baseball player Jerry. Do the same method calls as for Joe in order to print the 3rd and 4th line of output above. Here are the games played by Jerry and his statistics:
    Game 1: at bats = 1; hits = 1; home runs = 1
    Game 2: at bats = 5; hits = 2; home runs = 0

    10. Add a “toString” method in the BaseballPlayerStats class. Make it build a string such as “Joe (0.273)”. The number in parentheses is obtained by calling the calculateAverage method, and formatting it nicely to exactly 3 decimal places.

    11. In the main method, write a System.out.println statement that produces the 5th line of output above. You do not have to make the comparison yourself: just print the object representing Jerry, then the words “has a better average than”, and finally the object representing Joe.

    12. Add an accessor and a mutator method for the instance variable representing the number of home runs.

    13. In the main method, write the code to print the 6th line of output above. You should get the number of home runs by calling the related accessor method. Then use the mutator method to change the number of home runs to zero, and print the last line of output above (again calling the accessor method).

  2. #2
    Bunny's Avatar woof.

    Join Date
    Mar 2014
    Country
    Posts
    5,292
    Thanked
    2,873
    Thanks
    1,244
    This is all very easy to do but takes an hour or more to do. Absolutely nobody is going to do it for you, so get working.

  3. #3
    Bipolarity's Avatar ɪɴᴄᴏɢɴɪᴛᴏ

    Join Date
    Aug 2018
    Country
    Posts
    270
    Thanked
    290
    Thanks
    298
    Offer a prize and someone might even do it for you here.
    Also, try posting on reddit

  4. The following user said thank you to Bipolarity for this useful post:

    lucc666 (10-01-2018)

  5. #4
    Student's Avatar Learning...

    Join Date
    Jan 2015
    Country
    Posts
    120
    Thanked
    60
    Thanks
    19
    Lol, no one will waste times for this.
    Life is like riding a bicycle. To keep your balance, you must keep moving.
    ― Albert Einstein

  6. #5
    TheFlash

    Join Date
    Oct 2018
    Country
    Posts
    4
    Thanked
    5
    Thanks
    2
    Thanks I'll try that!

  7. #6
    StephanM's Avatar 🌹

    Join Date
    May 2009
    Country
    Posts
    16,637
    Thanked
    1,735
    Thanks
    5,423
    Try stackflow.

  8. The following user said thank you to StephanM for this useful post:

    lucc666 (10-01-2018)

  9. #7
    GeorgeGFX's Avatar secret.club

    Join Date
    Nov 2010
    Country
    Posts
    15,459
    Thanked
    2,331
    Thanks
    5,080
    Would you accept C#/JS code as well without comments of the code?..
    The assignment is pretty easy and doesn't require much work but keep in mind this is a private server of a game, not a programming community such as SOF..
    If you are up for the assignment written in another language, hit me up, you'll have to translate the logic on Java later on though by yourself.

    >>> Credits to Sikk408 @ DevaintArt <<<

  10. The following user said thank you to GeorgeGFX for this useful post:

    lucc666 (10-01-2018)

  11. #8
    TheFlash

    Join Date
    Oct 2018
    Country
    Posts
    4
    Thanked
    5
    Thanks
    2
    I'd be very grateful if you could write it in any of those codes.
    Yes, I understand that. Will post in a better location next time.

  12. #9
    Dave's Avatar 1' or 1=1--

    Join Date
    Aug 2008
    Country
    Posts
    24,014
    Thanked
    115
    Thanks
    12,958
    It's a terrible thing, I think, in life to wait until you're ready.
    I have this feeling now that actually no one is ever ready to do anything.
    There is almost no such thing as ready. There is only now.
    And you may as well do it now. Generally speaking, now is as good a time as any.

  13. The following 7 users say thank you to Dave for this useful post:

    Bipolarity (10-02-2018), Canpai (10-02-2018), GeorgeGFX (10-01-2018), Hulk (10-02-2018), Jonathan pls (10-01-2018), lucc666 (10-01-2018), Ommadawn (10-01-2018)

  14. #10
    Jonathan pls's Avatar Uh suma luma duma luma

    Join Date
    Jun 2013
    Country
    Posts
    826
    Thanked
    1,312
    Thanks
    494
    Originally Posted by Bunny View Post
    This is all very easy to do but takes an hour or more to do. Absolutely nobody is going to do it for you, so get working.

    Shoutout to Dave for proving you wrong

    faith in humanity restored

  15. The following 6 users say thank you to Jonathan pls for this useful post:

    Bunny (10-01-2018), Canpai (10-02-2018), Hulk (10-02-2018), lucc666 (10-01-2018), Ommadawn (10-01-2018), Skilly (10-01-2018)

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)