-
October 13th, 2011, 09:31 PM
#1
Cannot find Symbol Error
Hi, first I would like to say that it is a pleasure to be part of this forum.
Anyways I have an assignment due, and I am a perfectionist, so it is bugging me that it will not compile properly.
Here is the assignment: You are planning to transport a large number of people on a trip. You have 45-passenger buses and 16-passenger vans at your disposal. Any bus you use must be completely filled, and any remaining passengers transported by van.
You must write a Java program that returns the necessary numbers or each type of vehicle given the number of students to be transported. There should be methods to determine the number of buses, the number of vans and a main method to test them.
Here is what I have done so far:
public class bAndV{
public static void main (String args[]) {
System.out.println (bus(151));
System.out.println (vans());
}
public static int bus(int bus){
return bus/45;
}
public static int vans(int vans){
int rem = bus % 45;
if (rem % 45== 0)
return (0);
else
return ((rem/16)+1);
}
}
Error i recieve: cannot find symbol - variable bus
What must I do for the second method to identify bus as a variable from the first method? Thank you for the help.
-
October 14th, 2011, 01:46 AM
#2
Re: Cannot find Symbol Error
Hi,
Please use code tags for code.
You can save what bus() function returns into a variable to be passed to vans() function as an argument.
Code:
int busValue = bus(151);
int vansValue = vans(busValue);
You also have a mistake in vans() functions, where you are using an undeclared bus variable. I guess what you want is:
Code:
public static int vans(int vans){
int rem = vans % 45;
if (rem % 45== 0)
return (0);
else
return ((rem/16)+1);
}
Regards,
Albert.
Please, correct me. I'm just learning.... and sorry for my english :-)
-
October 14th, 2011, 10:33 AM
#3
Re: Cannot find Symbol Error
To add a little to Albert's, it is generally considered bad practice to name your variables and methods the same. It can cause confusion when reading the code (yes, I know: methods have the parens, but still).
-
October 15th, 2011, 07:23 AM
#4
Re: Cannot find Symbol Error
Code:
int rem = vans % 45;
if (rem % 45== 0)
What is the point of using the remainder operator in the if statement. 'rem' already holds the remainder of the division of vans (which as ProgramThis has already stated is a poor name) by 45. Therefore it is going to be a number between 0 and 44 inclusive and so applying the remainder operator again is going to have no effect.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|