boolean

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

boolean

 
0
  #1
Oct 9th, 2006
public class Plane {
private String FlightNumber;
private String Location;
private boolean isLanding;
private int ScheduledTime;
private static int TotalPlanes;

public Plane(String FlightNumber, String Location){
this.FlightNumber = FlightNumber;
this.Location = Location;
Plane.TotalPlanes++;
}
public String getFlightNumber(){
return this.FlightNumber;
}
public void setFlightNumber(String f){
this.FlightNumber = f;
}
public String getLocation(){
return this.Location;
}
public void setLocation(String l){
this.Location = l;
}
public static int getTotalPlanes(){
return Plane.TotalPlanes;
}

public boolean

i wrote this far and i like to use boolean but i need to write with isLanding wheather it lands or take offs.



something like

public boolean isLanding(Plane c) {
return this.Plane.equals(c.Plane);


how should i write..?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 101
Reputation: cms271828 is an unknown quantity at this point 
Solved Threads: 4
cms271828 cms271828 is offline Offline
Junior Poster

Re: boolean

 
0
  #2
Oct 9th, 2006
public boolean getIsLanding()
{
return isLanding;
}

I think thats what you want


What I would do is change your non-static boolean field isLanding to:
private boolean landing;
Then use the method:
public boolean isLanding()
{
return landing;
}

It conforms more to how java code is written using get/is.
Last edited by cms271828; Oct 9th, 2006 at 11:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 101
Reputation: cms271828 is an unknown quantity at this point 
Solved Threads: 4
cms271828 cms271828 is offline Offline
Junior Poster

Re: boolean

 
1
  #3
Oct 9th, 2006
If you didn't realise, but you probably do, your constructor is only setting flightNumber and location, so that means:
isLanding(landing if you make the change I suggested)=false
scheduledTime=0
Since they are the default values for booleans and ints.
So upto you if you want to set them when you create a new Plane object

Also, in your methods:

public String getFlightNumber(){
return this.FlightNumber;
}
public void setFlightNumber(String f){
this.FlightNumber = f;
}
public String getLocation(){
return this.Location;
}
public void setLocation(String l){
this.Location = l;
}
public static int getTotalPlanes(){
return Plane.TotalPlanes;
}

You keep using this.someField, well with the way you've written it, you don't need to call this.
You can just refer to the field by its name.
However, with your set methods, its more customary for the argument name to have the same name as the field, in which case it is MANDATORY that you use this, so that it knows which variable you are refering to, eg:

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

And same for other set methods.
One more thing... best to keep your variables lowerCamelCase, that means first letter is lower case, and so on, and Classes as UpperCamelCase, hope that helps.
Last edited by cms271828; Oct 10th, 2006 at 12:03 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

Re: boolean

 
0
  #4
Oct 10th, 2006
thank you for help!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC