【发布时间】:2014-12-23 20:55:35
【问题描述】:
编译器一直说没有 main 方法,但有一个:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class StarWarsFinal
{
final static Map<String, String> firstNameMap = new HashMap<>();
static {
firstNameMap.put("A", "Cho");
firstNameMap.put("B", "R2");
firstNameMap.put("C", "C-3po");
firstNameMap.put("D", "Yod");
firstNameMap.put("E", "Nas");
firstNameMap.put("F", "Slea");
firstNameMap.put("G", "Jan");
firstNameMap.put("H", "Zhur");
firstNameMap.put("I", "Boba");
firstNameMap.put("J", "Thre");
firstNameMap.put("K", "Bib");
firstNameMap.put("L", "Kit");
firstNameMap.put("M", "Kyp");
firstNameMap.put("N", "Gonk");
firstNameMap.put("O", "Zlung");
firstNameMap.put("P", "Adi");
firstNameMap.put("Q", "Nat");
firstNameMap.put("R", "Ru");
firstNameMap.put("S", "Cla");
firstNameMap.put("T", "Kir");
firstNameMap.put("U", "Obi");
firstNameMap.put("V", "Ken");
firstNameMap.put("W", "Ziro");
firstNameMap.put("X", "Zev");
firstNameMap.put("Y", "Tavion");
firstNameMap.put("Z", "Jar");
}
final static Map<String, String> lastNameMap = new HashMap<>();
static {
lastNameMap.put("A", "tzki");
lastNameMap.put("B", "hut");
lastNameMap.put("C", "der");
lastNameMap.put("D", "kzos");
lastNameMap.put("E", "vos");
lastNameMap.put("F", "vader");
lastNameMap.put("G", "thrawn");
lastNameMap.put("H", "mesk");
lastNameMap.put("I", "thuo");
lastNameMap.put("J", "skywalker");
lastNameMap.put("K", "D2");
lastNameMap.put("L", "maul");
lastNameMap.put("M", "sith");
lastNameMap.put("N", "muzzar");
lastNameMap.put("O", "jusik");
lastNameMap.put("P", "horn");
lastNameMap.put("Q", "phisto");
lastNameMap.put("R", "farlander");
lastNameMap.put("S", "dunhaussan");
lastNameMap.put("T", "jar");
lastNameMap.put("U", "binks");
lastNameMap.put("V", "lbis");
lastNameMap.put("W", "gnarzlo");
lastNameMap.put("X", "anakin");
lastNameMap.put("Y", "ackbur");
lastNameMap.put("Z", "axmis");
}
final static Map<String, String> jobMap = new HashMap<>();
static{
jobMap.put("Jan","Clone");
jobMap.put("Feb","Bounty Hunter");
jobMap.put("Mar","Droid");
jobMap.put("Apr","Jedi Knight");
jobMap.put("May","Gungan");
jobMap.put("Jun","Gangster");
jobMap.put("Jul","commander");
jobMap.put("Aug","ewok");
jobMap.put("Sep","Queen");
jobMap.put("Oct","Empirer");
jobMap.put("Nov","Darth");
jobMap.put("Dec","captain");
}
public static void main ( String[] args )
{
String[] planet = null, rank = null, rebbelion = null, letter1 = null, letter2= null , Map , HashMap;
Scanner input = new Scanner( System.in ); //scanner initilized
planet = new String[11]; //Planet options
planet[0] = "Alderaan";
planet[1] = "Bespin";
planet[2] = "Coruscant";
planet[3]= "Forest moon of Endor";
planet[4] = "Hoth";
planet[5] = "Kamino";
planet[6] = "Kashyyk";
planet[7] = "Mustafar";
planet[8] = "Yavin";
planet[9] = "DEATH STAR";//Planet options -END
System.out.println("Welcome to the Star Wars name generator");
System.out.println("What is your first name?"); //Name Generation
String firstName = input.nextLine();
String newFirst = firstNameMap.get(firstName.toUpperCase().substring(0,1)); //Name Generation (i want to take the first letter of there input and get the output from letter1 matching that # ie c = letter1 [2] a= letter1 [0])
System.out.println("What is your last name?"); //Name Generation
String lastName = input.nextLine(); //Name Generation (i want to take the first letter of there input and get the output from letter2 matching that # ie c = letter2 [2] a= letter2 [0])
String newLast = lastNameMap.get (lastName.toUpperCase().substring(0,1));
System.out.println("What is your Birth month(first 3 letters)?"); //Name Generation
String month = input.nextLine();
String job = jobMap.get(firstName.toUpperCase().substring(0,3));
System.out.println("If you had to choose 1)dark or 2)light side? please input the number"); //Selection of Dark or Light side
int side = input.nextInt();
//Selection of Dark or Light side
System.out.println("There are now several places you could live please choose one of the following by number:"); //Planet selections
System.out.println("1) Alderaan 2) Bespin 3) Coruscant 4) Forest moon of Endor 5) Hoth "); //Planet selections
System.out.println("6) Kamino 7) Kashyyk 8) Mustafar 9) Yavin 10)DEATHSTAR"); //Planet selections
String location =input.nextLine();
if (side == 1)
{
System.out.println("You Have chosen to be part of the dark side!");
System.out.println("You "+ newFirst + newLast +" now fight for the dark side As a proud "+ job +"of the"+ location +"Good luck against your enemy's and may the force be with you");
}
else
{
System.out.println("You are now part of the light side!");
System.out.println("You "+ newFirst + newLast +" now fight for the light side As a proud "+ job +"of the"+ location +"Good luck against your enemy's and may the force be with you");
}
System.out.println("Thank you for doing the starwars name generator!");
}
}
我不知道为什么它不会读取它,因为它之前工作过。我正在使用 NetBeans 作为 IDE。
【问题讨论】:
-
@SubhrajyotiMajumder 类不必公开。
-
@MarkoTopolnik 没错,我刚刚测试过,因为我不相信你!
-
因此,它一定是错误的包(移至默认),尽管 NetBeans 应该向您报告并提供重构。除此之外,我看不出有什么问题。
-
@haywire 怀疑是我们工作中的一个积极特征 :)
-
如果我在 IntelliJ 中运行你的代码,它就可以工作。您编译和调用应用程序的方式可能有问题。使用
javac StarWarsFinal.java编译它并使用java -cp . StarWarsFinal运行它(如果您当前在类文件所在的目录中)。