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>

[2979 byte] By [Aiginia] at [2007-11-27 9:00:23]
# 1

> ...

> 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++){

>

> f(((String)(places.get(i))).compareTo(place)==0)

> break;

> if(i==places.size()) return false;

> else

>return true;

>

> error message that pops up says that this method

> does not have a return statement.

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()) // this cannot happen!

return false;

else

return true;

}

// This is where the code continues if the 'break;' statement is excecuted

// What will be returned?

}

Perhaps the following is more appropriate:

public boolean isGoing(String place) {

return places.contains(place);

}

>

prometheuzza at 2007-7-12 21:28:58 > top of Java-index,Java Essentials,Java Programming...