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:
http://i44.tinypic.com/358wd5d.jpg
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)
{
this.name=name;
taken=true;
}
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();
addMouseListener(mListener);
}
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
for (int i = 0; i < seatList.size(); i++)
{
AirplaneModel model = seatList.get(i);
model.draw(g2);
}
}
}
**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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JPanel panel = new JPanel();
JTextField flightlabel = new JTextField("Flight #:", 5);
flightlabel.setEditable(false);
JTextField flightfield = new JTextField(3);
JTextField passengerlabel = new JTextField("Passenger:", 6);
passengerlabel.setEditable(false);
JTextField passengerfield = new JTextField(20);
JTextField seatlabel = new JTextField("Seat:", 3);
seatlabel.setEditable(false);
JTextField seatfield = new JTextField(3);
panel.add(flightlabel);
panel.add(flightfield);
panel.add(passengerlabel);
panel.add(passengerfield);
panel.add(seatlabel);
panel.add(seatfield);
frame.add(panel,BorderLayout.NORTH);
frame.setVisible(true);
}
}
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.