2017-04-26 16 views
-5

を取得しています:Javaコードでエラーが発生するのはなぜですか?だから私はこのエラーを

Exception in thread "main" java.lang.Error: Unresolved compilation problem: at KidsToys.main(KidsToys.java:24)

私は思うが、私はあまりにもわからない中括弧で行うには、その何かを、誰もが知っているのですか?単純な構文エラーですか?

/* 
    * class KidsToys skeleton code 
    * 
    * This code is incomplete. It implements the data storage 
    * and functional requirements for a program that manages the 
    * inventory in a toy store. However, the helper methods 
    * are not implemented, these are for you to do so! 
    */ 

    import java.util.*; 

    public class KidsToys { 


    // you can refer to the array and Scanner object here anywhere 
    // within this class, even within helper methods if you choose to 
    // implement them 

    private static final Toy [] inventory = new Toy [8]; 
    private static final Scanner sc = new Scanner(System.in); 



    public static void main(String[] args) 
    { 

    String userInput; 


    inventory[0] = new Toy("SOC-001","Socker Bopper Body Ball", 99.95, 2); 
    inventory[1] = new Toy("MEC-301", "Meccano M. A. X. Robot", 279.00, 8); 
    inventory[2] = new Toy("PWR-504", "Power Rangers Movie 17cm Red Ranger", 28.99, 18); 
    inventory[3] = new Toy("NER-020", "Nerf Zombie Strike Outbreaker Bow", 34.99, 16); 
    inventory[4] = new Toy("PWR-505", "Power Rangers Movie 17cm Pink Ranger", 28.99, 11); 
    inventory[5] = new Toy("LEG-710", "Lego Batman Movie - Arkham Asylum", 249.95, 5); 
    inventory[6] = new Toy("LEG-640", "Lego City High Speed Chase", 124.99, 0); 
    inventory[7] = new Toy("TST-750", "Toy Story Buzz and Woody Walkie Talkie", 139.99, 4); 


    // initialise selection variable to ascii nul to keep compiler happy 
    char selection = '\0'; 

    // creating and storing specified set of Toy objects in the array 
    do 
    { 

    // print menu to screen 
    System.out.println("Toy Store Inventory Program"); 
    System.out.println("---------------------------"); 
    System.out.println(); 

    System.out.printf("%-25s%s\n", "Display Inventory", "A"); 
    System.out.printf("%-25s%s\n", "Print Reorder List", "B"); 
    System.out.printf("%-25s%s\n", "Product Range Search", "C"); 
    System.out.printf("%-25s%s\n", "Accept Delivery", "D"); 
    System.out.printf("%-25s%s\n", "Make Sale", "E"); 
    System.out.printf("%-25s%s\n", "Exit Program", "X"); 
    System.out.println(); 

    // prompt user to enter selection 
    System.out.print("Enter selection: "); 
    userInput = sc.nextLine(); 

    System.out.println(); 

    // validate selection input length 
    if (userInput.length() != 1) 
    { 
     System.out.println("Error - invalid selection!"); 
    } 
    else 
    { 
     // make selection "case insensitive" 
     selection = Character.toUpperCase(userInput.charAt(0)); 

     // process user's selection 
     switch (selection) 
     { 
      case 'A': 
      displayInventory(); 
       break; 

      case 'B': 
      printReorderList(); 
       break; 

      case 'C': 
       // productRangeSearch(); 
       break; 

      case 'D': 
       // acceptDelivery(); 
       break; 

      case 'E': 
       // makeSale(); 
       break; 

      case 'X': 
       System.out.println("Exiting the program..."); 
       break; 

      default: 
       System.out.println("Error - invalid selection!"); 
      } 
     } 
     System.out.println(); 

    } while (selection != 'X'); 
} 
     public static void displayInventory() 

     { 
     for(int i = 0; i < inventory.length; i++) { 

      inventory[i].printDetails(); 
    } 
    } 
    public static void printReorderList() 

    { 
     System.out.println("----------------------------------------------------------------------"); 
     System.out.printf("%-1s%-12s%-1s%-38s%-1s%", "Product Code", "|", "Description", "|","Unit Price", 
      "|", "Stock Level", "|"); 




     } 
    } 

} 
} 

その少し厄介、最初の時間は、これを使用している場合申し訳ありません。

+4

"*中括弧と関係する* *" =>なぜコードを正しくインデントしないのですか? IDEを使用している場合、おそらくワンクリックでそれを行うことができます。 – assylias

+0

コンパイルの問題を修正する前に調整するということは心配です。どのIDEを使用していますか? – f1sh

答えて

0

私はそれを見る方法あなたの持っているあなたの投稿コードに次の2つの問題:

  1. あなたのコード内の玩具クラスには輸入がありません。そのimport文を追加して、javaが何をするべきかを知るようにします。
  2. また、最後にの中かっこ2つがあります。
関連する問題