This is all wrong I'm afraid. The variables
day
and
n
do not exist in the
toString
method. They should be set either in the constructor:
class ThisClass {
private int dayOfTheWeek;
private String name;
ThisClass(int day, String name) {
this.dayOfTheWeek = day;
this.name = name;
}
or by using setters (see
Adding Setter and Getter Methods - The Java EE 6 Tutorial[
^]).
Also you should not be printing the data in the
toString
method. Its purpose is to return a string which may be printed by the caller. So Your method should look like:
public String toString(){
String textday = new String("The name of the show is: " + n + "and airs on: " + day);
return textday;
}