Hey guys, I'm not new to programming but I am new to Java. Here is the layout of my program:
Introduction
The goal of this assignment is to familiarize you with writing a simple Java Graphical User Interface (GUI) application in Java to reinforce the object-oriented programming concepts discussed during lectures.
I'm having trouble implementing constructors and string to string to print to the GUI.
Any suggestions?
Procedures
1. *.java - Use an editor or Integrated Development Environment (IDE) to create the .java source code file.
2. Create a UI application to perform the following functions:
a. Create a class called Airline.java
i. Variables
1. airlineName
2. airlineHubLocation
ii. Methods
1. public getter/setter for all variables
2. public string toString() to print out the airline information
b. Create a class called Airport.java
i. Variables
1. airportName
2. airportCity
3. airportState
4. airportCode
ii. Methods
1. public getter/setter for all variables
2. constructor that takes four parameters for airportName, airportCity, airportState, airportCode
3. public string toString() to print out the airport information
c. Create a main class to run the application
i. Includes the “public static void main(String[] args) {}” function
ii. Creates an instance of Airport using the declared constructor; example Airport airport = new Airport(“Orlando International Airport”, “Orlando”, “Florida”, “MCO”);
iii. Create two instances of Airline; example Airline united = new Airline(); Airline delta = new Airline();
iv. Set the data attributes of each airline as follows:
1. united.setAirlineName(“United Airlines”);
2. united.setAirlineHubLocation(“MCO”);
3. delta.setAirlineName(“Delta Airlines”);
4. delta.setAirlineHubLocation(“ATL”);
v. Display the information about Orlando International Airport and its two airlines using the static method JOptionPane.showMessageDialog(null, string);
1. Using concatenation for the string parameter display
a. airport.toString() + “\n” + delta.toString() + “\n” + united.toString()
2. Output example
--- Update ---
Airline.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package airline;
import javax.swing.JOptionPane;
/*
*
*
*/
public class Airline {
String airlineName;
String airlineHubLocation;
//Methods
public String getAirlineName() {
return airlineName;
}
public String getAirlineHublocation() {
return airlineHubLocation;
}
public void setAirlineName(String airlineName) {
this.airlineName = airlineName;
}
public void setAirlineHubLocation(String airlineHublocation) {
this.airlineHubLocation = airlineHublocation;
}
@Override
public String toString() {
return "Airline{" + "airlineName=" + airlineName + ", airlineHubLocation=" + airlineHubLocation + '}';
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Airport airport = new Airport();
Airline united = new Airline();
united.setAirlineName("United Airlines");
united.setAirlineHubLocation("MCO");
Airline delta = new Airline();
delta.setAirlineName("Delta Airlines");
delta.setAirlineHubLocation("ATL");
JOptionPane.showMessageDialog(null, "airport.toString() + delta.toString() + united.toString()");
}
}
Airport.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package airline;
/**
*
*
*/
public class Airport {
String airportName;
String airportCity;
String airportState;
int airportCode;
public String getAirportName() {
return airportName;
}
public String getAirportCity() {
return airportCity;
}
public String getAirportState() {
return airportState;
}
public int getAirportCode() {
return airportCode;
}
public void setAirportName(String airportName) {
this.airportName = airportName;
}
public void setAirportCity(String airportCity) {
this.airportCity = airportCity;
}
public void setAirportState(String airportState) {
this.airportState = airportState;
}
public void setAirportCode(int airportCode) {
this.airportCode = airportCode;
}
}