Just need someone to confirm that what ive done is good . It compiles but i need confirmation that its good and up to standards .
this is the first class

import java.io.Serializable;

public class Flight implements Serializable
{
    //instance variables

    private String flightNumber; 
    private String day;
    private String destination;
    private int freeSeats;
    private String error;
    // constructors
    public Flight()
    {
        this.flightNumber = " ";
        this.day = " ";
        this.destination = " ";
        this.freeSeats = 0;

    }

    public Flight(String fNum, String day, String destination, int seatsBooked, int seatSold, int freeSeats)
    {
        this.flightNumber = fNum;
        this.day = day;
        this.destination = destination;
        this.freeSeats = freeSeats;

    }

    public String getFlightNumber()
    {
        return this.flightNumber;
    }

    public String getDay()
    { 
        return this.day;

    }

    public String getDestination()
    {
        return this.destination;
    }

    public int getFreeSeats()
    {
        return this.freeSeats;
    }

    public String flightNumber()
    {
        if(flightNumber.matches("EL[0-9][0-9][0-9]"))
        {
            this.flightNumber = flightNumber;
            System.out.println("Flight Number Accepted");
            return this.flightNumber;

        }//end if
        else
        {
            System.out.println("Invalid Number......Flight Number Must Start With EL And Have 3 Digits");
            return error;
        }//end else
    }

    public String day()
    {
        if(day.matches("[Monday][Tuesday][Wednesday][Thursday][Friday][Saturday][Sunday]"))
        {
            this.day = day;
            System.out.println("You Will Be Traveling On " + this.day);
            return this.day;
        }// end if statement 
        else 
        {
            System.out.println("Invalid option choosen");
            return error;
        }
    }

    public String destination()
    {
        this.destination = destination; 
        return this.destination;
    }

    public int freeSeats(int freeSeats)
    {
        if(freeSeats < 10 && freeSeats > 0)
        {
            System.out.println("Seats Available");
            return this.freeSeats;

        }
        else
        {
            System.out.println("No Seats availabele");
            return 0;
        }
    }

    public void display()
    {
        System.out.println(" Please Enter Flight Number Please: " +  this.flightNumber);
        System.out.println(" Enter Day Of Departure: " +  this.day);
        System.out.println(" Enter Destination: " +  this.destination);

        System.out.println("Number Of avaialable Seats + " + this.freeSeats);

    }
}

********************************************************************
*******************************************************************
This is the second class

import java.io.Serializable;
public class Passenger implements Serializable
{
    //instance variables
    private String name;
    private String address;
    private String emailAddress;
    private Flight flightBooked;// will hol the adress of the flight object 
    private String flightValid;
    private String answer;
    //constructors
    public Passenger()
    {
        this.name = " ";
        this.address = " ";
        this.emailAddress = " ";
        this.flightBooked = null;
    }

    public Passenger(String name, String address, String emailAddress, Flight flightBooked)
    {
        this.name = name;
        this.address = address;
        this.emailAddress = emailAddress;
        this.flightBooked = flightBooked;
    }

    //Getter methods
    public String getName()
    {
        return this.name;
    }

    public String getAddress()
    {
        return this.address;
    }

    public String getEmailAddress()
    {
        return this.emailAddress;
    }

    public Flight getFlightBooked()
    {
        return this.flightBooked;
    }

    //Setter methods
    //Getter methods
    public String name()
    {
        this.name = name;
        System.out.println("Please Enter Name");
        return this.name;
    }

    public String address()
    {
        this.address = address;
        System.out.println("Please Enter Address");
        return this.address;

    }

    public String email()
    {
        this.emailAddress = emailAddress;
        System.out.println("Please Enter Email");
        return this.emailAddress;
    }

    public Flight flightBooked()
    {
        this.flightBooked = flightBooked;
        System.out.println("Enter Flight Number");
        return this.flightBooked;
    }
    //create a flight here to store info about the flight!
    public boolean flightValid()
    {
        if(flightValid.equals("Yes"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public void displayP()
    {
        System.out.println(" Please Enter Name: " + this.name);
        System.out.println(" Please Enter ADrress: " + this.address);
        System.out.println(" Enter Email: " + this.emailAddress);
        System.out.println(" flight Booked?: " + this.flightBooked);

    }
}

Edited 3 Years Ago by Dani: Formatting fixed

public String name(){
    this.name = name;
    System.out.println("Please Enter Name");
    return this.name;
}

all your setter method are wrong, explain to me why and ill help you fix them :D

//create a flight here to store info about the flight!
public boolean flightValid(){
    if(flightValid.equals("Yes")){
        return true;
    }
    else{
        return false;
    }
}

you never create any flight here. and if you are going to return true if a condition is true after a if , simplify your whole method :

public boolean flightValid(){
    return flightValid.equals("Yes");
}

but that wouldn't do much good, since you never set any value to flightValid.

public String email(){
    this.emailAddress = emailAddress;
    System.out.println("Please Enter Email");
    return this.emailAddress;
}

you never read any user input, this.emailAddress & emailAddress are the same thing, you are saying x = x; it changes absolutly nothing.
then you print out to enter a value, but never read one, and simply return the unchanged variable.

the only time this.variable and variable are not worth the same is here :

public int freeSeats(int freeSeats){
    if(freeSeats < 10 && freeSeats > 0){
        System.out.println("Seats Available");
        return this.freeSeats;
    }
    else{
        System.out.println("No Seats availabele");
        return 0;
    }
}

because you receive an argument that has the same name as your instance variable, so freeSeats represents the argument, and this.freeSeats represents the instance variable. the code is not any better tho, you do a verification on the argument , then return the unchanged instance variable.

Why would you expect an argument to be sent to a method that should simply return the current value of an isntance variable?
Why would you say "no seats available" if there are 10 or more seats available?

This article has been dead for over six months. Start a new discussion instead.