Isaac Davis

Greenhorn
+ Follow
since Oct 24, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Isaac Davis

Thanks for all the help folks, I've figured it out now. I saw these messages today because my internet connection was down yesterday. A friend of mine taught me how to do what I was trying to do so I figured it out, but I will definitely keep these things in mind, and use them for future reference. Once again I greatly appreciate all the help.
14 years ago
I'm extremely confused on the use of static methods. I've been writing a code to calculate the surface gravity of each planet in our solar system. I got help from my teacher and I thought I understood but when I tried to finish the program I was still very confused. I know the problems somewhere in the main method and the static void method printResults. The main problem I'm really having is referencing things. I'm not sure how to tell another method to grab info from the main method and print that out. I'm just really confused, any help or refernce to a good static method tutorial or anything that will help will be appreciated.

14 years ago

Stephan van Hulst wrote:It doesn't say in the requirements you need a nested loop.



It isn't very specific but it does say it in the grading rubric, and the assignment is going to be turned in as Assignment 5.05 nested loops. So I'm pretty sure it had to use nested loops, believe me if it was my choice I wouldn't use nested loops for this.
14 years ago

Stephan van Hulst wrote:I apologize, I didn't notice you already had a variable with that name. I meant a new variable, which you have interpreted correctly.

Anyway, looking at your program, I don't see why it would keep asking for input. You should have an entirely different problem on your hand, namely that you're stuck in a permanent loop. Have a look at the exit condition of your nested for loop.

By the way, you can also eliminate a lot in your display code.

If I may give you a big hint, I think you are using the nested loop for the wrong purpose. Tell me, how many dice do you have?



That's the format the displays supposed to go in, according to the example given by my teacher. These are the assignment instructions, and I have to use nested loops because of the section I'm on, it's an Ap class that i take online. So it's mostly self learned.

1. Create a new project called 5.05 Random Dice in the Mod05
Assignments folder.
2. Create a class called DiceProbability in the newly created project
folder.
3. Ask the user to input how many times the dice will be rolled.
4. Calculate the probability of each combination of dice. (You may want to start with
more familiar six-sided dice.)
5. Print the results neatly in two columns (do not worry about excessive decimal places).
6. What is the effect on the percentages when the number of rolls is increased?
7. After the program works, you might want to make it more interesting and ask the user
to enter the number of sides on a die (singular for dice).
14 years ago

Stephan van Hulst wrote:First of all, start by making your program more clear by eliminating all the 'cases' you use. You can store your values in a simple array like this:

rolls[random -1]++;

This will *greatly* decrease the verbosity of your program, and make it more clear why it's doing what it does.



I can't use rolls to store my values, rolls needs to be a number put in by the user because it determines how many times a dice would be rolled. The only real use I have for it is to determine when the main for loop ends. Then I need compare each new random to 1-12, to determine how many times that number has been rolled. I sort of understand what you're getting at with rolls[random -1]++ but I'm not quite sure how to assign the array as you're trying to point out.

Anyways this is what I've worked out according to what I think you mean. Still get the same issue though. I think it's asking for a new rolls every time the for loop runs through, any idea how to fix that?

14 years ago
One of my assignments requires that I make a program that will calculate dice probability using nested loops(no idea why nested loops would be used here). I've written it out, and I get no compiling errors, but when I actually run the program for some reason it won't stop asking for user input, any advice as to why it does this would be helpful. I think the problems inside the for loop because without it there is no repetitive issue. I think the for loop isn't taking the value of rolls and is actually asking for it, but I need that value in there.

14 years ago

Paul Beckett wrote:Make sense now?


Yeah I get it now, I guess I had just figured that would be ignored but now I see what you're saying. I really appreciate your help and everyone elses, thanks a ton folks. I'm pretty sure I should be able to fix it now, just gotta work through the rest of it. Oh and thanks for the new vocab word(Tautology) Ritchie.
14 years ago

fred rosenberger wrote:I corrected your code tags to get it to display better.
[edit]apparently there was a minor bug in our release that cause the code tags to not work correctly.[\edit]

