Loading
View RSS Feed

yusuf keil

TCS ILP Case Study : Railway Management System

Rate this Entry
Trivandrum Railway station

is a busy station with number of trains arriving and departing each day. The

station has five platforms. The task of scheduling trains to different platforms is quite a redundant task
and hence the station authorities have requested to automate the process of scheduling trains to different
platforms based on platform availability on arrival. Make train scheduler software which correctly
manages scheduling of train to different platforms and marks their arrival and departure.
Develop the classes RailwayStation, Train, Platform and implement following business behaviors:

1) Maintain a list of trains that arrive at the station.


2). Remove a departing train from the list.


3) At any time user should able to find a train that has been scheduled for arrival at the station given it's
name.

4) Set an arriving train's wait state to true if all platforms are occupied and it cannot be allocated a
platform.

5) On departure of a Train from the Railway Station, assign the free platform to a waiting train, if any.




1.Train:

Train should know about the trainName ,arrivalTime and its waitStatus .
NB: waitStatus tells whether all platforms are occupied or not. If all platforms are occupied then the wait status need to be set as true or else false.
1.a) Train(String trainName,String arrivalTime) :Constructor to initialize Train object. This should also set its wait property to false.

2.Platform

Platform should know about the platformNumber , the train to which platform is allotted , and isAllottedStatus flag. isAllotedStatus will be true if a train is allotted to that platform or else it will be false.
2.a) Platform(int platformNumber) : Constructor to initialize Platform object. This should also set the isAllotedStatus flag to false and Train object to null.

3.RailwayStation

RailwayStation should know about the stationName , platformCount ,details of train arrived in the station and the details of all platforms.
PlatformCount - indicates the total number of platforms in the station.

3.a)RailwayStation(String stationName,int platformCount):Constructor to initialize Railway

Station object .Constructor should also create as many platforms as platformCount and add it to the platformList of RailwayStation.
Number of platform Objects to be created depends on the platformCount
Note: Platform number doesn’t start from 0.The platform numbers should be 1, 2, 3,4, ... and so on in ascending order. The platform objects should be saved in the array of platforms in the ascending order of platform number.

3.b)getFreePlatform() :Returns the first free platform in the Railway Station else returns null if no
platform is free
3.c)findTrain(String trainName): Returns a Train object that is arriving on the station on giving the Train Name else returns null if the train is not found.
3.d)trainArrival(String trainName,String arrivalTime):
Creates Train object and adds the new Train arriving at the station to trainList. If a platform is free, then
sets the new train on to the first free platform available and turns the isAllotedStatus flag of the platform to true; if the platform is not available sets the waitStatus flag of the new train to true.
3.e)assignPlatformToTrainOnWait():
Searches the trainList to find the first train which has wait flag set to true.
Allocates a free platform to this train which is on wait status by setting the train on the platform
Turns the isAllotedStatus flag of the platform to true.
Sets the waitStatus flag of the train to false.
3.f)trainDeparture(String trainName):
On departure of a train from the station, free the platform on which corresponding train had arrived also
remove the train from the trainList available at the RailwayStation. Also if there is any Train waiting for
a platform, assign the freed Platform to the Train which is first in the queue.
(Activities to be performed: Set isAllotedStatus of Platform to false, Set the Train on Platform to null,
Remove the train from the trainList, if there is any Train waiting for a platform, assign the freed
Platform to the Train which is first in the queue.)
3.g)getTrainOnPlatform(int PlatformNumber):Returns the Train that is allocated to a platform else
returns null if no Train is present on the given Platform
3.h)getAllotedPlatform(String trainName): Returns the Platform on which a Train has arrived on
giving the Train Name. If the Train has not been allotted any Platform returns null.
Also implement necessary getters and setters for all classes.


Train.java

Code:
public class Train {
	
	String trainName ;
	String arrivalTime;
	boolean waitStatus ;
	Train(String trainName,String arrivalTime)
	{
		this.waitStatus=false;
		this.arrivalTime=arrivalTime;
		this.trainName=trainName;
	}
	public String getTrainName() {
		return trainName;
	}
	public void setTrainName(String trainName) {
		this.trainName = trainName;
	}
	public String getArrivalTime() {
		return arrivalTime;
	}
	public void setArrivalTime(String arrivalTime) {
		this.arrivalTime = arrivalTime;
	}
	public boolean isWaitStatus() {
		return waitStatus;
	}
	public void setWaitStatus(boolean waitStatus) {
		this.waitStatus = waitStatus;
	}
	
}


Platform.java



Code:
public class Platform {
	
	int platformNumber;
	boolean isAllottedStatus;
	Train train;
	
	Platform(int platformNumber)
	{
		this.platformNumber=platformNumber;
		this.isAllottedStatus=false;
		this.train=null;
	}
}

RailwayStation.java
Code:
import java.util.ArrayList;



public class RailwayStation {
	String stationName;
	int platformCount;
	ArrayList<Platform> pList;
	ArrayList<Train> tList;
	
