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 4 of 4

Thread: A quick help to complete my program :D

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default A quick help to complete my program :D

    Hello java members i want to u if u can to help me how i can canculate something in a particular method i think is simple but im stuck on that ;p

    The program is asking to find the average age of passengers in a buss let me explain u some things first about what the class what need to contain and ofcourse i will post my code to check what mistakes may did
    Okey Every buss must have a number and an array 60 slots of passengers.The buss class also contain a method witch addPassengers() to a buss and method GetNumberOfPassengers() witch return the number of passengers in a buss.Also the class contains the GetAverageAge() witch canculate the average of their age.How i will canculate their age?Let me inform you that the program also contains more classes like rout,passenger,RouteManager witch contains the main method.If u need any further information reply.Thanks for your time!

    public class Buss {
     
     
    	private Passenger [] listpassenger = new Passenger[60];
    	int numpassenger = 0;
     
     
     
    	public void addpassenger(Passenger passenger){
     
    		 listpassenger[numpassenger]= passenger;
     
    		 numpassenger++;
    	}
     
     
    	public int getnumberofpassengers(){
     
    		return numpassenger;
    	}
     
     
    	public void getaverageage(){
     
     
    	}
     
    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: A quick help to complete my program :D

    How would you calculate the average age if someone handed you a sheet of paper with a bunch of names with numbers next to them? What steps would you take?

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: A quick help to complete my program :D

    i would make the summary of the numbers of their age and div them with the number of the ppl.. but here im confused..My age variable with other information about passengers is in another class passengers so if i use for ex numpassenger/age; it will show me error :/

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: A quick help to complete my program :D

    The age information is in the class Passengers, but your Bus class happens to handily have an array of Passenger objects, and you can extract the necessary information from these objects by looping through the array.

Similar Threads

  1. Complete Newbie needs help Please!
    By kungfuthug in forum Java IDEs
    Replies: 0
    Last Post: February 27th, 2013, 09:49 PM
  2. Complete java
    By abhaygautam in forum Java Theory & Questions
    Replies: 2
    Last Post: February 24th, 2013, 01:22 PM
  3. [SOLVED] Code Complete?
    By remedys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 15th, 2013, 06:15 AM
  4. Beginner seeking help with quick problem in program
    By Gravs2889 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 23rd, 2012, 10:59 PM