Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Help with final project  RSS feed

 
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have greatly appreciated all the help I have gotten from the Ranch thus far. Thanks to you guys I was able to finish two really difficult (for me) homework assignments. I come to you guys one more time for help on my final as I have no idea where to start.

I am to write a Java program that will take a user entered value for a free throws percentage. It will then show free throws made across 5 games played (10 attempts in each game). After the 5th games it will show a summary of the games played that shows the best game number of free throws made (showing how many free throws were made in the best game), worst game free throws made, total free throws made and their average percentage of free throws across their 5 games

I am not asking for someone to answer this for me. I want to solve it for Myself but I don't even know where to begin with this. My guess is to write 3 methods. One that takes the user input. One that would take the previous method and create 5 games with 10 free throws each. And a final method that creates the summary. Would I be on the right track there? Any and all help is greatly appreciated. Thank you
 
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a "free throw"? Is it an int? Are these user entered or randomly generated? What's the range of valid values?
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The free throw is a user entered int percentage ranging from 0 to 100
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry my apologies. The user is expected to enter a percentage of free throws made (this number would be an int between 0 and 100) then the program would take that number and figure out how to get that percentage across 5 games played with 10 attempts in each game
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought all games consisted of 10 free throws.
 
Sheriff
Posts: 23867
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I look at that, what I see is this: You have a thing called a Game. And a Game contains things called FreeThrow. And a FreeThrow can be made (or not, presumably). Also, each Game has to be able to tell the controller how many of its FreeThrows were made.

So far I don't see any methods. I see two classes, about which I know some things they need to do. So I would start by creating those classes.
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:[code=java]I thought all games consisted of 10 free throws.



Yes. So there would be 5 games played and show the results of those 10 attempts made

I'm not very good with explaining this. Here let me show the example that was given to me
FINALPROJECT.PNG
[Thumbnail for FINALPROJECT.PNG]
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

with 10 attempts in each game

What is an "attempt"?  Again, user entered?

Your requirements need an overhaul. Don't use a term without defining it first, e.g. "free throw", and "attempt".
Instead of sentences use bullet points. Bullet points are easier to decompose into programming steps.
If you are going to use an object oriented approach, that would suggest that you have a class called "Game".
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What determines "Out" vs "In"?
What is the purpose of entering the Player's Free Throw Percentage?
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The out vs in determines if the attempt was a success or not. I agree I don't really understand the purpose of having the user enter a percentage but from my understanding, the program is to take the total number of attempts made and the total number of successful free throws and give a percentage based on that
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it necessary to remember the actual In's and Out's, or can you just keep track of: number of free throws, and the number of free throws In?
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I don't think it is necessary to display it but it would need to be tracked. What I mean by free throws made are the actual attempt. Free throws in would be a successful attempt
 
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what determines if a free throw results in an "in" or "out"?
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user entered percentage. The idea is to take the user entered int and get as close to that as possible by the end of the 5 games
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that a random number is involved.
 
Piet Souris
Master Rancher
Posts: 3001
105
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, for my understanding, something like this:

A game would then invoke 10 times this method, determine how many times we determine an "in"?


Edit: added "101"  between the parentheses. Sorry!
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that seems to be right. The idea is to take the user entered percentage and then run 5 games with 10 attempts in each game and approximate the user entered percentage.
 
