Programming › Re: Help On Java by Dolemite(f): 3:44pm On May 03, 2011 |
Any ideas on how I could integrate the first two classes into a gui below? public class Passenger { private String name; private int fare; private int weight; private int luggage; private int tpw; private int totalTpw; public Passenger(String nameIn, int fareIn, int weightIn, int luggageIn){ name=nameIn; fare=fareIn; weight=weightIn; luggage=luggageIn; } public int setWeight(int weightIn){ weight=weightIn; return weight; } public String getName(){ return name; } public int getFare(){ return fare; } public int getWeight(){ return weight; } public int getLuggage(){ return luggage; } public int setTpw(){ tpw=weight*luggage; return tpw; } public String toString(){ return name + " " + fare + " " +weight+ " " +luggage; } } public class Aircraft { private ArrayList<Passenger>pass=new ArrayList<Passenger>(); private int seats=250; private final int WEIGHT= 21300; private String name; private int fare; private int weight; private int luggage; private int tpw; private int totalfares; private Passenger p; public void addPassenger(String nameIn,int fareIn, int weightIn, int luggageIn){ name=nameIn; fare=fareIn; weight=weightIn; luggage=luggageIn; p= new Passenger(name,fare,weight,luggage); //passenger object tpw=weightIn+luggageIn; //calculates and adds the tpw if(tpw>=50&&tpw<=100&&tpw<WEIGHT&&seats>0){ pass.add(p); //adds the passenger fare=fareIn+((tpw-50)*5); //calculates the fare totalfares=totalfares+fareIn; System.out.println("You have just added"+nameIn); System.out.println("Fare is"+fare); seats--; System.out.println(seats+"left" ; }else if(tpw>=100&&tpw<=150&&tpw<WEIGHT&&seats>0){ pass.add(p); //adds the passenger fare=fare+((tpw-100)*10); totalfares=totalfares+fareIn; //collects the total fares System.out.println("You have just added"+nameIn); System.out.println("Fare is" +fare); seats--; System.out.println(seats+"left" ;//print out the name of the passanger u just added by getting its name u initialized } else { System.out.println("Passenger cannot be added!!" ; } }
public ArrayList<Passenger> getPassengers(){ System.out.println(pass); return pass; } public int getTotalfares(){ System.out.println(totalfares); return totalfares; } public void removePassenger(String nameIn){ Iterator<Passenger> i = pass.iterator(); while(i.hasNext()){ if(i.next().getName().equals(nameIn)){ i.remove(); totalfares=totalfares-fare; System.out.println(nameIn+ "has been removed" ; } } } public void searchPassenger(String nameIn){ Passenger pFound; Iterator<Passenger> i = pass.iterator(); while(i.hasNext()){ if(i.next().getName().equals(nameIn)){ System.out.println(nameIn+ "is in the list" ; pFound=i.next(); break; } } } } and Im trying to create a gui: public class BookingGui extends JFrame { private JButton addButton = new JButton("Add Passenger" ; private JButton removeButton = new JButton("Remove Passenger" ; private JButton displayButton = new JButton("Display Passengers" ; private JButton fundsButton = new JButton ("Display Funds" ; private JTextField seatsField = new JTextField(4); private JTextField nameField = new JTextField(15); private JTextField fareField = new JTextField(15); private JTextField weightField = new JTextField(15); private JTextField luggageField = new JTextField(15); public BookingGui(){ setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Airline Booking System" ; setSize(550,450); setLocation(400,100); getContentPane().setBackground(Color.gray); //creates a border style for the JButtons BevelBorder raisedBevel = new BevelBorder(BevelBorder.RAISED); //adding the components add(seatsField); seatsField.setBorder(new TitledBorder("Seats" ); //Buttons are added with background colors and borders set add(addButton); addButton.setBackground(Color.green); addButton.setBorder(raisedBevel); add(removeButton); removeButton.setBackground(Color.green); removeButton.setBorder(raisedBevel); add(displayButton); displayButton.setBackground(Color.green); displayButton.setBorder(raisedBevel); add(fundsButton); fundsButton.setBackground(Color.green); fundsButton.setBorder(raisedBevel); add(nameField); nameField.setBorder(new TitledBorder("Name" ); add(fareField); fareField.setBorder(new TitledBorder("Fare" ); add(weightField); weightField.setBorder(new TitledBorder("Weight" ); add(luggageField); luggageField.setBorder(new TitledBorder("Luggage" ); setVisible(true); } } |
Programming › Re: Help On Java by Dolemite(f): 4:22pm On May 02, 2011 |
thank youuuuuuuuuu, please stay around, this saga is far from over. . . |
Programming › Re: Help On Java by Dolemite(f): 3:23pm On May 02, 2011 |
|
Programming › Re: Help On Java by Dolemite(f): 12:04pm On May 02, 2011 |
2much what do you suggest I do? |
Programming › Re: Help On Java by Dolemite(f): 11:16am On May 02, 2011 |
Thanks alot, but how do i test for this? and does it take off the whole object from the list? eg. objectofaircraft.RemovePassenger("John"  ; // won't compile. |
Programming › Re: Help On Java by Dolemite(f): 8:31am On May 02, 2011 |
public class Aircraft { private ArrayList<Passengers>pass=new ArrayList<Passengers>(); //holdin all passangers private int seats; private String name; private int fare; private int weight; private int luggage; private int tpw; private int totalfares; private Passengers p; public void addPass(String i,int f, int w, int l){ name=i; fare=f; weight=w; luggage=l; p= new Passengers(name,fare,weight,luggage); tpw=w*l; if(tpw>250){ System.out.println("Too much weight" ; System.out.println(name +" Cannot be added!" ; }else{ pass.add(p); //add the passanger totalfares=totalfares+fare; //add to the total fares System.out.println("You have just added "+name); } } public ArrayList<Passengers> getPass(){ System.out.println(pass); return pass; } public int getTotalfares(){ System.out.println(totalfares); return totalfares; } } How can I implement a remove passenger method in this code that searches for the passenger by name and removes the whole object of the passenger. . . |
Programming › Re: Help On Java by Dolemite(f): 1:05am On May 02, 2011 |
Lol, no no he's been helping me with the code, all help is welcomed please. . .  |
Programming › Re: Help On Java by Dolemite(f): 11:05pm On May 01, 2011 |
Segs has a better knowledge of my code. I appreciate your help.  |
Programming › Re: Help On Java by Dolemite(f): 10:47pm On May 01, 2011 |
Segs where are youuuuuuuuuuuuuuuuuu?? |
Programming › Re: Help On Java by Dolemite(f): 3:07am On May 01, 2011 |
I tried to use the remove passenger method but i get a 'concurrent modification exception' error at runtime.  |
Celebrities › Re: Where Is Wande Coal? by Dolemite(f): 11:00am On Apr 29, 2011 |
He's currently undergoing penile enlargement therapy. . . |
Celebrities › Re: Femi Kuti Lauded As Best World Music Artist by Dolemite(f): 10:48pm On Apr 28, 2011 |
Greatness!! |
Programming › Re: Help On Java by Dolemite(f): 10:36pm On Apr 28, 2011 |
Thanks, good to have a genius like you here, you're the ONLY useful person here on nairaland!!  |
Programming › Re: Help On Java by Dolemite(f): 5:02pm On Apr 27, 2011 |
public class Aircraft { private ArrayList<Passengers>pass=new ArrayList<Passengers>(); private int seats; private String name; private int fare; private int weight; private int luggage; private int tpw; private int totalfares; private Passengers p; public void addPass(String i,int f, int w, int l){ name=i; fare=f; weight=w; luggage=l; p= new Passengers(name,fare,weight,luggage); tpw=w*l; if(tpw>250){ System.out.println("Too much weight" ; System.out.println(i+"Cannot be added!" ; }else{ pass.add(p); totalfares=totalfares+f; //add the new created object to the arralist System.out.println("You have just added"+i); //print out the name of the passanger u just added by getting its name u initialized } } public void checkPass(){ System.out.println(pass); } public int checkTotalfares(){ System.out.println(totalfares); return totalfares; } public void getTpw(){ p.getTpw(); } public void TotalTpw(){ p.getTotalTpw(); } } Module what now? anyway this one works, please have a look and tell me if my logic is faulty. . . |
Programming › Re: Help On Java by Dolemite(f): 11:56am On Apr 27, 2011 |
I tried your code, it still doesn't work. . . |
Programming › Re: Help On Java by Dolemite(f): 1:46am On Apr 27, 2011 |
EDIT**I modified the code thus; public class Aircraft { private ArrayList<Passengers>pass=new ArrayList<Passengers>(); String name; int fare; int weight; int luggage; Passengers p1 = new Passengers(name,fare,weight,luggage); public Aircraft(String i,int f, int w, int l){ name=i; fare=f; weight=w; luggage=l; } /** public void addPass(Passengers p){ pass.add(p); System.out.println(p.toString()); } */ public void addPass(String i,int f, int w, int l){ //create an instance of Passengers to be added int tpw=w*l; if(tpw>250){ System.out.println("Too much weight" ; System.out.println(i+"Cannot be added!" ; }else{ pass.add(p1); //add the new created object to the arralist System.out.println("You have just added"+i); //print out the name of the passanger u just added by getting its name u initialized } } public void checkPass(){ System.out.println(p1.getName()); } } I get a 'null' whenever i run the checkPass() method, why is that? I haven't tried that one though, the remove command. . . |
Programming › Re: Help On Java by Dolemite(f): 1:39am On Apr 27, 2011 |
Edited. . . Thanks |
Programming › Re: Help On Java by Dolemite(f): 1:10am On Apr 27, 2011 |
Thanks alot, silly me i could KISS you right now lol, it really helped, but I would also need to a remove passenger functionality. . . EDIT**I modified the code thus; public class Aircraft { private ArrayList<Passengers>pass=new ArrayList<Passengers>(); String name; int fare; int weight; int luggage; Passengers p1 = new Passengers(name,fare,weight,luggage); public Aircraft(String i,int f, int w, int l){ name=i; fare=f; weight=w; luggage=l; } /** public void addPass(Passengers p){ pass.add(p); System.out.println(p.toString()); } */ public void addPass(String i,int f, int w, int l){ //create an instance of Passengers to be added int tpw=w*l; if(tpw>250){ System.out.println("Too much weight" ; System.out.println(i+"Cannot be added!" ; }else{ pass.add(p1); //add the new created object to the arralist System.out.println("You have just added"+i); //print out the name of the passanger u just added by getting its name u initialized } } public void checkPass(){ System.out.println(p1.getName()); } } I get a 'null' whenever i run the checkPass() method, why is that? |
Programming › Re: Help On Java by Dolemite(f): 3:18pm On Apr 26, 2011 |
I need help please; I have this class; public class Passengers { private String name; private int fare; private int weight; private int luggage; private int tpw; public Passengers(String nameIn, int fareIn, int weightIn, int luggageIn){ name=nameIn; fare=fareIn; weight=weightIn; luggage=luggageIn; } public String getName(){ return name; } public int getFare(){ return fare; } public int getWeight(){ return weight; } public int getLuggage(){ return luggage; } public int getTpw(){ tpw=luggage*weight; return tpw; } } Now I need the user to be able to create multiple objects of passenger and store them in an array list with unique identifier, so I can delete passengers and all their details from the system; I have a booking class; public class Booking { private ArrayList<Passengers>pass=new ArrayList<Passengers>(); Passengers p1 = new Passengers("",0,0,0); public Booking(){ } public void addPass(String i,int f, int w, int l){ pass.add(p1); System.out.println(p1); } I KNOW this is wrong. . . please help me segs |
Computers › Re: Plz Improve The Graphics Of This Website by Dolemite(f): 8:59pm On Apr 25, 2011 |
Thing is refurbishing the site may affect its google ranking. . . |
|
Celebrities › Re: Nollywood Actor Ashley Nwosu Is Dead. by Dolemite(f): 3:11pm On Apr 21, 2011 |
How sad, he was a good guy. . . |
Celebrities › Re: Men Have Seen Part Of My Chest, What Else Do They Want To See? -monalisa Chinda by Dolemite(f): 6:00am On Apr 20, 2011 |
. . . Your butt cheeks, your vajay-jay? |
|
Celebrities › Re: Actor Nicolas Cage Arrested In New Orleans by Dolemite(f): 6:31am On Apr 19, 2011 |
|
Forum Games › Re: Naija Proverbs by Dolemite(f): 4:00pm On Apr 17, 2011 |
|
Forum Games › Re: Guess How Many Partners The Nairalander Above You Has/ Has Had by Dolemite(f): 2:20pm On Apr 17, 2011 |
0 |
Forum Games › Re: Rate This Guy by Dolemite(op): 12:28pm On Apr 17, 2011 |
Goldieluks: Tpiah needs a man,urgently!!!  Lol how old do you think he is? |
Programming › Re: Help On Java by Dolemite(f): 9:07am On Apr 17, 2011 |
Seg whats your take on this, I'm really interested in games programming, java doesn't seem to be used much as most of the coolest games i've played were done with c++, my belief is that java makes good software not games, actioncript doesn't seem like a strong contender for making games only a gamer would appreciate. . .what do you think? java vs c++ vs actionscript. . . |
Forum Games › Re: Rate This Guy by Dolemite(op): 8:59am On Apr 17, 2011 |
tpiah!: ^is he a nler?  No. D328babe: 8 !
 Ahaha!! thanks. |
|
Forum Games › Re: Rate This Guy by Dolemite(op): 9:52pm On Apr 16, 2011 |
4?  Lol, yes he speaks english and the ratings are for, well trivial reasons. |