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!
Code :
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(){
}
}
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?
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 :/
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.