hi.
Iv got two classes; one creates times and manipulates them (Time), and one creates Atheletes (name etc).
However, once I've got all the values the constructor needs etc, I can't print the data using println.
Here's the code:
-------------Time.java-----------------
/**
*@author: Joe Wardell
*@Worksheet: 4
*@Date: 21/10/02
*/
public class Race
{
//declare attributes:
public String name;
public Time finishTime;
public Race(String theName, Time finishTime)
{
name = theName;
}
//declare the SET and GET method for attribute; name
public void setName (String theName)
{
name = theName;
}
//----------------------------------
public String getName()
{
return name;
}
//-----------------------------------
public void setFinishTime (Time theFinishTime)
{
finishTime = theFinishTime;
}
//-----------------------------------
public Time getFinishTime()
{
return finishTime;
}
//-----------------------------------
//the constructor for Race
//@param name, allows the user to set the name
public static void main(String[] args)
{
Time jw = new Time(1, 3, 58);
Time bp = new Time(3, 40, 30);
Race r1 = new Race("Joe Wardell", jw);
Race r2 = new Race("Ben Price", bp);
}
public raceTest()
{
raceTest rt1 = new raceTest();
rt1.s
public String toString()
{
System.out.println("Racer:\t" + r1 +
"Time:\t" + r2);
}
}//end of class Race
-------------------Racer.java-----------------
/**
*@author: Joe Wardell
*@Worksheet: 4
*@Date: 21/10/02
*/
public class Race
{
//declare attributes:
public String name;
public Time finishTime;
public Race(String theName, Time finishTime)
{
name = theName;
}
//declare the SET and GET method for attribute; name
public void setName (String theName)
{
name = theName;
}
//----------------------------------
public String getName()
{
return name;
}
//-----------------------------------
public void setFinishTime (Time theFinishTime)
{
finishTime = theFinishTime;
}
//-----------------------------------
public Time getFinishTime()
{
return finishTime;
}
//-----------------------------------
//the constructor for Race
//@param name, allows the user to set the name
public static void main(String[] args)
{
Time jw = new Time(1, 3, 58);
Time bp = new Time(3, 40, 30);
Race r1 = new Race("Joe Wardell", jw);
Race r2 = new Race("Ben Price", bp);
this.toString();
}
public String toString()
{
System.out.println("Racer:\t" + r1 +
"Time:\t" + r2);
}
}//end of class Race
-------------------------------------------------
Anyone can try and compile these and see the problems, but it's the toString() that I think is the poblem.
Why can't the instances r1 and r2 be printed so all the values in these instances can be printed???
Any and all comments and suggestions are very welcome!!
cheers every1,
Joe we are all of us living in the gutter.
But some of us are looking at the stars.
Iv got two classes; one creates times and manipulates them (Time), and one creates Atheletes (name etc).
However, once I've got all the values the constructor needs etc, I can't print the data using println.
Here's the code:
-------------Time.java-----------------
/**
*@author: Joe Wardell
*@Worksheet: 4
*@Date: 21/10/02
*/
public class Race
{
//declare attributes:
public String name;
public Time finishTime;
public Race(String theName, Time finishTime)
{
name = theName;
}
//declare the SET and GET method for attribute; name
public void setName (String theName)
{
name = theName;
}
//----------------------------------
public String getName()
{
return name;
}
//-----------------------------------
public void setFinishTime (Time theFinishTime)
{
finishTime = theFinishTime;
}
//-----------------------------------
public Time getFinishTime()
{
return finishTime;
}
//-----------------------------------
//the constructor for Race
//@param name, allows the user to set the name
public static void main(String[] args)
{
Time jw = new Time(1, 3, 58);
Time bp = new Time(3, 40, 30);
Race r1 = new Race("Joe Wardell", jw);
Race r2 = new Race("Ben Price", bp);
}
public raceTest()
{
raceTest rt1 = new raceTest();
rt1.s
public String toString()
{
System.out.println("Racer:\t" + r1 +
"Time:\t" + r2);
}
}//end of class Race
-------------------Racer.java-----------------
/**
*@author: Joe Wardell
*@Worksheet: 4
*@Date: 21/10/02
*/
public class Race
{
//declare attributes:
public String name;
public Time finishTime;
public Race(String theName, Time finishTime)
{
name = theName;
}
//declare the SET and GET method for attribute; name
public void setName (String theName)
{
name = theName;
}
//----------------------------------
public String getName()
{
return name;
}
//-----------------------------------
public void setFinishTime (Time theFinishTime)
{
finishTime = theFinishTime;
}
//-----------------------------------
public Time getFinishTime()
{
return finishTime;
}
//-----------------------------------
//the constructor for Race
//@param name, allows the user to set the name
public static void main(String[] args)
{
Time jw = new Time(1, 3, 58);
Time bp = new Time(3, 40, 30);
Race r1 = new Race("Joe Wardell", jw);
Race r2 = new Race("Ben Price", bp);
this.toString();
}
public String toString()
{
System.out.println("Racer:\t" + r1 +
"Time:\t" + r2);
}
}//end of class Race
-------------------------------------------------
Anyone can try and compile these and see the problems, but it's the toString() that I think is the poblem.
Why can't the instances r1 and r2 be printed so all the values in these instances can be printed???
Any and all comments and suggestions are very welcome!!
cheers every1,
Joe we are all of us living in the gutter.
But some of us are looking at the stars.