我嘗試這用記事本完成《Java入門第三季》的最終作業(yè),調試了一下午才編譯通過,又顯示“找不到或無法加載主類”,求幫忙看一下,多謝了!package?game;
public?class?Main{
public?static?void?main?(String?[]?args){
new?Game();
}
}package?game;
import?java.util.Scanner;
import?java.util.Random;
import?java.util.List;
import?java.util.ArrayList;
public?class?Game?{
List<Card>?cards;
Player?playerA,playerB;
short?a;
Card?temporary;
Random?random;
public?Game(){
this.random?=?new?Random();
this.cards?=?new?ArrayList<Card>();
Scanner?scanner?=?new?Scanner(System.in);
System.out.println("please?input?first?player's?name");
this.playerA?=?new?Player(scanner.next());
System.out.println("please?input?second?player's?name");
this.playerB?=?new?Player(scanner.next());
System.out.println("loading");
//開始洗牌
for(short?times?=?0;times?<?52;times?++){
do{
this.temporary?=?new?Card((short)(random.nextInt(13)+1),(short)(random.nextInt(4)+1));
}while(this.cards.contains(temporary));
}
System.out.println("please?waite?a?minute");
//開始發(fā)牌
a?=?(short)random.nextInt(this.cards.size());
this.playerA.take(this.cards.get(a));
this.cards.remove(a);
a?=?(short)random.nextInt(this.cards.size());
this.playerB.take(this.cards.get(a));
this.cards.remove(a);
a?=?(short)random.nextInt(this.cards.size());
this.playerA.take(this.cards.get(a));
this.cards.remove(a);
a?=?(short)random.nextInt(this.cards.size());
this.playerB.take(this.cards.get(a));
this.cards.remove(a);
//開始比較
System.out.println("fight");
if(this.playerA.show().compareTo(this.playerB.show())?>?0){
System.out.println("Player:A?Wins?!");
}else?{
System.out.println("Player:B?Wins?!");
}
//游戲結束
System.out.println("Game?Over?!");
}
}package?game;
public?class?Card?implements?Comparable?<Card>{
short?number;
short?shape;
public?Card(short?number,short?shape){
this.number?=?number;
this.shape?=?shape;
}
public?int?compareTo(Card?card){
if(this.number?==?card.number){
return?(new?Integer(this.shape)).compareTo(new?Integer(card.shape));
}else?{
return?(new?Integer(this.number)).compareTo(new?Integer(card.number));
}
}
public?boolean?equals(Card?card){
if?(this.number?==?card.number?&?this.shape?==?card.shape){
return?true;
}else{
return?false;
}
}
}package?game;
import?java.util.List;
import?java.util.ArrayList;
import?java.util.Collections;
public?class?Player?{
String?name;
List<Card>?cards;
public?Player(String?name){
this.name?=?name;
this.cards?=?new?ArrayList<Card>();
}
public?Card?show?(){
Collections.sort(this.cards);
return?this.cards.get(1);
}
public?void?take?(Card?card){
this.cards.add(card);
}
}
Java入門第三季求助
神華內斂方能以柔克剛
2018-03-02 16:55:53