为了账号安全,请及时绑定邮箱和手机立即绑定

Java入门第三季求助

Java入门第三季求助

神华内敛方能以柔克刚 2018-03-02 16:55:53
我尝试这用记事本完成《Java入门第三季》的最终作业,调试了一下午才编译通过,又显示“找不到或无法加载主类”,求帮忙看一下,多谢了!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"); //开始发牌 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); } }
查看完整描述

1 回答

?
carolcoral

TA贡献41条经验 获得超9个赞


如果你确定代码、逻辑都没问题建议重启 eclipse,今天遇到几次一切都没问题就是404的情况,重启 eclipse 就好了
查看完整回答
反对 回复 2018-03-05
  • 1 回答
  • 0 关注
  • 1057 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信