I have a class, Terminus. I also have the class TerminusTest to test run the compilation of the whole Bus program which includes the ADT Bus class, Terminus, TerminusTest and Time ADT.

But when i try to run the TerminusTest which is the main program(client class), I do not get a sorted output, and the number of inputs that appears is not the number of inputs I input. Let's say the number of inputs given is 20, it does not happen that way. There is also an input box that pops up asking for a number of places required. The number I enter does not coincide with what comes out either.

There is also a problem in the edit method in the Terminus class.Please help me correct this error.

Besides can u help me correct my client class(TerminusTest) in case it has any errors. This class should be able to allow the user to addBus, sort the records, edit , delete, filter the records. But I am not sure how to do this.
Below is the code for the Terminus class, and below that is TerminusTest.

Please help me debug these codes.

Java Code:
Terminus.java

/**
* Terminus is to accept input from the user, using vector to store the information gathered.
* It has methods like readFile() to output data inserted into the vector,
* the writeFile() method to write input into the vector
* addBus() method to add data about the bus
* sort() method to sort data required
* filter() methods to filter results wanted only
* edit() and delete() methods to edit data and delete data in the vector
* display() method to display the final output
* @author (your AIGINI)
* @version (a version number or a date)
*/
import java.io.*;
import java.util.*;
import javax.swing.*;
import static javax.swing.JOptionPane.*;

public class Terminus
{
private Vector buses;
int choice = 0;
private int records;

public Terminus(){
buses = new Vector();
records = 0;
readFile();
}

/**method to get input from the user to add data into the vector
*@param b : bus number
* @param c : company name
* @param d : dayorder
* @param sh : starting hour
* @param sm : starting minute
* @param ss : starting seconds
* @param time : starting time
* @param n : to get the number of places for the bus to travel
*/
public void addBuss() {
do{
String b = JOptionPane.showInputDialog("Enter bus number :");

String c = JOptionPane.showInputDialog("Enter company name : ");

int d = Integer.parseInt(JOptionPane.showInputDialog("Select dayorder : 1-Sunday, 2-Monday, 3-Tuesday, 4-Wednesday, 5-Thursday, 6-Friday, 7-Saturday"));

int sh = Integer.parseInt(JOptionPane.showInputDialog("Enter hour :"));
int sm = Integer.parseInt(JOptionPane.showInputDialog("Enter minutes :"));
int ss = Integer.parseInt(JOptionPane.showInputDialog("Enter seconds :"));

Time t = new Time(sh,sm,ss);

int n = Integer.parseInt(showInputDialog("How many places?"));
Vector places = new Vector();

for(int i=0; i<=n; i++) {
String p = showInputDialog("Enter places:");
places.add(p);
}

Bus bs = new Bus (b, c, t, places, d);

buses.add(bs);

choice = Integer.parseInt(JOptionPane.showInputDialog("Next 1, Exit 0"));
}while(choice == 1);
writeFile();
sortBus();
}

/**To enter output data that has been written into the file.*/
public void readFile(){
buses = new Vector();
try {
FileInputStream fis = new FileInputStream("Terminus");
ObjectInputStream ois = new ObjectInputStream(fis);
Object obj = null;
do{
obj = ois.readObject();
if(obj != null) {
buses.add(obj);
System.out.println(((Bus)obj).toString());
}
}while(obj != null);
}catch(ClassNotFoundException ce){
System.err.println(ce.getMessage());
}catch(ClassCastException cce){
System.err.println(cce.getMessage());
}catch(IOException e){
System.err.println(e.getMessage());
}
}

/**To write data into the file*/
public void writeFile() {
try {
FileOutputStream fos = new FileOutputStream("Terminus", false);
ObjectOutputStream oos = new ObjectOutputStream(fos);
for(int i = 0; i < buses.size(); i++)
oos.writeObject(buses.get(i));
}catch(FileNotFoundException fe){
System.err.println(fe.getMessage());
}catch(IOException ioe){
System.err.println(ioe.getMessage());
}
}


/**To sort information dayorder wise*/
public void sortBus(){
Bus b [] = new Bus[buses.size()];

for(int i = 0; i < b.length; i++)
b = (Bus)buses.get(i);

//sorting as per dayorder
for(int i = 1; i < b.length; i++)
for(int j=0; j< b.length-1; j++)
if((b[j].getDayorder() < b[j+1].getDayorder()) ||
((b[j].getDayorder() == b[j+1].getDayorder() &&
(b[j].getS_Time().compareTo(b[j+1].getS_Time()) < 0))))
{
Bus temp = b[j];
b[j] = b[j+1];
b[j+1] = temp;
}

String output = "Bus Number\tCompany\tDay Order\tStart Time\t";

}

/**To display records*/
public void displayRecords(){
String output = "";
for(int i=0; i<buses.size(); i++){
output += ((Bus)buses.get(i)).toString()+"\n";
}
JTextArea tarea = new JTextArea();
tarea.setText(output);
JOptionPane.showMessageDialog(null, tarea);
}

/**To filter records time wise*/
public String filterTimeWise(){

Time from, to;

int s = Integer.parseInt(showInputDialog("from Seconds 1-60"));
int m = Integer.parseInt(showInputDialog("from Minutes 1-60"));
int h = Integer.parseInt(showInputDialog("from Hour 1-24"));

from = new Time(s, m, h);

s = Integer.parseInt(showInputDialog("To Seconds 1-60"));
m = Integer.parseInt(showInputDialog("To Mintues 1-60"));
h = Integer.parseInt(showInputDialog("To Hour 1-24"));

to = new Time(s, m, h);

String display = "";
for(int i=0; i><buses.size(); i++){
Bus b = (Bus)buses.get(i);
if(((b.getS_Time()).compareTo(from)>=0)&&((b.getS_Time()).compareTo(to)<=0))
display += b+"\n";
}
return display;
}

/**To filter records place wise
private String filterPlaceWise(String place){
String display = "";
for(int i=0; i<buses.size();i++)
if(((Bus)buses.get(i)).isGoing(place))
display += (Bus)buses.get(i) + "\n";
return display;
}
*/

/**To delete bus number of any buses*/
public void deleteRecord(String busnum){
for(int i=0; i><buses.size(); i++){
Bus b = (Bus)buses.get(i);

if((b.getBusnum()).compareTo(busnum)==0)
buses.removeElementAt(i);
}
}

/**To edit record in the file*/
public void editRecord(String busnum){

for(int i=0; i><buses.size(); i++){
Bus b = (Bus)buses.get(i);

if((b.getBusnum()).compareTo(busnum)==0){
buses.removeElementAt(i);
}
buses.insertElementAt((Object)i,1);
}
}
}