	RailwayStation(String stationName,int platformCount)
	{
		this.stationName=stationName;
		this.platformCount=platformCount;
		for(int i=1;i<=platformCount;i++)
		{
			pList.add(new Platform(i));
		}
	}
	Platform getFreePlatform() 
	{
		for(Platform p:pList)
		{
			if(p.isAllottedStatus)
			{
				return p;
			}
		}
		return null;
	}
	Train findTrain(String trainName)
	{
		for(Train t:tList)
		{
			if(t.getTrainName().equals(trainName))
			{	//if (!(t.waitStatus))
					return t;
			}
		}
		return null;
	}
	void trainArrival(String trainName,String arrivalTime)
	{
		Train newTrain=new Train(trainName,arrivalTime);
		tList.add(newTrain);
		Platform free=getFreePlatform();
		if(free==null)
			newTrain.setWaitStatus(true);
		else
		{
			free.setTrain(newTrain);
			free.setAllottedStatus(true);
		}
	}
	int assignPlatformToTrainOnWait()
	{
		for(Train t:tList)
		{
			if (t.waitStatus)
			{
				Platform free=getFreePlatform();
				if(free==null)
					return 0;
				else
				{
					free.setTrain(t);
					free.setAllottedStatus(true);
					t.setWaitStatus(false);
					return 1;
				}
			}
		}
		return -1;
	}
	int trainDeparture(String trainName)
	{
		for(Platform p:pList)
		{
			if(p.getTrain().getTrainName().equals(trainName))
			{
			 p.setTrain(null);
			 p.setAllottedStatus(false);
			 tList.remove(p.getTrain());
			 for(Train t:tList)
			 {
			 	if (t.waitStatus)
				{
			 		p.setTrain(t);
					p.setAllottedStatus(true);
					t.setWaitStatus(false);
				}
			 }	
			 return 1;
			}
		}	
		return -1;
	}
	Train getTrainOnPlatform(int platformNumber)
	{
		for(Platform p:pList)
		{
			if(p.getPlatformNumber()==platformNumber)
			{
				return p.getTrain();
			}
		}
		return null;
	}
	Platform getAllotedPlatform(String trainName)
	{
		for(Platform p:pList)
		{
			if(p.getTrain().getTrainName().equals(trainName))
			{
				return p;
			}
		}
		return null;
	}
}


Hope this code adds to your purpose. All the functions are properly coded. You just have to write the main class depending upon the way you want.
If there is any problem, comment in the comment section.

Submit "TCS ILP Case Study : Railway Management System" to Digg Submit "TCS ILP Case Study : Railway Management System" to del.icio.us Submit "TCS ILP Case Study : Railway Management System" to StumbleUpon Submit "TCS ILP Case Study : Railway Management System" to Google

