Originally Posted by
helloworld922
Make sure your two classes know where each other are. If they are in the same package/folder, there's not really any extra work needed. If they are in different packages, you must import from the class that is using the other class. If they are in different project all-together, you'll need to figure out some way to either link projects together, or tell your program where to look for that class.
Could you post either the compiler error or the runtime error you are getting?
Their both in the otherStuff package, so Im not sure if thats the problem. And the thing about the error is, Im getting no error whatsoever, just a non-functional piece of code. Heres the class I was trying to call a method from if it helps.
package OtherStuff;
import acm.program.ConsoleProgram;
public class ageCalc extends ConsoleProgram {
String status;
int x;
int y;
public void run() {
int yearBorn = readInt("Enter year you were born: ");
int currentYear = readInt("Enter current year: ");
int currentAge = currentYear - yearBorn;
while (true) {
int inputYear = readInt("\nEnter a year: ");
int futureYear = inputYear - yearBorn;
int pastYear = inputYear - yearBorn;
if (inputYear < currentYear & inputYear != yearBorn) {
println("You were " + pastYear + " years old on this date.");
}
if (inputYear == yearBorn) {
println("This was the year you were born, and you are currently " + currentAge + " years old right now.");
}
if (inputYear > currentYear & inputYear != yearBorn) {
println("You will be " + futureYear + " years old in this year.");
}
if (inputYear == currentYear) {
println("This is the current year, and you are " + currentAge + " years old this year.");
}
}
}
}
Also, the method startAgeCalc in the original posted code was removed from the ageCalc class, and replaced with run(). They were the same exact copy and pasted piece of code, but I was just trying to experiment when I did that. So all in all, when you see startAgeCalc in the original post, that should be run().