Piet Souris
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'Game' has, as it is called, a Binomial distribution with parameters 10 (the number of free thows) and a succespercentage per throw of that UserDefinedPercentage. The mean is 10 * (percentage / 100), et cetera.
(but that doesn't help you create a Game class).

Given what a class should be able to output, can you come up with a Game class? I.E. what is needed to output the 10 attempts, how would you get the mean of all the attempts, et cetera?
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My teacher confirmed for me. The way it determines in or out is a random number. So the user will enter their percentage then the program will use a random number to see if it goes in or out. If it's less than or equal to the percentage the user entered. It's in. Over the percentage is out. I'm starting to get it but I'm not sure I understand yet.

My running idea so far is to make 2 methods. One method will take the user entered percentage (0-100) int and then generate a random number and compare that number to the user percentage. It will do this 10 times per game and it will play 5 games. The final method will print the results of the games and show which game had the highest number of "in" free throws and which game had the highest number of "out" free throws. Finally it will display the percentage of free throws made across all 5 games. It's starting to make sense to me but I'm unsure of the execution
 
Marshal
Posts: 61715
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should forget about “methods” etc. for the time being. Start by writing down as simply as possible what the game is supposed to do, not how you are going to do it. Once you have got the “what” part working nicely, it will guide you into how to write the code.
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so what the game is supposed to do is to take a user inputted number (testing to make sure the number is between 0 and 100) and compare that to a random number. If the random number is higher than the user entered number. The "free throw" is out. If it is less than or equal to that number, the free throw is in. It will do this 10 times for one "game". Then it will run 5 "games". At the end of the 5th game, it will produce a summary that will show what game had the most "in" what game had the most "out" and what the actual percentage of shots were "in" compared to total shots made

So I've made a start. Tell me what you guys think



Am I heading in the right direction?
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You are still concentrating on the details before coming up with a coherent design. The design should give you a better idea of how to implement the details.

Also your method does not incorporate a loop to reprompt the uses if their input is invalid.
 
Campbell Ritchie
Marshal
Posts: 61715
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to avoid the ≤ and ≥ operators if I can, simply because > and < are easier to read. If you want 100 to be the maximum value try ... > 100. If you want 0 to be a prohibited value, well, then maybe <= 0  still works. That test doesn't fulfil

make sure the number is between 0 and 100

If you want to prompt the user for repeated in put, you would want a loop rather than an if. That method belongs in a utility class sepaarate from the other code. Don't create a new Scanner reading from System.in. Create one Scanner per application and use it repeatedly.
 
Sean Mcintosh
Ranch Hand
Posts: 63
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Campbell, I was wondering where that was going wrong. I'll work on getting that corrected so that 0 and 100 are good because I do want both options just nothing above those numbers obviously


I'm sorry Carey I don't know what to do because I thought I had a decent idea of what the design should be but you're telling me I don't. I thought that getting the user inputted percentage. creating the "free throw" of comparing that number to the a math.random number to determine "in" vs "out, and then looping that 10 times to create a "game" was the right direction. Guess not. What step am I doing wrong here?
 
Carey Brown
Saloon Keeper
Posts: 5140
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need a "Game" class? If you had one, what would it contain? What methods would it have? Do you need to keep track of the individual In's and Out's or can you just keep a count of the number of In's? Would you keep an array or List of Game's? If so, how would you traverse the Game's to pull out the statistics you need? Would a Statistics class help? Where do you put the responsibility for printing? In the Game and Statistics classes?

These are the kind of questions to ask as you work out a design.

Some of the steps:
  • Start with a text description of the problem (you've already got this).
  • Break it down to bullet points.
  • Look for nouns (classes) and verbs (methods).
  • Look for IS-A and HAS-A relationships (inheritance and aggregation).
  • Work out the flow
  • Create pseudo code
  • Pick off one of the pieces of the pseudo code and implement it and compile it and test it.
  • repeat


  • Edit: Note that depending on your analytical abilities, some of these steps can be done in your head but in some cases pencil and paper will help.
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    An example:
    "Game" is one of the nouns in your stated problem, so lets assume you'll need a Game class. Next, look for IS-A relationships to Game. It doesn't appear that you have any other nouns with an IS-A relationship to Game, either as a parent or a child. Look for HAS-A relationships to Game. Possible contenders: a count of In's, an array of In's and Out's, a game number, number of attempts. Possible verbs: print, compute attempts. In order for Statistics to do its job Game will need to provide: game number, number of attempts, and number of In's.
     
    Sean Mcintosh
    Ranch Hand
    Posts: 63
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Classes were not covered in my course. While I am aware of using different classes I would think that would need to be avoided
    So I guess here are my bullet points

    Gather User Entered number for a percentage.

    User Entered number must be tested for validity (Value between 0 and 100)

    If the number is invalid, return invalid. If the number is vaild, store value

    Using the stored value from the user. Compare value to a randomly generated number.

    If the randomly generated number is higher than user entered value, the attempt is considered failed ("out")

    If the randomly generated number is lower or equal to the user entered value, the attempt is considered success ("in)

    These will be considered an "attempt" Loop "attempt" 10 times, this will constitute a "game"

    Loop "Game" 5 times

    After 5 "games" a summary will print

    This summary will have

    Best game (Which game had most "in")

    Worst game (Which game had most "out")

    The actual percentage of "in" compared to total number of attempts made

    Does this sound like I'm getting somewhere?
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So if classes are out....

    You have a nested set of loops:
    Now you could apply statistics as you go. That's one approach. Or, you could collect your games into a array of ints representing the number of In's in a game. Or, you could collect your game/attempts into a 2D array of booleans ("isIn"). Then post process the arrays to get the statistics.

    ** OR **
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Sean Mcintosh wrote:Classes were not covered in my course. While I am aware of using different classes I would think that would need to be avoided
    So I guess here are my bullet points

    Gather User Entered number for a percentage.

    User Entered number must be tested for validity (Value between 0 and 100)

    If the number is invalid, return invalid. If the number is vaild, store value

    Using the stored value from the user. Compare value to a randomly generated number.

    If the randomly generated number is higher than user entered value, the attempt is considered failed ("out")

    If the randomly generated number is lower or equal to the user entered value, the attempt is considered success ("in)

    These will be considered an "attempt" Loop "attempt" 10 times, this will constitute a "game"

    Loop "Game" 5 times

    After 5 "games" a summary will print

    This summary will have

    Best game (Which game had most "in")

    Worst game (Which game had most "out")

    The actual percentage of "in" compared to total number of attempts made

    Does this sound like I'm getting somewhere?

    Yes, exactly. I would have also added loop "Attempt" 10 times.
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A note about constants:
    Your program will have two constants: the number of games (5), and the number of attempts (10). Create static constants for this inside your class. This will make it possible to easily change later if you have to and it makes your code more readable. The naming convention for constants in Java is all upper case with words separated by underscores.
     
    Sean Mcintosh
    Ranch Hand
    Posts: 63
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, that makes sense to me! (I've always been more of a visual learner anyway)



    I know that's not quite right but am I going in the right direction?
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As previously mentioned, you should only have one System.in Scanner for the entire project, so make it a static final.

    Your previous attempt at a method to get the percentage was better except for needing a loop for invalid entries.
    This needs some work. You have the concept of "attempt", this is the act of getting a random number and comparing it to a percentage. You have "attempts" which is a quantity.
     
    Carey Brown
    Saloon Keeper
    Posts: 5140
    54
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Carey Brown wrote:

     
    Campbell Ritchie
    Marshal
    Posts: 61715
    193
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Sean Mcintosh wrote:Classes were not covered in my course. . . . .

    That is very unfortunate; Java┬« is supposed to be an object‑oriented language and that makes me suspect you maybe haven't been taught object‑oriented programming.
     
    Sean Mcintosh
    Ranch Hand
    Posts: 63
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Carey, I'll try that when I get home (had to go to work)

    Campbell, I think OOP will he covered in the next Java class in my University. This is just the basics and making sure you understand them (which I don't) which is why I've decided not to take the next class until I understand the basics a lot better
     
    Campbell Ritchie
    Marshal
    Posts: 61715
    193
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I would hope so, but you called that a final project so I thought you had completed the course.
     
    Sean Mcintosh
    Ranch Hand
    Posts: 63
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Final project for this course. This is Programming I . Still gotta take Programming II
     
    Sean Mcintosh
    Ranch Hand
    Posts: 63
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok so I've been talking to my teacher and I've made some progress but I'm not there yet. Here is what I've written so far



    What I'm trying to do is to have a method that takes the user entered percentage and ,in a another method, compares that a Math.random number. If it is higher than the user entered number it is "out" if it is less than or equal to it is "In". Am I heading in the right direction? What should I alter? Thanks for any help
     
    I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
    Download Free Java APIs to Work with Office Files and PDF
    htttp://www.e-iceblue.com/free-apis.html
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!