| | |
boolean
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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..?
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..?
•
•
Join Date: Oct 2006
Posts: 101
Reputation:
Solved Threads: 4
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.
{
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.
•
•
Join Date: Oct 2006
Posts: 101
Reputation:
Solved Threads: 4
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.
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.
![]() |
Similar Threads
- Boolean Algebra (C++)
- using boolean expression on an array (Java)
- Questions about assembly and boolean algebra (Assembly)
- Problem with Boolean argument (Java)
- Any Boolean Expression to Sum of Minterms (C++)
Other Threads in the Java Forum
- Previous Thread: String question..
- Next Thread: Need java tutor?
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





