Hey, so this is my final java assignment for 1st year comp sci program. I really want to get a decent mark before exams, so please I need your help. I've been working on it hard, but this assignment is making me feel dumb :( I'm supposed to make an airplane reservation using mouse events, grahpics, and object orientation. Here's how the program should be:


and looks (not necessarily as neat): http://i296.photobucket.com/albums/mm182/A_A_M_I_R/seating.jpg

Here's the work that I've done so far. Keep in mind that I'm still trying to advance in the programs, so your feedback and help would be greatly appreciated. (i.e. tell me if I'm on the right track and provide some assitance with the code):

Class Seat:

public class Seat {

private String name;
private boolean taken;
private int xLeft, yTop, width;
private Color colour;

public Seat(String aname, int x, int y, int recwidth, Color rectcolour) 
    name = aname;
    xLeft = x;
    yTop = y;
    width = recwidth;
    colour = rectcolour;

public final double getXPos()
    return xLeft;

public final double getYPos()
    return yTop;

public void book (String name)

public String getName() 
    return name;

public boolean isTaken() 
    return taken;

public String toString()
    return "Seat: " + name;

public boolean isSelected(int x, int y) 

    Point2D.Double p = new Point2D.Double(x, y);
    int xmax = xLeft + width;
    int ymax = yTop + width;
    boolean check = false;

    if (x > 0 && y > 0) 
        if (x <= xmax && y <= ymax) check= true;
    else if (x > xmax || y>ymax) check = false;
    return check;


Class AirplaneModel

public class AirplaneModel extends JComponent
ArrayList<Seat> seatList= new ArrayList();
int rows,columns;
int    xPos, yPos, w, h;
//double xRadius, yRadius;

public AirplaneModel()
    xPos = 0;
    yPos = 0;

public AirplaneModel(int xposition, int yposition, int width, int height) 
    xPos = xposition;
    yPos = yposition;
    w = width;
    h = height;
 public int seatNumber(String seatName)
     // Am i supposed to use for loop to find seat in the arraylist?? how do i approach it??

 public void draw(Graphics2D g2) 



Componet Class

public class AirlineComp extends AirplaneModel // because class Airplane model has JComponent, so this extends JComponent too? :$
Seat seats;
public AirlineComp()
    class MousePressListener implements MouseListener
         public void mousePressed(MouseEvent event)
            int x = event.getX();
            int y = event.getY();
         public void mouseReleased(MouseEvent event){}
         public void mouseClicked(MouseEvent event){}
         public void mouseEntered(MouseEvent event){}
         public void mouseExited(MouseEvent event){}
      MouseListener mListener = new MousePressListener();

public void paintComponent(Graphics g)
    Graphics2D g2 = (Graphics2D) g;
    for (int i = 0; i < seatList.size(); i++)
        AirplaneModel model = seatList.get(i); 


**Viewer class*

public class AirlineViewer 
public static void main (String[] args)
    JFrame frame = new JFrame();

    final int FRAME_WIDTH  = 600;
    final int FRAME_HEIGHT = 600;

    frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    frame.setTitle("Airplane Reservation");
    frame.setLayout(new BorderLayout());

    JPanel panel = new JPanel();

    JTextField flightlabel = new JTextField("Flight #:", 5);
    JTextField flightfield = new JTextField(3);

    JTextField passengerlabel = new JTextField("Passenger:", 6);
    JTextField passengerfield = new JTextField(20);

    JTextField seatlabel = new JTextField("Seat:", 3);
    JTextField seatfield = new JTextField(3);





I still have Passenger and AirlineFlight classes to work on, but I thought I'd post what I have so far so I can get feedback because my professor's office hours are the thursday and the assignment is due friday.

Edited by Hitman Mania

4 Years
Discussion Span
Last Post by NormR1

Is the code so far working the way you want? Do you have any specific questions about it?


Not yet, my prof says to start simple and expand your program and that what I'm doing. A question on my mind is, for class AirplaneModel, I'm supposed to have method int seatNumber(String seatName) that calculates and returns the index into the arraylist of seat objects when given seat name... I don't really understand how to approach this, do I use a for loop and if so how?


What does "calculates" mean? You use a for loop when you know how many times you potentially need to loop. If you are searching an array, then a for loop would work.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.