The first tip i have is to ask you to explain what "it runs but, but not correctly" means. What do you expect it to do, and what does it do? Why is that not what you expect? We have no way to know how to 'fix' the code to get it to do what you expect if we don't know what that is.

The easier you make it for someone to help you, the more likely you are to get that help.



Right now it's set up to create a random number between 100 and 999 I have it set up so that it shows what that number is so I can test it, when i test the program it doesn't run correctly because let's say the number is 600, if I put in 600 it doesn't say the user has won, this
is supposed to make it do that. The other two wins are supposed to be triggered if the user's inputted number has the same first two numbers or last two numbers as the number randomly selected. Hope that explains that well enough if not I don't mind trying to explain it more specifically again. Thanks for the help, sorry for not being specific enough.


Paul Beckett wrote: think about your conditional logic. Hint: You have four conditions, the first two are "equal" and "not equal".


Not sure what you mean, my first condition (the for loop) runs the loops if the remaining tries the user has doesn't equal 5. and the second compares the number the user puts in to the random number, and then if it's not equal it prompts the user for a new guess(entry).

Sean Clark wrote: Oops, I see why you have used it, please ignore me.


Don't sweat it , I appreciate you trying to help.

Lester Burnham wrote: You're using the "==" operator to compare strings - BIG no-no! You need to use the "equals" method instead.


I wasn't aware that the == couldn't be used for strings as well, i thought it was just used for anything within a boolean statement (if,for,while etc.), it's worked fine for me before but I don't think I was comparing strings then, thanks for the tip. I've changed that but I'm still getting the same results, it's only printing the first if statement that prompts the user for a new entry.
14 years ago
I'm not sure what's wrong with it, I don't get any compiling errors and it runs but, but not correctly.

This is my Code, any help/tips for future programs would be appreciated.



14 years ago
Nvm figured everything out and got everything working properly. Thanks for all the info and help folks.
14 years ago

Campbell Ritchie wrote:It was your heart rate thing I executed, not the random thing.
Have you read the documentation for the nextInt method? I think you have completely misunderstood what the (int) bit means.



I had found a few ways to fix my program and get it to work before I had seen your post, so this version is just the work I turned in, I thought someone might want to see it, I think I got 100 on this (which made me very happy). Since turning this in I think I've been using the scanner class a bit more effectively for other assignments. Right now the only assignment truly troubling me though is the one I posted above. Also what do you mean by I have everything in the main method? I'm not sure where else to put the code.

In more detail(I've made some changes)


14 years ago
Thanks, for the advice, in the end I ended up with this.



I hadn't read that last post yet, but I'm very new to programming and I still don't know much about it. I try to learn more but I tend to stick to what I know. Since my last post I've been making lots of progress in my class, but I found myself stuck yet again. We've started working with while loops and I've become stuck because the assignment is rather difficult (for me anyway). If anyone's up for helping me again I'd appreciate it.

These are my assignment instructions: Write a program that randomly chooses a secret number within a specified range (e,g., 125 and 175 inclusively). Ask the user to enter the range as a high value and a low value separated by a blank space. The computer should then randomly guess the secret number that was chosen. Then count the number of guesses required to find a match.

This is the code I've written so far, I've rewritten this and tried several things but I've run out of ideas. I'd appreciate any form of help (well minus having the assignment done for me).



I don't get any errors while compiling but the program just doesn't work.
14 years ago
I don't see an edit button anywhere
14 years ago
You sir, are my hero.

Thanks for the help, I'd parsed some of the other parts of this but for some reason I hadn't considered that, that needed parsing as well.
14 years ago
Hi, I'm new to Java, started learning it this year in an online class and I haven't had many issues so far until right about now. I keep getting this error saying, "Operator >= cannot be applied to java.land.String,int". I need to set this up so that my program will say whether or not the heart rate after exercising is within a targeted zone, but I'm confused as to how to do it. Please help.
This is what I have so far.




I need to set the rest of this program up so that it compares the lowEndOfTrainingHeartRate and highEndOfTrainingHeartRate to the heartAfterExercise. Then the program needs to state whether it is within the target zone or not.




Any help given would be appreciated.

14 years ago