- #1
smilesofmiles
- 19
- 0
This is a class assignment that has been puzzling me for a few hours. I need this to print out the values from the passenger array. My code so far prints the values from my aircraft class perfectly but not from my passenger class. Please see my output below:
View attachment 6401
How do I make the output display this instead?
Information regarding AirCraft: 2000 parsecs 4 Passenger1[The Twilight Zone, First Class Bunker] Passenger2 [ Bermuda Triangle, Near the Bathroom] Passenger3 [North Korea, Windowseat blocked by Airplane Wing] Passenger4 [Japan, Behind screaming infant].
Preferably without the ugly brackets haha
Things I've tried:
MY ENTIRE CODE SEPARATED BY CLASSES
Some background:
I need to make all of these classes for my assignment.
An Aircraft class
A Pilot class
A Passenger class
A Stewardess class
A Suitcase class
An Address class
A Map class
With each Aircraft containing one Pilot, one Stewardess, and four Passengers.
I decided to take it slow and just create the first two classes, Aircraft and Passenger. I am trouble shooting them right now but can't get them to print :-(
Any help, or push int the right direction would be greatly appreciated!
Thank you!
View attachment 6401
How do I make the output display this instead?
Information regarding AirCraft: 2000 parsecs 4 Passenger1[The Twilight Zone, First Class Bunker] Passenger2 [ Bermuda Triangle, Near the Bathroom] Passenger3 [North Korea, Windowseat blocked by Airplane Wing] Passenger4 [Japan, Behind screaming infant].
Preferably without the ugly brackets haha
Things I've tried:
Code:
//In my main class
airCraft.getInfo();
airCraft.getInfo().getPassengerInfo();
airCraft.getPassengerInfo().getInfo();
airCraft.getPassengferInfo();
System.out.println(airCraft.getInfo().getPassengerIno());
System.out.println(airCraft[0].getInfo()); <-- I know it's not an array but I was desperate!
// In my passenger class
public String getInfo(){
return ("Information regarding AirCraft: " + maxSpeed + " " + maxPassengers + " " + passenger.getPassengerInfo());
}
//Other things I've tried
//Making sure I have the correct number of variables in each constructor, Double checking my syntax for arraylists
//Looking up youtube videos on arraylists and classes
//Re-reading my textbook
//Taking a break for hot chocolate
MY ENTIRE CODE SEPARATED BY CLASSES
Code:
//CLASS APP
import java.util.ArrayList;public class App {
public static void main(String[] args) {
ArrayList<Passenger> passenger = new ArrayList();
passenger.add(new Passenger("The Twilight Zone", "First Class Bunker"));
passenger.add(new Passenger("Bermuda Triangle", "Near the Bathroom"));
passenger.add(new Passenger("North Korea", "Windowseat blocked by Airplane Wing"));
passenger.add(new Passenger("Japan", "Behind screaming infant"));
//I hate flying :-D
AirCraft airCraft = new AirCraft("2000 parsecs", 4, passenger);
System.out.println(airCraft.getInfo());
}
}
Code:
//CLASS AIRCRAFT
import java.util.ArrayList;
public class AirCraft {
//AKA Constructor hint
//Each Aircraft contains one Pilot, one Stewardess, and four Passenger
//maxSpeed, maxPassengers,]\
private String maxSpeed;
private int maxPassengers;
private ArrayList<Passenger> passenger;
public AirCraft(String maxSpeed, int maxPassengers, ArrayList<Passenger> passenger){
this.maxSpeed = maxSpeed;
this.maxPassengers = maxPassengers;
this.passenger = passenger;
}
public String getMaxSpeed()
{
return this.maxSpeed;
}
public void setMaxSpeed(String maxSpeed)
{
this.maxSpeed = maxSpeed;
}
public int getMaxPassengers(){
return this.maxPassengers;
}
public void setMaxPassengers(int maxPassengers){
this.maxPassengers = maxPassengers;
}
public void getPassenger (ArrayList<Passenger> passenger){
this.passenger = passenger;
}
public ArrayList<Passenger> setPassenger(){
return this.passenger;
}
public String getInfo(){
return ("Information regarding AirCraft: " + maxSpeed + " " + maxPassengers + " " + passenger);
}
}
Code:
//CLASS PASSENGER
import java.util.ArrayList;public class Passenger {
//Must have two attributes
//finalDestination, seatingSection
private String finalDestination;
private String seatingSection;
Passenger(String finalDestination, String seatingSection){
this.finalDestination = finalDestination;
this.seatingSection = seatingSection;
}
public String getFinalDestination()
{
return this.finalDestination;
}
public void setFinalDestination(String finalDestination){
this.finalDestination = finalDestination;
}
public String getSeatingSection(){
return this.seatingSection;
}
public void setSeatingSection(String seatingSection){
this.seatingSection = seatingSection;
}
public String getPassengerInfo(){
return (finalDestination + " " + seatingSection + " ");
}
}
Some background:
I need to make all of these classes for my assignment.
An Aircraft class
A Pilot class
A Passenger class
A Stewardess class
A Suitcase class
An Address class
A Map class
With each Aircraft containing one Pilot, one Stewardess, and four Passengers.
I decided to take it slow and just create the first two classes, Aircraft and Passenger. I am trouble shooting them right now but can't get them to print :-(
Any help, or push int the right direction would be greatly appreciated!
Thank you!