-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", "|");
}
}
}
}
如果使用這個它有點亂,第一次對不起。
「*它與花括號*」=>爲什麼不從正確縮進代碼開始?如果您使用IDE,則可以通過單擊完成。 – assylias
事實上,在修復編譯問題之前嘗試調用它是令人擔憂的。你在用什麼IDE? – f1sh