File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cyberschool Assignment

 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Davis wrote:I keep getting this error saying, "Operator >= cannot be applied to java.land.String,int".


Well, the error is pretty clear -- the compiler is saying that it can't check for whether a string is greater than or equal to an int. In fact, you can't do that comparison with any strings. You need to parse the string into a type, where you can apply that operator to it.

Henry

 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use the code button and indent your code.
 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see an edit button anywhere
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Davis wrote:I don't see an edit button anywhere
No, it vanishes some time after you have posted. I'll take pity on you because you are new and see if I can edit that post.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have lots and lots in the main method. That is not usually a good idea. You ought to remove almost all that code and put it into other methods.
Why are you parsing what your Scanner returns? Scanner has methods for nextXXX which give you the result already parsed. Just beware with nextLine; it has a quirk which confuses lots of people, so make sure to ask if your Scanner gives you unexpected errors.
 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We often quote this FAQ ( ). You will have to tell us what happens when you run that class. It seemed to run when I tried it.
Why are you not using the nextXXX methods of Scanner?
Why have you still got all your code in the main method?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)


 
Isaac Davis
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nvm figured everything out and got everything working properly. Thanks for all the info and help folks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic