我有點困惑,因爲我無法弄清楚我在這裏做錯了什麼。我做了幾乎所有我可以做的事情,但仍然無法正常工作。我現在無言如何從這裏前進。請幫助,我真的很感謝你的可能解決方案。由於麻煩在Java中的類
public class Example {
public static void main(String[] args) {
String cafescan;
Scanner scan= new Scanner (System.in);
System.out.print ("Please enter the name of the cafe :");
cafescan = scan.nextLine();
Cafe naam = new Cafe();
naam.name = (cafescan);//THIS WORKS FINE
Cafe thau = new Cafe();
thau.location = (location1);//THIS IS WHERE ERROR IS
System.out.println (naam.setName());
System.out.print (thau.setLocation());
在我Cafe.jave文件我有這樣的:
public class Cafe{
String name;
String location;
public String setName(){
name=name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase()+ " Cafe";
return name;
}
public String setLocation(){
char location1 = name.charAt(0);
//SWITCH IS SUPPOSED TO WORK ACCORDING TO FIRST ALPHABET OF cafescan
switch (location1)
{
case 'E':
System.out.println("Rosedale");
break;
case 'M':
System.out.println ("Parkville");
break;
case 'T':
System.out.println ("Towson");
break;
default:
System.out.println("Baltimore");
}
return location;
}
}
幫我出大師:)
' location1'的數據類型是? –
什麼不起作用?你會得到什麼錯誤? – 2013-04-15 06:40:45
您是否收到錯誤'找不到符號位置1'? – sanbhat