Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need help with exercise: Flight reservation system


  • Please log in to reply
3 replies to this topic

#1 Coldhearth

Coldhearth

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 88 posts

Posted 13 December 2009 - 12:38 PM

Hi, I'm currently working on a flight reservation system (basic though it is) for school for my Java class. This system connects with a MySQL database for testing purposses.
I'm should work with the MVC (model view controller) pattern they said.
This is what I have so far...

Main (start of my application):
import view.MainJFrame;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MainJFrame application = new MainJFrame();
		application.setVisible(true);
	}

}

MODEL:
Person class:
package model;

public class Person {

	private String lastName;
	private String firstName;
	private String street;
	private int number;
	private int zipCode;
	private String city;
	
	public Person(){
		this("", "", "", 0, 0, "");
	}
	
	public Person(String lastName, String firstName, String street, int number, int zipCode, String city){
		setLastName(lastName);
		setFirstName(firstName);
		setStreet(street);
		setNumber(number);
		setZipCode(zipCode);
		setCity(city);
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public int getZipCode() {
		return zipCode;
	}

	public void setZipCode(int zipCode) {
		this.zipCode = zipCode;
	}
	
	
	
}

Customer class:
package model;

public class Customer extends Person{

	private String customerID;

	public Customer(){
		this("", "", "", 0, 0, "", "");
	}
	
	public Customer(String lastName, String firstName, String street, int number, int zipCode, String city, String customerID){
		super(lastName, firstName, street, number, zipCode, city);
		setCustomerID(customerID);
	}
	
	public String getCustomerID() {
		return customerID;
	}

	public void setCustomerID(String customerID) {
		this.customerID = customerID;
	}
	
}

Employee class:
package model;

public class Employee extends Person{

	private String username;
	private String password;
	private String employeeID;
	
	public Employee(){
		this("", "", "", 0, 0, "", "", "", "");
	}
	
	public Employee(String lastName, String firstName, String street, int number, int zipCode, String city, String username, String password, String employeeID){
		setUsername(username);
		setPassword(password);
		setEmployeeID(employeeID);
	}

	public String getEmployeeID() {
		return employeeID;
	}

	public void setEmployeeID(String employeeID) {
		this.employeeID = employeeID;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	
	
}

Flight class:
package model;

public class Flight {
	private String flightNumber;
	private String name;
	private String date;
	private String info;
	
	public Flight(){
		this("", "", "", "");
	}
	
	public Flight(String flightNumber, String name, String date, String info){
		setFlightNumber(flightNumber);
		setName(name);
		setDate(date);
		setInfo(info);
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getFlightNumber() {
		return flightNumber;
	}

	public void setFlightNumber(String flightNumber) {
		this.flightNumber = flightNumber;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
}

VIEW:
MainJFrame class:
(this class will only show a button and textare for now, if I click the button It should get flight info of all my flights in the database)
package view;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextArea;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainJFrame extends javax.swing.JFrame {
	private JButton btn_showFlightInfo;
	private JTextArea txa_showFlightInfo;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainJFrame inst = new MainJFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public MainJFrame() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(thisLayout);
			{
				btn_showFlightInfo = new JButton();
				getContentPane().add(btn_showFlightInfo, BorderLayout.SOUTH);
				btn_showFlightInfo.setText("Flight info");
				btn_showFlightInfo.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("btn_showFlightInfo.actionPerformed, event="+evt);
						//TODO add your code for btn_showFlightInfo.actionPerformed
						txa_showFlightInfo.setText("ljl");
					}
				});
			}
			{
				txa_showFlightInfo = new JTextArea();
				getContentPane().add(txa_showFlightInfo, BorderLayout.CENTER);
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

I also have a MysqlDatabaseConnection class that handles queries like SELECT, INSERT, UPDATE and DELETE for a MySQL database.

My questions now are:
- Am I starting out good (is the MVC structure good so far)
- How should I build this MVC structure now?
- In what part of the MVC structure do I put my database related classes?

Any help will be appreciated :)
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 14 December 2009 - 06:42 AM

I'm not sure you understand the MVC pattern.

You start with the raw data: that's your Model. In this case, the contents of your database.
Then you have to look at how you will present the data, your Views. This could vary widely from charts, to graphs, etc.
Finally, you have to look at how you will modify the data, your Controls. These will be various forms, perhaps even some of your Views will function as Controls.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Coldhearth

Coldhearth

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 88 posts

Posted 14 December 2009 - 07:16 AM

Does somebody know a source code example of a simple exercise that uses the MVC pattern with a MySQL database for the data?
An example would be very good to study and learn from :)
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 14 December 2009 - 08:03 AM

You're thinking about this wrong.

You have the Model: your database.
Just ask yourself, how do you want to present the data?
How do you want to modify the data?

Once you answer those two questions, you'll be done with an MVC model app.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download