Cannot Find Symbol (Pointing towards "new" in my initiation of a new class object)?
For a homework assignment I have a "health" or basically a BMI/BMR calculator. When I try to create a new class object using values picked up previously in my Tester class by the scanner it's telling me cannot find symbol. I feel as if it's something obvious but at the same the fact that I'm getting an error doing such a common thing as creating a new object is stumping me.
EDIT: Also wasn't sure how best to paste or point out the line where the error occurs but it's halfway down on the Tester code. I tried to bold it but I didn't wanna break the scroll box.
Actual Error:
HowHealthy.java:87: cannot find symbol
symbol : constructor Healthy(java.lang.String,char,double,double,int)
location: class Healthy
Healthy healthObj1 = new Healthy(name, genderStatus, weight, height, age);
Class:
public class Healthy
{
// define attributes
private String name;
private char gender;
private double weight;
private double height;
private double weightMetric;
private double heightMetric;
private int age;
private double finalBMR;
private double finalBMI;
private double finalTDEE;
private final double CENTIMETER_CONVERSION = 2.54;
private final double KILOGRAM_CONVERSION = 0.45359237;
/* Creates constructor with default values
*/
public Healthy()
{
name = "";
weight = 0.0;
height = 0.0;
age = 0;
}
/* Creates constructor with initialized values
*/
public Healthy(String inName, char inGender, double inWeight, double inHeight, int inAge, int inActLevel)
{
name = inName;
gender = inGender;
weight = inWeight;
height = inHeight;
age = inAge;
}
} // end class Healthy
Tester
import java.util.Scanner;
/*
* A class to test the Healthy Class
*/
public class HowHealthy
{
public static void main (String[] args)
{
//Declarations
String name;
String gender;
char genderStatus;
double weight;
String weightStatus;
double height;
int age;
int level;
//Create Health object
Healthy healthTest = new Healthy();
//Get and validate info
Scanner scan = new Scanner(System.in);
//Enter name
System.out.print("Person's name: ");
String nameScan = scan.nextLine();
if (nameScan.length() > 0)
{
name = nameScan;
}
else
{
System.out.println("ERROR: Name must include at least one character");
System.exit(0);
}
//Enter gender
System.out.printf("\n%s, are you male or female (M/F): ", nameScan);
char genderScan = scan.nextLine().toUpperCase().charAt(0);
if ((genderScan == 'M') || (genderScan == 'F'))
{
genderStatus = genderScan;
}
else
{
System.out.println("ERROR: Gender must be either M or F");
System.exit(0);
}
//Enter weight
System.out.printf("\n%s's weight (pounds): ", nameScan);
double weightScan = scan.nextDouble();
if (weightScan >= 100)
{
weight = weightScan;
}
else
{
System.out.println("ERROR: Weight must be at least 100 pounds");
System.exit(0);
}
//Enter height
System.out.printf("\n%s's height (inches): ", nameScan);
double heightScan = scan.nextDouble();
if (heightScan >= 60 && heightScan <= 84)
{
height = heightScan;
}
else
{
System.out.println("ERROR: Height must be between 60 to 84 inches");
System.exit(0);
}
//Enter age
System.out.printf("\n%s's age (years): ", nameScan);
int ageScan = scan.nextInt();
if (ageScan >= 18)
{
age = ageScan;
}
else
{
System.out.println("ERROR: Must be at least 18 years old");
System.exit(0);
}
//Creating another Health object using values declared f开发者_运维技巧rom Scanner
**Healthy healthObj1 = new Healthy(name, genderStatus, weight, height, age);**
System.out.println("\nActivity Level: Use these categories: ");
System.out.println("\t1 - Sedentary (little or no exercise, desk job)");
System.out.println("\t2 - Lightly active (little exercise / sports 3-5 days/wk");
System.out.println("\t3 - Moderately active(moderate exercise / sports 3-5 days/wk)");
System.out.println("\t4 - Very active (hard exercise / sports 6 -7 day/wk)");
System.out.println("\t5 - Extra active (hard daily exercise / sports physical \n\t job or 2X day training i.e marathon, contest, etc.)");
System.out.print("\n\nHow active are you? ");
int levelTemp = scan.nextInt();
/*Validate the level input */
if ((levelTemp >= 1) && (levelTemp <= 5))
{
level = levelTemp;
} //if
else
{
System.out.println("Invalid leve - must between 1 to 5");
System.exit(0);
} //else
System.out.printf("\n\n%s's information\n", name);
System.out.printf("Weight: %.1f pounds \n", healthObj1.getWeight());
System.out.printf("Height: %.1f inches \n", healthObj1.getHeight());
System.out.printf("Age: %d years \n", healthObj1.getAge());
/*Give the proper syntax for gender */
if (genderStatus == 'M')
{
gender = "Male";
if(genderStatus =='F')
{
gender = "Female";
}
}
System.out.print("These are for a " + gender + ".\n\n");
System.out.printf("BMR: %.2f pounds\n", healthObj1.getBMI(weight, height)); //Pass the weight and height
System.out.printf("BMI: %.2f inches\n", healthObj1.getBMR(genderStatus)); //Pass the gender
System.out.printf("TDEE: %.2f years\n", healthObj1.getTDEE(level)); // Pass the level
/*Give the overall status of the weight */
if ((healthObj1.getBMI(weight, height)< 18.5))
{
weightStatus = "Underweight";
}
else if((healthObj1.getBMI(weight, height)>= 18.5) && (healthObj1.getBMI(weight, height)< 25))
{
weightStatus = "Normal weight";
}
else if((healthObj1.getBMI(weight, height)>= 25) && (healthObj1.getBMI(weight, height)< 30))
{
weightStatus = "Overweight";
}
else if((healthObj1.getBMI(weight, height)>= 30))
{
weightStatus = "Obese";
}
System.out.println("Your BMI classifies you as " + weightStatus);
} // end class main
} // end class HowHealthy
^
Your constructor is expecting 6 arguments and you're only passing 5 (the inActLevel is missing :)).
Healthy healthObj1 = new Healthy(name, genderStatus, weight, height, age);
While:
public Healthy(String inName, char inGender, double inWeight, double inHeight, int inAge, int inActLevel) {...}
Edit: And you're missing the getters and setters in your Healthy class but I don't know if it's because you didn't paste everything ^^
精彩评论