2017-08-14 8 views
0

RestaurantSelector1クラスをCuisineChoiceにプルして、ユーザーがRestaurantSelector1の変数に割り当てることのできる選択肢を入力できるようにしています。これは私が持っているものです。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); 
} 

そして、これは料理Choiceクラスです:

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; 
    } 

} 
} 
} 

私がどれだけトンを把握することはできませんo場所と料理タイプのユーザー入力を入力として使用して、その場所にあるその料理のランダムレストランを取得します。私はCuisineChoiceにRestaurantSelector1クラスを表示することさえ問題になっています。

ご協力いただければ幸いです。

+1

私は強く[Javaのチュートリアル](https://www.google.by/url?sa=t&rct=j&q=&esrc=s&source=を渡すことをお勧めしますWeb&cd = 1&cad = rja&uact = 8&ved = 0ahUKEwivhJShydfVAhXHBZoKHTdfDVwQFggmMAA&url = https%3A%2F%2Fdocs.oracle.com%2Fjavase%2Ftutorial%2F&usg = AFQjCNE1m2PqVsncDnYixu6Kv67G70IpBw)。それはあなたが今問題を抱えているすべての基本を完全に説明しています –

答えて

0

どちらもアプリケーションの開始点であるメインメソッドと、アプリケーションの構造体は同じパッケージまたは異なるパッケージにありますか? if文のようなコードでいくつかのタイプミスがありますが、 "{"は文を開きません。case文では "{}"は必要ありません。

if (null != location)switch (location) { 

それは次のようになります。

if (null != location){ switch (location) { 
+0

私は、あなたがユーザー入力を求めているところに出発点が欲しいと思っています。スイッチとケースのステートメントはネットビーンズで私に提案されました。私は今それらを修正します。 –

+0

私は、各クラスがmainメソッドを持っていることを意味し、アプリケーションは開始するためのメインメソッドを1つだけ必要とするか、少なくともそれらをアプリケーションの開始ポイントとして指定する必要があります。このメインメソッド(アプリケーションの開始)に、ユーザー入力を求めるコードを設定します。 – Omar

関連する問題