我得到以下錯誤:Getter/Setter方法錯誤。找不到符號
Line 13, cannot find symbol - System.out.println(getDirection(room1)); (with an arrow pointing to room1). Symbol: Variable room 1 location: class ArtRecord.
本質是什麼代碼試圖做的是,去的getDirection
的方法。並獲取在setDirection
中設置的room1的方向。
import java.util.Scanner;
class ArtRecord
{
public static void main (String[] param)
{
Scanner reader = new Scanner(System.in);
createandprintsart();
String location = askwhere();
if (location == "Room 1"){
System.out.println(getDirection(room1)); //#ERROR FOUND ON THIS LINE
}
}
public static void createandprintsart()
{
Art room1 = new Art();
Art room2 = new Art();
Art room3 = new Art();
Art room4 = new Art();
//System.out.println(getDirection(room2));
room1 = setDirection(room1, "To your left is a painting by");
room2 = setDirection(room2, "Ahead of you is a painting by");
}
public static String askwhere()
{
Scanner reader = new Scanner(System.in);
System.out.println("What room are you in?");
System.out.println("Room 1");
System.out.println("Room 2");
System.out.println("Room 3");
System.out.println("Room 4");
String locationvalue = reader.nextLine();
return locationvalue;
}
public static void doStuff(Art room)
{
}
public static Art setDirection(Art room, String direction)
{
room.direction=direction;
return room;
}
public static String getDirection(Art room)
{
return room.direction;
}
}
class Art
{
String direction;
String artist;
String title;
int year;
int height;
int width;
}
由於
@ c650請您詳細說明。 – Haque
查看我的回答... – Charles
@ c650它不會編譯,那麼'println'如何提供幫助? – ajb