Comments

  1. musaddiquesanderwale's Avatar
    String trainNames[]={"mahalaxmi exp","H.Nizamuddin exp","koyena exp","ilahabad exp","kudchi-miraj pasngr","pune-mumbai exp","gondia exp","ajmer superfast","rani channamma exp"};
    String arrivalTime[]={"8.23","12.43","15.33","7.00","22.43","4.22","11 .36","5.23","19.43"};
    public void putPlatform()
    {
    for(int i=0;i<platformNum.length;i++)
    {
    platList.add(new Platform(platformNum[i]));

    }
    }

    public void dispPlatform()
    {
    for(Platform p:platList)
    {

    System.out.println("PlatformNum:"+p.getplatformNum ber()+"\tAlloted Status:"+p.getAllotedStatus()+"\tAlloted Train:"+p.getTrain().getTrainName());
    }
    }


    when i use dispPlatform() null pointer exception is occured....plz help....thanks
    i want to display null value in p.getTrain().getTrainName()......
  2. musaddiquesanderwale's Avatar
    no need to reply

    problem has solved....


    plz tell me how to upload solution
  3. purnima.gahlaut's Avatar
    [U][/U][B][U][LEFT][COLOR="#0000CD"][SIZE=5]Pl provide sol. for main also ASAP.[/SIZE][/COLOR][/LEFT][/U][/B]
  4. Unregistered's Avatar
    this is something similar to that..

    //package CricketTeam;

    import java.util.*;
    import java.lang.String;
    import java.io.*;

    public class CricketTeam{

    public static void main(String [] args) throws IOException{

    int optionEntered;
    // Scanner keyboard = new Scanner(System.in);

    System.out.print("create team press - 1 \nremove team press - 2\nedit team press - 3\nview team details press - 4\nenter option: ");

    // optionEntered = keyboard.nextInt();
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    optionEntered = Integer.parseInt(bf.readLine());



    if(optionEntered==1){
    System.out.print("\nenter country name: ");
    String countryName = bf.readLine();
    System.out.print("\nenter team name: ");
    String teamName = bf.readLine();
    System.out.print("\nenter coach name: ");
    String coachName = bf.readLine();

    Team team = new Team(countryName, teamName, coachName);
    team.setPlayer();
    }


    }
    }


    class Team{

    private String countryName,teamName, coachName;
    ArrayList playerdetails = new ArrayList();

    Team(String countryName,String teamName,String coachName ){
    this.countryName = countryName;
    this.teamName = teamName;
    this.coachName = coachName;

    }
    void setPlayer() throws IOException{
    BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in));

    for(int count=0; count<3; count++ ){
    System.out.print("\nenter"+(count+1)+" player name: ");
    String playerName =bf1.readLine();
    System.out.print("\nenter player age: ");
    int age =Integer.parseInt(bf1.readLine());
    System.out.print("\nability: ");
    String ability =bf1.readLine();
    Player newPlayer =new Player(playerName,age,ability);
    playerdetails.add(newPlayer);

    }
    Collections.sort(playerdetails, new comparator());
    public int compare(Player player1, Player player2)
    {

    return player1.playerName.compareTo(player2.playerName);
    }


    }
    }

    class Player{
    String playerName , ability;
    int age;

    Player(String player,int age, String ability){

    this.playerName = player;
    this.age = age;
    this.ability = ability;
    // System.out.println("in player ");
    }
    public String toString(){
    return "playerName "+playerName+"age "+age+" ability "+ability;
    }


    }
  5. Unregistered's Avatar
    import java.util.*;
    import java.lang.String;
    import java.io.*;


    public class User{
    public static void main(String [] args) throws IOException{
    ArrayList applicants = new ArrayList();
    ArrayList interviewers = new ArrayList();

    while(true){
    System.out.println("\n**************************** ********* ");
    System.out.println("choice task");
    System.out.println("1----> enter applicant data");
    System.out.println("2----> view applicants");
    System.out.println("3----> enter interviewer data");
    System.out.println("4----> view interviewers");
    System.out.println("5----> schedule an interview");
    Scanner scn = new Scanner(System.in);
    System.out.print("enter option: ");
    int choice = scn.nextInt();


    if(choice==1)
    {
    Applicant newApplicant = new Applicant();
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("\nenter the name of applicant:");
    String appName = bf.readLine();
    newApplicant.name = appName;
    System.out.print("\nenter the age of applicant:");
    int appage = Integer.parseInt(bf.readLine());
    newApplicant.age = appage;
    System.out.print("\nenter the technology of applicant:");
    String appTech = bf.readLine();
    newApplicant.tech = appTech;
    System.out.print("\nenter the qualification of applicant:");
    String appquali = bf.readLine();
    newApplicant.qualification = appquali;
    System.out.print("\nenter the experience of applicant:");
    int appexp = Integer.parseInt(bf.readLine());
    newApplicant.exp = appexp;

    applicants.add(newApplicant);
    System.out.print("\n\n"+appName+" is saved.");
    do_continue();
    }

    if(choice==2){
    Iterator itr = applicants.iterator();
    while(itr.hasNext())
    {
    Applicant app = (Applicant)itr.next();
    System.out.print("\n\n"+app.name+"\nage:"+app.age+ "\ntechnology: "+app.tech+"\nqualification: "+app.qualification+"\nexperience: "+app.exp);

    }
    do_continue();
    }
    if(choice==3){
    Interviewer intvwr = new Interviewer();

    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("\nenter the name of interviewer:");
    String intName = bf.readLine();
    intvwr.name = intName;

    System.out.print("\nenter the technology:");
    String intTech = bf.readLine();
    intvwr.tech = intTech;

    System.out.print("\nenter the availability in the format mm/dd/yy:");
    String intavai = bf.readLine();
    intvwr.availability = intavai;

    interviewers.add(intvwr);
    System.out.print("\n\n"+intName+" is saved.");
    do_continue();
    }
    if(choice==4){
    Iterator itr1 = interviewers.iterator();
    while(itr1.hasNext())
    {
    Interviewer intvwr = (Interviewer)itr1.next();
    System.out.print("\n\n"+intvwr.name+"\ntechnology: "+intvwr.tech+"\navailability"+intvwr.availability );
    }
    do_continue();
    }
    if(choice==5){
    Iterator itra = applicants.iterator();
    Iterator itrb = interviewers.iterator();
    Interviewer intvwr;
    Applicant app;
    while(itra.hasNext()){
    app = (Applicant)itra.next();
    while(itrb.hasNext())
    {
    intvwr = (Interviewer)itrb.next();
    if(app.tech.equals(intvwr.tech)){
    System.out.print("\n\n"+app.name+" has an interview on "+intvwr.availability+" with "+intvwr.name);
    break;
    }
    throw new
    }
    }
    } //has to be completed. time constraint
    }

    }

    static boolean do_continue() throws IOException{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("\nto continue press 1 to exit press 2: ");
    int choice1 = Integer.parseInt(bf.readLine());
    if(choice1==2)
    {
    System.exit(0);
    }
    return true;
    }



    }

    class InterviewerNotFreeException extends Exception{
    InterviewerNotFreeException(){
    super();
    }

    InterviewerNotFreeException(String s){
    super(s);
    }
    }



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.