Java Code:
TerminusTest

/*
* TerminusTest.java
*
* Created on June 26, 2007, 9:37 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author AIGINI
*/
import javax.swing.*;
import static javax.swing.JOptionPane.*;

/**To test whether or not the program is running*/
public class TerminusTest {
public static void main(String args[]){
Terminus tm = new Terminus();

int n = Integer.parseInt(showInputDialog("Enter number of inputs : "));
for(int i = 0; i >< n; i++)
tm.addBuss();
tm.displayRecords();
}
}
Besides, I shall also include the 'Time' ADT for the compilation of the whole bus program :

Java Code:
Time.java

/*
* Time.java
*
* Created on June 17, 2007, 2:08 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author AIGINI
*/
public class Time implements java.io.Serializable{
/**initializing variables*/
private int hour, minute, second;
/**method to set time*/
public Time(int h, int m, int s) {
if (h < 0 || h > 23 || m < 0 || m > 60 || s < 0 || s > 60 )
setTime(0, 0, 0);
else setTime(h, m, s);
}
/**method to explain varibles used*/
private void setTime(int h, int m, int s) {
hour = h;
minute = m;
second = s;
}
/**method to get the hour*/
public int getHour() {
return hour;
}
/**method to get the number of minutes*/
public int getMinute() {
return minute;
}
/**method to get the number of seconds*/
public int getSecond() {
return second;
}
/**method to show the output if one time input is equal to the other time input*/
public boolean isEqual(Time that) {
return (that.getHour() == hour && that.getMinute() == minute && that.getSecond() == second);
}
/**method to compare two different times*/
public int compareTo(Time that) {
if (that.getHour() == hour && that.getMinute() == minute && that.getSecond() == second) return 0;
else if (that.getHour() > hour && that.getMinute() > minute && that.getSecond() > second) return -1;
else return 1;
}

/**method to return hour, minute and second of a requested time*/
public String toString() {
return hour + ":" + minute + ":" + second;
}
}