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