Tuesday 15 June 2010

Java compiler won't find methods from another Java file in same folder? -



Java compiler won't find methods from another Java file in same folder? -

our assignment take code our instructor gave us, , write methods that code calls in separate java file. after that, we're supposed set in same folder. here code gave us:

import java.util.scanner; public class cscd210lab9 { public static void main(string [] args) { scanner kb = new scanner(system.in); string name = null; double height, weight; { name = lab9methods.readname(kb); height = lab9methods.readinfo(kb, "height"); weight = lab9methods.readinfo("weight", kb); lab9methods.displayresults(name, height, weight, lab9methods.calcbmi(height, weight)); }while(lab9methods.goagain(kb)); }// end main }// end class

i've compiled file wrote methods in, , compiles fine, no errors @ all. however, when go compile code right after, compiler points every instance lab9methods written, , gives error "error: cannot find symbol".

i don't understand why won't read methods other file, though both files in same folder. doing wrong?

edit

here code lab9methods class.

import java.util.scanner; public class lab9methods { public static string readname(final scanner kb)throws exception { if(kb == null) throw new runtimeexception("precondition not met"); string name; system.out.println("please come in person's name: "); name = kb.nextline(); homecoming name; } public static double readinfo(final scanner kb, final string str) { system.out.println("please come in your" + str + ";"); double height = kb.nextdouble(); homecoming height; } public static double readinfo(final string str ,final scanner kb) { system.out.println("please come in your" + str + ";"); double weight = readinfo(kb,str); homecoming weight; } public static int calcbmi(double height, double weight) { int calcbmi = (int)(weight/((height * height) * 703)); homecoming calcbmi ; } public static void displayresults(final string name, final double height, final double weight, final double bmi) { system.out.println(name + "with weight of" + weight + "and height of" + height + " " + bmi); if(bmi < 18.5) { system.out.println("you underweight"); } else if(bmi > 18.6 && bmi < 24.9) { system.out.println("you normal"); } else if(bmi > 25.1 && bmi < 29.9) { system.out.println("you overweight"); } else if(bmi > 29.9) { system.out.println("you obese"); } } public static boolean goagain(final scanner kb) { boolean goagain = false; string answer; system.out.println("do want go 1 time again (yes/no) :"); reply = kb.nextline(); while(!answer.equals("yes") && !answer.equals("no")) { system.out.print("error re-try, want go 1 time again (yes/no) :"); reply = kb.nextline(); } if(answer.equals("yes")) { goagain = true; } else if(answer.equals("no")) { goagain = false; } homecoming goagain; } }

try downloading ide (eclipse or intellij community edition example) , doing project in that. guess need declare 'package' should map directory classes in.

and tell tutor style more c java, , //end main , //end class went out of fashion long time ago ;)

java methods

No comments:

Post a Comment