Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

import java.util.

Scanner;
import java.util.Random;
/*
AUTHOR : ASHER JEREMY NEUMANN GONZALEZ
Program knows three stations: Bristol, Reading and York
*/
class getterandsetter
{
// Main method, where the program begins
public static void main(String args[])
{
String response = question("What station do you need to know about?").toLowerCase(); // Ask
users for station
station[] railway_info = createRecord(); // Holds records of the three stations
String print_out = message(railway_info,response); // Passes users response and the three
known stations and a message is returned
System.out.println(print_out); // Prints out message.

}
/*
This method will print out the message to the user
Uses a switch statement, comparing the users response with each case
*/
public static String message(station[] a, String answer_from_user)
{
/* where:
a[0] = bristol
a[1] = Reading
a[2] = york
*/
String print_message;
switch(answer_from_user)
{
case "bristol":
if(getWheelchair_access(a[0])) // if(True)
{
print_message = "Bristol is operated by Great Western and has step free access.";
}else
{
print_message ="Bristol is operated by Great Western and has no step free access.";
}
break;
case "reading":
if(getWheelchair_access(a[1])) // if(True)
{
print_message ="Reading is operated by Great Western and has step free access.";
}else
{
print_message ="Reading is operated by Great Western and has no step free
access.";
}
break;
case "york":
if(getWheelchair_access(a[2])) // if(True)
{
print_message ="York is operated by Great Western and has step free access.";
}else
{
print_message ="York is operated by Great Western and has no step free access.";
}
break;
default:
print_message = "I do not know that station.";
break;

}
return print_message;
}
/* This method creates three records of type Station.
Each record represents a station and contains their zone and whethere they have
wheelchair_access.
The three records are returned in an array of type station.
Initialisation method.
*/
public static station[] createRecord()
{

station bristol = new station();


setZone(bristol, 1);
setWheelchair_access(bristol, false);

station reading = new station();


setZone(reading, 2);
setWheelchair_access(reading, true);

station york = new station();


setZone(york, 3);
setWheelchair_access(york, true);

station[] aa = {bristol, reading, york};


return aa;

}
// General method used to ask the question
public static String question(String a)
{
Scanner scanner = new Scanner(System.in);
System.out.println(a);
return scanner.nextLine();
}

// Getters
public static int getZone(station a)
{
return a.zone;
}
public static boolean getWheelchair_access(station a)
{
return a.wheelchair_access;
}
// Setters:
public static station setZone(station a, int zone)
{
a.zone = zone;
return a;
}
public static station setWheelchair_access(station a, boolean access)
{
a.wheelchair_access = access;
return a;
}

// Record type named station


class station
{
int zone;
boolean wheelchair_access;
}

You might also like