我试图将RestaurantSelector1类拉入CuisineChoice,以便我能够让用户输入选择,然后我可以将其分配给RestaurantSelector1中的变量(如果这有意义的话。这就是我所拥有的:< / p>
在RestaurantSelector1:
public class RestaurantSelector1 {
public static String getRandom(List<String[]> list) {
Random random = new Random();
int listAccess = random.nextInt(list.size());
String[] s = list.get(listAccess);
return s[random.nextInt(s.length)];
}
public static void main(String[] args){
ArrayList<String[]> WestVillageCuisine = new ArrayList<String[]>();
WestVillageCuisine.add(Expensive.WestVillage.italian);
.
.
.
WestVillageCuisine.add(Expensive.WestVillage.greek);
final String[] randomCuisine = WestVillageCuisine.get(random.nextInt(WestVillageCuisine.size()));
final String randomRestaurant = randomCuisine[random.nextInt(randomCuisine.length)];
final String[] randomWVItalian = WestVillageCuisine.get(0);
final String westVillageItalian = r randomWVItalian[random.nextInt(randomWVItalian.length)];
System.out.println(getRandom(WestVillageCuisine));
System.out.println(randomRestaurant);
System.out.println(westVillageItalian);
}
这是烹饪选择课:
class CuisineChoice{
public static void main(String[] args){
RestaurantSelector1 A = new RestaurantSelector1();
System.out.println("What price range are you looking for? one = $-$$ and two = $$$-$$$$");
Scanner scan2 = new Scanner(System.in);
String price = scan2.next();
if (price.equals("two")){
price = "Expensive";
System.out.println("In which neighborhood would you like to eat?");
Scanner scan = new Scanner(System.in);
String location = scan.next();
if (null != location)switch (location) {
case "Tribeca":{
System.out.println("Great! And what type cuisine would you like in " + location + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location + " " + type + " " + price);
break;
}
case "West Village":{
System.out.println("Great! And what type cuisine would you like in " + location + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location + " " + type + " " + price);
break;
}
case "Flatiron":{
System.out.println("Great! And what type cuisine would you like in " + location + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location + " " + type + " " + price);
break;
}
case "Chelsea":{
System.out.println("Great! And what type cuisine would you like in " + location + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location + " " + type + " " + price);
break;
}
default:
break;
}
}
else{
price= "Inexpensive"; System.out.println("In which neighborhood would you like to eat?");
Scanner scan3 = new Scanner(System.in);
String location1 = scan3.next();
if (null != location1)switch (location1) {
case "Tribeca":{
System.out.println("Great! And what type cuisine would you like in " + location1 + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location1 + " " + type + " " + price);
break;
}
case "West Village":{
System.out.println("Great! And what type cuisine would you like in " + location1 + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location1 + " " + type + " " + price);
break;
}
case "Flatiron":{
System.out.println("Great! And what type cuisine would you like in " + location1 + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location1 + " " + type + " " + price);
break;
}
case "Chelsea":{
System.out.println("Great! And what type cuisine would you like in " + location1 + " ?");
Scanner scan1 = new Scanner(System.in);
String type = scan1.next();
System.out.print(location1 + " " + type + " " + price);
break;
}
default:
break;
}
}
}
}
我无法弄清楚如何使用位置和美食类型的用户输入作为输入,以获得该位置的随机餐厅。我甚至无法让RestaurantSelector1课程出现在CuisineChoice中。
非常感谢任何帮助!
答案 0 :(得分:0)
两者都有main方法,哪一个是应用程序的起点,你的应用程序的结构是什么,它们是在同一个包中还是在不同的包中?并且你在if语句等代码中有一些拼写错误,它没有&#34; {&#34;打开陈述,在案件陈述中你不需要&#34; {}&#34;。
if (null != location)switch (location) {
应该是:
if (null != location){ switch (location) {