Error in ADT class
I have created an ADT class Bus with all the methods necessary. A method in this class will be called in a method in another class 'Terminus'. This method(in 'Terminus') will filter records place of travel wise on any day listing the buses.
But I seem to have a problem in this method (Bus class) when i try to compile the Bus class. The method is shown below:
public boolean isGoing(String place){
for(int i=0; i<places.size(); i++){
if(((String)(places.get(i))).compareTo(place)==0) break;
if(i==places.size()) return false;
else
return true;
}
The error message that pops up says that this method does not have a return statement.
The whole code for this class(Bus class) is :
/**
* Class to initialize all the variables in bus.
* @param busnum : bus number
* @param s_time : start time
* @param places : places of travel by user
* @param dayorder : To store the dayorder according to String array days
*
* @author (AIGINI)
* @version (a version number or a date)
*/
import java.util.*;
public class Bus
{
private String busnum, company;
private Time s_time;
private Vector places;
private String days[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
private int dayorder;
/**To set an empty constructor in Bus*/
public Bus() { setData (null, null, null, null, 0); }
/**To set a proper constructor for class Bus*/
public Bus (String b, String c, Time st, Vector p, int dy) {
setData(b, c, st,p, dy);
}
/**To create a set method for class Bus*/
private void setData(String b, String c, Time st, Vector p, int dy)
{
busnum = b;
company = c;
s_time = st;
places = p;
dayorder = dy;
}
/**To get the bus number from user*/
public String getBusnum()
{
return busnum;
}
/**To get company name from user*/
public String getCompany()
{
return company;
}
/**To get start time from user*/
public Time getS_Time()
{
return s_time;
}
/**To get places from user*/
public Vector getPlaces(){
return places;
}
/**To get day order from user*/
public int getDayorder()
{
return dayorder;
}
/**to return true or false when moving from one place to another*/
public boolean isGoing(String place){
for(int i=0; i><places.size(); i++){
if(((String)(places.get(i))).compareTo(place)==0) break;
if(i==places.size()) return false;
else
return true;
}
}
/**To return output*/
public String toString()
{
return busnum + "\t" + company + "\t" + dayorder + "\t" + s_time + "\t" + places;
}
}
Message was edited by:
Aigini>

