su ma

Greenhorn
+ Follow
since Apr 14, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by su ma

Thankyou very much!



Originally posted by Stefan Willi:
Hi!

Yeah, the class looks fine, but remember, that you perhaps need the package declaration, if there is an package...

If you want test your code, you can simply add a static main method in your class, like the following one.


Use the following commands to compile and run your class.

javac Berth.java
java Berth



I dont know your intention by creating the display method. But, if you only want a method, which produce a String representation of your class, then override the toString() Method from the Object.class (You know, each Class in Java is extending from Object).


I like to add a further annotation!
Java loves naming conventions. EG. A getter or setter Method starts with get/is/set followed by a capitalized Letter. eg. getBerthWidth(). But this is only a recommendation.


Hope, this was usefull.

Stefan

19 years ago
I am just starting java and would appreciate help!
Is this right and how can I test it?

class Berth //class name
{

//declare the variables
private String berthId;
private int berthWidth;
private int berthLength;

//Constructor

Berth(String Bi,int Bw,int Bl)
{
setberthId(Bi);
setberthWidth(Bw);
setberthLength(Bl);

}

// ===================================


//methods

public void setberthId (String Bi)/*start the methods to set the variables
set the berth ID*/

{
berthId=Bi;
}


public void setberthWidth (int Bw)//set the berth width
{
berthWidth=Bw;
}


public void setberthLength (int Bl)//set the berth length

{
berthLength=Bl;
}

//=======================================

public String getberthId() /*start the methods to return the variables
get the berth ID*/
{
return berthId;
}


public int getberthWidth() //get the berth width//

{
return berthWidth;
}


public int getberthLength() //get the berth length//


{
return berthLength;
}

// ===================================

public void display () // method to display the information

{
System.out.println("Berth ID : " + berthId);
System.out.println("Berth Width : " + berthWidth);
System.out.println("Berth Length : " + berthLength);
}

//end methods

}//end class
19 years ago