我有点困惑,因为我无法弄清楚我在这里做错了什么。我已经做了我能做的几乎所有事情,但仍然无法正常工作。我现在不知道如何从这里前进。请提供帮助,我非常感谢您提供可能的解决方案。谢谢
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;
}
}
帮我看看大师:)