February 24th, 2000, 06:18 AM
Does anyone understand how to take an object of my Distance class as an argument?
"The fourth and final constructor must take an object of the Distance class as an argument. This constructor will copy the instance variable values from the argument object to the object being instantiated. "
The following is what I have but I keep getting error
// default constructor
public int Distance()
{
feet = yards = miles = 0;
}
//second constructor //
public Distance(int f) { feet = f; }
//third constructor//
public Distance(int y, char units) // Both variables cannot be named y, so I named the second units.
{
switch(units)
{
case 'f':
case 'F':
feet = y;
break;
case 'm':
case 'M':
miles = y;
break;
case 'y':
case 'Y':
yards = y;
break;
default:
feet = yards = miles = 0; }
//fourth argument
public int Distance(int arg1)
{
feet = arg1;
}
}
This will not compile.
not sure what is wrong
"The fourth and final constructor must take an object of the Distance class as an argument. This constructor will copy the instance variable values from the argument object to the object being instantiated. "
The following is what I have but I keep getting error
// default constructor
public int Distance()
{
feet = yards = miles = 0;
}
//second constructor //
public Distance(int f) { feet = f; }
//third constructor//
public Distance(int y, char units) // Both variables cannot be named y, so I named the second units.
{
switch(units)
{
case 'f':
case 'F':
feet = y;
break;
case 'm':
case 'M':
miles = y;
break;
case 'y':
case 'Y':
yards = y;
break;
default:
feet = yards = miles = 0; }
//fourth argument
public int Distance(int arg1)
{
feet = arg1;
}
}
This will not compile.
not sure what is wrong