Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Variable Error

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    My Mood
    Sad
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Variable Error

    I posted this in the codeguru forum, but I decided to post here, because this is a forum specified for java, and it appears that users are active, so this will be the main java forum i use. All help is apprecieted

    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.


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Variable Error

    I didnt read your task but if u want to use static method in class u must use class name to initialize her. for example :
    class MyClass {
    static void myMethood(){}
    }
    if u want use myMethood() :
    MyClass.myMethood();

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Variable Error

    I think your should modify your second method first, since the vans is not used, and bus is not claimed.

    public static int vans(int vans){
    int rem = vans % 45;
    if (rem % 45== 0)
    return (0);
    else
    return ((rem/16)+1);
     
    }

    then call it by vans(151) as same as the first method.

Similar Threads

  1. non-static variable
    By frozen java in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 15th, 2011, 06:18 PM
  2. [SOLVED] what is this? Variable?
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 7th, 2011, 11:32 PM
  3. Must I add a Class Variable?
    By maress in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 04:40 AM
  4. How do I set a static variable??
    By wingchunjohn in forum Object Oriented Programming
    Replies: 4
    Last Post: January 22nd, 2010, 04:36 AM
  5. Semantic error: Variable assignment: please help!!
    By humdinger in forum Java Theory & Questions
    Replies: 1
    Last Post: November 17th, 2009, 02:28 PM