₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,050 members, 8,429,156 topics. Date: Thursday, 18 June 2026 at 01:49 PM

Toggle theme

Dolemite's Posts

Nairaland ForumDolemite's ProfileDolemite's Posts

1 2 3 4 5 6 7 8 ... 20 21 22 23 24 25 26 27 28 (of 74 pages)

ProgrammingRe: 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"wink;
}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"wink;//print out the name of the passanger u just added by getting its name u initialized
}
else {
System.out.println("Passenger cannot be added!!"wink;
}
}

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"wink;
}
}
}
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"wink;
pFound=i.next();
break;

}
}
}
}
and Im trying to create a gui:

public class BookingGui extends JFrame
{
private JButton addButton = new JButton("Add Passenger"wink;
private JButton removeButton = new JButton("Remove Passenger"wink;
private JButton displayButton = new JButton("Display Passengers"wink;
private JButton fundsButton = new JButton ("Display Funds"wink;
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"wink;
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"wink);
//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"wink);
add(fareField);
fareField.setBorder(new TitledBorder("Fare"wink);
add(weightField);
weightField.setBorder(new TitledBorder("Weight"wink);
add(luggageField);
luggageField.setBorder(new TitledBorder("Luggage"wink);
setVisible(true);


}
}
ProgrammingRe: Help On Java by Dolemite(f): 4:22pm On May 02, 2011
thank youuuuuuuuuu, please stay around, this saga is far from over. . .
ProgrammingRe: Help On Java by Dolemite(f): 3:23pm On May 02, 2011
2muchlogic:
Have you solved it yet? post your attempt here and let me see  wink wink wink wink wink
Yes i solved it. . .
public void removePass(String nameIn) {
Iterator<Passengers> i = p.iterator();
        while(i.hasNext()) {
            if (i.next().getName().equals(nameIn)) {
                i.remove();
break;
                System.out.println(nameIn + "has been removed"wink;
            }
        }
    }
Now I need to implement a searchPassenger method. . .any ideas?
ProgrammingRe: Help On Java by Dolemite(f): 12:04pm On May 02, 2011
2much what do you suggest I do?
ProgrammingRe: 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"wink; // won't compile.
ProgrammingRe: 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"wink;
System.out.println(name +" Cannot be added!"wink;
}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. . .
ProgrammingRe: 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. . . grin
ProgrammingRe: Help On Java by Dolemite(f): 11:05pm On May 01, 2011
Segs has a better knowledge of my code. I appreciate your help. smiley
ProgrammingRe: Help On Java by Dolemite(f): 10:47pm On May 01, 2011
Segs where are youuuuuuuuuuuuuuuuuu??
ProgrammingRe: 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. sad
CelebritiesRe: Where Is Wande Coal? by Dolemite(f): 11:00am On Apr 29, 2011
He's currently undergoing penile enlargement therapy. . .
CelebritiesRe: Femi Kuti Lauded As Best World Music Artist by Dolemite(f): 10:48pm On Apr 28, 2011
Greatness!!
ProgrammingRe: 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!! grin
ProgrammingRe: 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"wink;
System.out.println(i+"Cannot be added!"wink;
}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. . .
ProgrammingRe: Help On Java by Dolemite(f): 11:56am On Apr 27, 2011
I tried your code, it still doesn't work. . .
ProgrammingRe: 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"wink;
System.out.println(i+"Cannot be added!"wink;
}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. . .
ProgrammingRe: Help On Java by Dolemite(f): 1:39am On Apr 27, 2011
Edited. . . Thanks
ProgrammingRe: 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"wink;
System.out.println(i+"Cannot be added!"wink;
}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?
ProgrammingRe: 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
ComputersRe: 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. . .
CelebritiesRe: Nollywood Actor Ashley Nwosu Is Dead. by Dolemite(f): 3:11pm On Apr 21, 2011
How sad, he was a good guy. . .
CelebritiesRe: 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?
CelebritiesRe: Actor Nicolas Cage Arrested In New Orleans by Dolemite(f): 6:31am On Apr 19, 2011
MzDarkSkin:
[color=#0066ff]What is going on with our American actors? they are going bananas!
First Lindsay Lohan grin, Charlie Sheen, now Nicolas Cage? and they are just a few  undecided undecided smh.[/color]
How can you even put a Linday Lohan in the same sentence as Nicolas Cage or a Charlie Sheen. . .these things happen to everyday people too, but because they're celebrities it's amplified.
Forum GamesRe: Naija Proverbs by Dolemite(f): 4:00pm On Apr 17, 2011
jamace:
huh huh Na small small dey thing dey start o. grin grin
Copied off Natasha's signature. wink
Forum GamesRe: Guess How Many Partners The Nairalander Above You Has/ Has Had by Dolemite(f): 2:20pm On Apr 17, 2011
0
Forum GamesRe: Rate This Guy by Dolemite(op): 12:28pm On Apr 17, 2011
Goldieluks:
Tpiah needs a man,urgently!!! cool
Lol how old do you think he is?
ProgrammingRe: 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 GamesRe: Rate This Guy by Dolemite(op): 8:59am On Apr 17, 2011
tpiah!:
^is he a nler? huh
No.

D328babe:
8 !

wink
Ahaha!! thanks.
Forum GamesRe: Rate This Guy by Dolemite(op): 9:52pm On Apr 16, 2011
4? shocked Lol, yes he speaks english and the ratings are for, well trivial reasons.

1 2 3 4 5 6 7 8 ... 20 21 22 23 24 25 26 27 28 (of 74 pages)