Results 1 to 2 of 2
  1. #1
    laurastrain is offline Member
    Join Date
    Apr 2017
    Posts
    1
    Rep Power
    0

    Default Help with Java coding problem I am working on. Cannot find my error(s)

    I am coding the following for a TrainTimeTable and keep getting error messages:


    TrainTimeTable.java:51: error: class, interface, or enum expected
    public Station(String city, Date arrival, Date departure, int day) {
    ^
    I am using JGrasp and would appreciate any feedback that might help resolve my error so that I can test and run the program. Thanks.

    import java.util.Date;

    import java.text.SimpleDateFormat;

    import java.util.Calendar;

    import java.util.GregorianCalendar;


    /*A train time table for a train travelling between Vancouver and
    *Toronto. Store the information from each row of the table in an
    *object. Then, arrange the objects in an ArrayList structure.
    * Your program should take th following commands in a continous loop:
    *i. show-shows the full table
    *ii. Delay<station>minutes> the arrival of the train is delayed by<minutes>
    */

    public class TrainTimeTable {

    private Date arrival;

    private Date departure;

    private String city;

    private int day;
    }
    /**

    *parameter for the arrival

    *parameter for the departure

    *parameter for the city

    */

    public Station(String city, Date arrival, Date departure, int day) {

    super();

    this.arrival = arrival;

    this.departure = departure;

    this.city = city;

    int = day;

    }

    /**

    * parameter for the arrival

    * set the arrival

    */

    public String getArrival() {

    if (arrival == null){

    return "";

    return new SimpleDateFormat("HH:mm").format(arrival);

    }

    public void setArrivalDate(Date arrival) {

    this.arrival = arrival;

    }

    public int getDay() {

    Calendar cal = new GregorianCalendar();

    if (departure == null) {

    cal.setTime(arrival);

    else

    cal.setTime(departure); // potential bug here. If delay/pull-up over a year


    return cal.get(Calendar.DAY_OF_YEAR);

    }


    public void setDay(String Day) {

    this.day = day;

    }

    public void displaySchedule() {

    System.out.printf("%16s\t%8s\t%8s\t%3d\n", getCity(), getArrival(),

    getDeparture(), getDay());

    }

    public void delay(int minutes) {

    // negative delay is permitted, but there is no guarantee on the date part

    Calendar cal = new GregorianCalendar();

    if (arrival != null) {

    cal.setTime(arrival);

    cal.add(Calendar.MINUTE, minutes);

    arrival = cal.getTime();



    if (departure != null) {

    cal.setTime(departure);

    cal.add(Calendar.MINUTE, minutes);

    departure = cal.getTime();

    }


    //get and return the departure

    public String getDeparture() {

    if (departure == null) {

    return "";

    return new SimpleDateFormat("HH:mm").format(departure);

    }


    /**

    *parameter of the departure

    *the departure to set

    */


    public void setDeparture(Date departure) {

    this.departure = departure;

    }


    /**

    * return the city

    */

    public String getCity() {

    return city;

    }

    /**

    * parameter of the city

    * set the city

    */


    public void setCity(String city) {

    this.city = city;

    }

    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Help with Java coding problem I am working on. Cannot find my error(s)

    When posting code please wrap it in code tags so it retains its formatting.

    You have declared a TrainTimetable class that looks like this:
    Java Code:
    public class TrainTimeTable {
    
    private Date arrival;
    
    private Date departure;
    
    private String city;
    
    private int day;
    }
    Not the close bracket, that means the TimeTable class is just those 4 private attributes.
    All the code after that is outside the class, which is not a valid place for code in Java.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Please help me! Basic java coding error!
    By Skater1024 in forum New To Java
    Replies: 13
    Last Post: 11-09-2015, 08:04 PM
  2. New to JAVA, and coding error
    By -Lucius- in forum New To Java
    Replies: 2
    Last Post: 11-09-2012, 12:49 PM
  3. Problem with Coding Java Class
    By Bentino in forum New To Java
    Replies: 8
    Last Post: 02-15-2012, 01:09 AM
  4. A newbie to Java needing help on coding error
    By Turo in forum New To Java
    Replies: 5
    Last Post: 08-28-2011, 05:11 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •