Java Reference
In-Depth Information
//constructor with parameter
//Postcondition: x = num
public IntClass( int num)
{
x = num;
}
//Method to set the data member x
//Postcondition:x=num
public void setNum( int num)
{
x = num;
}
//Method to return the value of x
//Postcondition: The value of x is returned
public int getNum()
{
return x;
}
//Method to update the value of x by adding
//the value of num
//Postcondition: x = x + num;
public void addToNum( int num)
{
x = x + num;
}
//Method to update the value of x by multiplying
//the value of x by num
//Postcondition: x = x * num;
public void multiplyToNum( int num)
{
x = x * num;
}
//Method to compare the value of x with the value of num
//Postcondition: Returns a value < 0 if x < num
// Returns 0 if x == num
// Returns a value>0ifx>num
public int compareTo( int num)
{
return (x - num);
}
//Method to compare x with num for equality
//Postcondition: Returns true if x == num;
// otherwise it returns false
public boolean equals( int num)
{
if (x == num)
return true ;
else
return false;
}
Search WWH ::




Custom Search