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..

//Purpose:compute a heart beat training zone for your age of interest
import java.util.*;
public class TrainingZone{
//main():application entry point
public static void main(string[]args){
//defining constants
	final double LOW_ZONE_MULTIPLIER=0.65;
	final double HIGH_ZONE_MULTIPLIER=0.80;
	final double BASE_RATE=220.0;
	//displaying legend(step1)
	System.out.println("Heart beat estimator");
	 //get person's characteristics
	System.out.print("Enter age(years): ");
	double age = stdin.nextDouble();
	//perform trainingZone
                double trainingzone=HIGH_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);
   	double trainingzone=LOW_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest); 	//display result
	System.out.println("Suggested heart beat training zone for");
	System.out.println("a fit person"+"age of interest"+"years with normal");
	System.out.println("heart rate is"+"low BeatRate"+"to");
	System.out.println ("high BeatRate"+"beats per minute");  

it gives    ')'expected  errors on 
   double trainingzone=HIGH_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);
   double trainingzone=LOW_ZONE_MULTIPLIER*(BASE_RATE-ageOf Interest);

im waiting to your help:))

8 Years
Discussion Span
Last Post by masijade

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:

Scanner stdin = new Scanner(System.in);

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.

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.

public class UsingVariables{

   public static void main(String[] args){
     int aNewVariable = 0; //creates 'aNewVariable' & initializes it to 0.
     //creates 'a_Different_Variable' & doesn't initialize it.
     int a_Different_Variable; 

     System.out.println(aNewVariable); //This will print 0

    //We didn't initialize the variable & can't be sure what this prints

     //Not allowed. a_Different_Variable already exists!
     int a_Different_Variable = 5; 

     //This initializes a_Different_Variable to 5.
     a_Different_Variable = 5; 

     System.out.println(a_Different_Variable); //This will print 5.

can anyone find my mistake in TrainingZone.java


Votes + Comments
to the point, brief and a technical correct answer :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.