can anyone find my mistake in TrainingZone.java

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 1
Reputation: chengineer is an unknown quantity at this point 
Solved Threads: 0
chengineer chengineer is offline Offline
Newbie Poster

can anyone find my mistake in TrainingZone.java

 
0
  #1
Nov 1st, 2008
hi,i started to learn java nearly 2 weeks ago so i dont know java clearly,i try to write a program about trainingzone.
i must provide an interactive training zonecalculator that prompts a user for age.
i write a program but it gives errors and i dont improve this,if anyone can help me i will be too happy ,maybe most of people know this program and it seems easy but please dont forget im starter of java.Already now thanks to everybody..
  1. //Purpose:compute a heart beat training zone for your age of interest
  2. import java.util.*;
  3. public class TrainingZone{
  4. //main():application entry point
  5. public static void main(string[]args){
  6. //defining constants
  7. final double LOW_ZONE_MULTIPLIER=0.65;
  8. final double HIGH_ZONE_MULTIPLIER=0.80;
  9. final double BASE_RATE=220.0;
  10.  
  11. //displaying legend(step1)
  12. System.out.println("Heart beat estimator");
  13. //get person's characteristics
  14. System.out.print("Enter age(years): ");
  15. double age = stdin.nextDouble();
  16.  
  17. //perform trainingZone
  18. double trainingzone=HIGH_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);
  19. double trainingzone=LOW_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest); //display result
  20. System.out.println("Suggested heart beat training zone for");
  21. System.out.println("a fit person"+"age of interest"+"years with normal");
  22. System.out.println("heart rate is"+"low BeatRate"+"to");
  23. System.out.println ("high BeatRate"+"beats per minute");
  24. }
  25. }
  26.  
  27.  
  28. it gives ')'expected errors on
  29. double trainingzone=HIGH_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);
  30. double trainingzone=LOW_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);
im waiting to your help)
Last edited by ~s.o.s~; Nov 1st, 2008 at 9:36 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: can anyone find my mistake in TrainingZone.java

 
0
  #2
Nov 1st, 2008
well you have a few mistakes.. For ex. ageOf Interest is what? I mean is it a variable (and should be ageOfInterest)? Then, you define twice the variable trainingzone. The second one should be trainingzone1 or something like that. And to read double values from standard input you need first to init your stdin variable like this:
  1. Scanner stdin = new Scanner(System.in);
Last edited by Chaster; Nov 1st, 2008 at 7:56 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: can anyone find my mistake in TrainingZone.java

 
0
  #3
Nov 1st, 2008
Chaster is correct, you must define your variables before you use them. A variable in computer science is the same as it is in normal algebra. For example, x and y are commonly used variables in algebra. Similarly, in Java programming, you can define your own variables. To define a variable of type double named Age of Interest, do the following.

double age_Of_Interest;

Please note the following things about the declaration above:
  • it is intentionally spelled age_Of_Interest because, by convention, variable names start with a lowercase letter. Each word in the variable name (except the first word) starts with an uppercase letter.
  • Java does not allow you to put spaces in your variable names, so if you want to separate words, you have to do so using underscores. ( _ )
  • After the declaration above, age_Of_Interest does not have a value. Giving a variable a value is called "initializing the variable". So after we declared the variable, if we had said age_Of_Interest = 3.5, that is initializing the variable.
  • A variable can only be declared once. When you first put the type and the name of the variable, that declares it. So double age_Of_Interest; is a variable declaration.
  • You should not use a variable before it is declared and initialized. And the compiler will not let you use a variable that is not declared, which is why you got errors.
  • The first time you say double age_Of_Interest; you are creating a variable called age_Of_Interest. After you do that, if you say double age_Of_Interest; again, you are trying to create a variable that already exists, which does not make sense and is not allowed. To use the variable after its been declared/created, all you have to do is say age_Of_Interest.
Last edited by BestJewSinceJC; Nov 1st, 2008 at 4:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: can anyone find my mistake in TrainingZone.java

 
0
  #4
Nov 1st, 2008
A quick example of what I explained in my post above. Comments start with // and are either above the line they refer to, or next to the line they refer to.


  1. public class UsingVariables{
  2.  
  3. public static void main(String[] args){
  4. int aNewVariable = 0; //creates 'aNewVariable' & initializes it to 0.
  5. //creates 'a_Different_Variable' & doesn't initialize it.
  6. int a_Different_Variable;
  7.  
  8. System.out.println(aNewVariable); //This will print 0
  9.  
  10. //We didn't initialize the variable & can't be sure what this prints
  11. System.out.println(a_Different_Variable);
  12.  
  13. //Not allowed. a_Different_Variable already exists!
  14. int a_Different_Variable = 5;
  15.  
  16. //This initializes a_Different_Variable to 5.
  17. a_Different_Variable = 5;
  18.  
  19. System.out.println(a_Different_Variable); //This will print 5.
  20. }
  21. }
Last edited by BestJewSinceJC; Nov 1st, 2008 at 5:04 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: can anyone find my mistake in TrainingZone.java

 
1
  #5
Nov 1st, 2008
Originally Posted by chengineer View Post
can anyone find my mistake in TrainingZone.java
Yes.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC