This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cyberschool Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cyberschool Assignment" Watch "Cyberschool Assignment" New topic
Author

Cyberschool Assignment

Isaac Davis
Greenhorn

Joined: Oct 24, 2010
Posts: 15
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
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Isaac Davis
Greenhorn

Joined: Oct 24, 2010
Posts: 15
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

Joined: Oct 13, 2005
Posts: 38057
    
  22
Welcome to the Ranch

Please use the code button and indent your code.
Isaac Davis
Greenhorn

Joined: Oct 24, 2010
Posts: 15
I don't see an edit button anywhere
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Oct 24, 2010
Posts: 15
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

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Oct 24, 2010
Posts: 15
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

Joined: Oct 24, 2010
Posts: 15
Nvm figured everything out and got everything working properly. Thanks for all the info and help folks.
 
Don't get me started about those stupid light bulbs.
 
subject: Cyberschool Assignment
 
Similar Threads
Problems w/ a HashMap
Need help with structure...
Why does cons remain equal to null?
problems with math methods
I dont get the "get and set" method for my homework