Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2007, 03:57 PM
Member
 
Join Date: Jun 2007
Posts: 21
ai_2007 is on a distinguished road
Problems in running client class
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.

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); } } }

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 :

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; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inner class problems orchid New To Java 2 08-13-2008 09:56 AM
When to use –client and -server option while running a java program Java Tip java.lang 0 04-04-2008 03:49 PM
problems with class Splashscreen in netbeans ernieBob NetBeans 0 02-07-2008 02:30 AM
how to create java client to access web services running on https/ssl navneet1083 NetBeans 0 11-13-2007 11:13 AM
Problems with client and server Albert Advanced Java 2 07-02-2007 07:07 AM


All times are GMT +3. The time now is 04:02 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org