1 Replies - 779 Views - Last Post: 09 March 2009 - 09:26 PM Rate Topic: -----

#1 MV1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-March 09

Return object called

Post icon  Posted 09 March 2009 - 05:51 PM

Hi, all i am creating a timetable program, which should when a destination is typed in return all instances of that destination. At the moment i can get it to read in a name and return that same name but i cannot get it to return the times associated with it.
import java.io.*;
import java.util.*;

public class Buses
{
	public Buses()
	{
		System.out.println("Please enter Destination:");
		ReadIn in = new ReadIn();
		String s = in.readString();

		System.out.println("Your destination is:");
		System.out.println("\n" + s);
		System.out.println("Your departure time:");
		System.out.println("Your arrival time:");

	}

	public static void main(String args[])
	{
		new Buses();

		Journey busJourney[] = new Journey[15];

		busJourney[0] = new Journey(9.25,"Thornhill",9.50);
		busJourney[1] = new Journey(9.55,"Newport",10.20);
		busJourney[2] = new Journey(10.00,"Llanishen",10.25);
		busJourney[3] = new Journey(10.10,"Thornhill",10.35);
		busJourney[4] = new Journey(10.25,"Llanishen",10.50);
		busJourney[5] = new Journey(10.35,"Thornhill",11.00);
		busJourney[6] = new Journey(10.55,"Pembroke",11.15);
		busJourney[7] = new Journey(11.05,"Thornhill",11.35);
		busJourney[8] = new Journey(11.25,"Newport",11.55);
		busJourney[9] = new Journey(11.50,"Llanishen",12.10);
		busJourney[10] = new Journey(12.05,"Thornhill",12.25);
		busJourney[11] = new Journey(12.20,"Llanishen",12.45);
		busJourney[12] = new Journey(12.35,"Thornhill",13.00);
		busJourney[13] = new Journey(12.55,"Pembroke",13.10);
		busJourney[14] = new Journey(13.20,"Thornhill",13.35);

	}
}

class ReadIn {
	static InputStreamReader is = new InputStreamReader( System.in );
	static BufferedReader br = new BufferedReader( is );
	StringTokenizer st;

	StringTokenizer getToken() throws IOException
	{
	   String s = br.readLine();
	   return new StringTokenizer(s);
	}

	String readString()
	{
	   try
	   {
		 return br.readLine();
	   }
	   catch (IOException ioe)
	   {
		  System.err.println("IO Exception in ReadIn.readString");
		  return "";
	   }
	}
}


public class Journey
{

		Double fdeparture;
		String fdestination;
		Double farrival;


		public Journey(Double departure, String destination, Double arrival)
		{
			fdeparture = departure;
			fdestination = destination;
			farrival = arrival;
		}

}

Your help will be very much apprciated and i am eager to learn how to do these tasks.

Is This A Good Question/Topic? 0
  • +

Replies To: Return object called

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Return object called

Posted 09 March 2009 - 09:26 PM

In the journey class. I would make a getter for depature and arrival.
public double getDeparture()
{
	return fdeparture;
}


and so forth for the destination and the arrival. Then you can call those methods in the other class

This post has been edited by Fuzzyness: 09 March 2009 - 09:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1