程序完全不能运行。。。

bileebilee 2014-05-02 03:22:38
编了下面这个程序,是一个Nim游戏,要求可以添加删除重置用户,可是写完之后完全不能运行,我对多个class的程序不是很熟,实在找不出来是怎么回事了,希望各位大神帮帮忙,马上就要交作业了,很急。。。
import java.util.Arrays;

public class NimPlayer {

public String username;
public String family_name;
public String given_name;
public int game;
public int win;
public int percentage;

public final static int MAX_PLAYER_NUM = 100;
static NimPlayer [] players = new NimPlayer[MAX_PLAYER_NUM];

static int numofplayer = 0;

public void addplayer(String username, String family_name, String given_name){
for (int index = 0; index < numofplayer; index++) {
if (players[index].username == username) {
System.out.println("The player already exists.");
System.out.println();
System.out.printf(">");
return;
}
}
players[numofplayer].username = username;
players[numofplayer].family_name = family_name;
players[numofplayer].given_name = given_name;
numofplayer++;
System.out.println();
System.out.printf(">");
}

public void removeplayer(String username){
for (int index = 0; index < numofplayer; index++) {
if (players[index].username == username) {
players[index] = players[numofplayer-1];
players[numofplayer-1] = null;
numofplayer--;
System.out.println();
System.out.printf(">");
return;
}
}
System.out.println("The player does not exist.");
System.out.println();
System.out.printf(">");
}

public void removeallplayer(){
System.out.println("Are you sure you want to remove all players? (y/n)");
String flag = Nimsys.keyboard.next();
if (flag == ("y")){
for (int index = 0; index < numofplayer; index++){
players[index] = null;
}
}
System.out.println();
System.out.printf(">");
}

public void editplayer(String username, String new_family_name, String new_given_name){
for (int index = 0; index < numofplayer; index++) {
if (players[index].username == username) {
players[index].family_name = new_family_name;
players[index].given_name = new_given_name;
System.out.println();
System.out.printf(">");
return;
}
}
System.out.println("The player does not exist.");
System.out.println();
System.out.printf(">");
}

public void resetstats(String username){
for (int index = 0; index < numofplayer; index++) {
if (players[index].username == username) {
players[index].game = 0;
players[index].win = 0;
players[index].percentage = 0;
System.out.println();
System.out.printf(">");
return;
}
}
System.out.println("The player does not exist.");
System.out.println();
System.out.printf(">");
}

public void resetstatsall(){
System.out.println("Are you sure you want to reset all player statistics? (y/n)");
String flag = Nimsys.keyboard.next();
if (flag == ("y")){
for (int index = 0; index < numofplayer; index++){
players[index].game = 0;
players[index].win = 0;
players[index].percentage = 0;
}
}
System.out.println();
System.out.printf(">");
}

public void displayplayer(String username){
for (int index = 0; index < numofplayer; index++) {
if (players[index].username == username) {
System.out.println(getdescription(index));
System.out.println();
System.out.printf(">");
return;
}
}
System.out.println("The player does not exist.");
System.out.println();
System.out.printf(">");
}

public void displayallplayer(){
Arrays.sort(players);
for (int index = 0; index < numofplayer; index++){
System.out.println(getdescription(index));
}
}

public static String getdescription(int index){
String description = (players[index].username + ", " + players[index].given_name + ", " + players[index].family_name + ", " + players[index].game + "games, " + players[index].win + "wins");
return description;
}

import java.util.Scanner;

public class Nimsys {

public static Scanner keyboard;

public static void main(String[] args){
keyboard = new Scanner(System.in);
System.out.println("Welcome to Nim");
System.out.printf("\n>");
NimPlayer player = new NimPlayer();
NimGame newgame = new NimGame();
while(true){
String[] command = keyboard.next().split(",| ");

if (command[0] == "addplayer")
player.addplayer(command[1], command[2], command[3]);
else if ((command[0] == "removeplayer") && (command.length != 1))
player.removeplayer(command[1]);
else if ((command[0] == "removeplayer") && (command.length == 1))
player.removeallplayer();
else if (command[0] == "editplayer")
player.editplayer(command[1], command[2], command[3]);
else if ((command[0] == "resetstats") && (command.length != 1))
player.resetstats(command[1]);
else if ((command[0] == "resetstats") && (command.length == 1))
player.resetstatsall();
else if ((command[0] == "displayplayer") && (command.length != 1))
player.displayplayer(command[1]);
else if ((command[0] == "displayplayer") && (command.length == 1))
player.displayallplayer();
else if (command[0] == "startgame")
newgame.startgame(Integer.parseInt(command[1]), Integer.parseInt(command[2]), command[3], command[4]);
}
}

public class NimGame {

public void startgame(int initialstones, int upperbound, String username1, String username2){
int currentplayer;
int nextplayer;
int removal;
if (checkplayer(username1) && checkplayer(username2)){
currentplayer = getplyerindex(username1);
nextplayer = getplyerindex(username2);
System.out.println();
System.out.println("Initial stone count: " + initialstones);
System.out.println("Maximum stone removal: " + upperbound);
System.out.println("Player1: " + NimPlayer.players[currentplayer].given_name + NimPlayer.players[currentplayer].family_name);
System.out.println("Player2: " + NimPlayer.players[nextplayer].given_name + NimPlayer.players[nextplayer].family_name);
}
else{
System.out.println("One of the players does not exist.");
System.out.println();
System.out.printf(">");
return;
}

while (initialstones != 0)
{
System.out.println();
System.out.printf(initialstones + " stones left:");
int stone;
for(stone = initialstones;stone >0;stone--)
System.out.print(" *");
System.out.println("\n" + NimPlayer.players[currentplayer].given_name + "'s turn - remove how many?");
removal = Nimsys.keyboard.nextInt();
if (removal > 0 && removal < min(initialstones, upperbound)){
initialstones = initialstones - removal;
int temp = currentplayer;
nextplayer = currentplayer;
currentplayer = temp;
}
else{
System.out.println("/nInvalid move. You must remove between 1 and " + min(initialstones, upperbound) + "stones.");
continue;
}
}
System.out.println();
System.out.println("Game Over");
System.out.println(NimPlayer.players[currentplayer].given_name + " " + NimPlayer.players[currentplayer].family_name + " wins!");
NimPlayer.players[currentplayer].game++;
NimPlayer.players[currentplayer].win++;
NimPlayer.players[nextplayer].game++;
}

public static boolean checkplayer(String username){
for (int index = 0; index < NimPlayer.numofplayer; index++){
if (NimPlayer.players[index].username == username)
return true;
}
return false;
}

public static int getplyerindex(String username){
int playerindex = 0;
for (int index = 0; index < NimPlayer.numofplayer; index++){
if (NimPlayer.players[index].username == username)
playerindex = index;
}
return playerindex;
}

private static int min(int n1, int n2) {
int temp = 0;
if (n1 < n2)
temp = n1;
else
temp = n2;
return temp;
}
}
...全文
348 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
-江沐风- 2014-05-02
  • 打赏
  • 举报
回复
直接运行Nimsys这个类不就可以了;
DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复。程序主要针对0xc000007b问题设计,可以完美修复该问题。本程序中包含了最新版的DirectX redist(Jun2010),并且全部DX文件都有Microsoft的数字签名,安全放心。 本程序为了应对一般电脑用户的使用,采用了傻瓜式一键设计,只要点击主界面上的“检测并修复”按钮,程序就会自动完成校验、检测、下载、修复以及注册的全部功能,无需用户的介入,大大降低了使用难度。 本程序适用于多个操作系统,如Windows XP(需先安装.NET 2.0,详情请参阅“致Windows XP用户.txt”文件)、Windows Vista以及Windows 7,同时兼容32位操作系统和64位操作系统。本程序会根据系统的不同,自动调整任务模式,无需用户进行设置。 本程序的V2.1版分为标准版、增强版以及在线修复版。其中的标准版以及增强版都包含完整的DirectX组件,增强版中还额外包含了c++ Redistributable Package,因此增强版适合无法自行解决c++相关问题的用户使用;在线修复版的功能与标准版相同,只是其所需的文件将通过Internet下载,因此大大减小了程序的体积。本程序的各个版本之间,主程序完全相同,只是配套使用的数据包不同。因此,当您使用标准版数据包时,程序将进行标准修复;当您使用增强版的数据包时,程序将进行增强修复;当数据包不全或没有数据包(即只有DirectX Repair.exe程序)时,程序将进行在线修复。在线修复、离线修复可自由灵活组合,充分满足不同用户的需要。 本程序自V2.0版起采用全新的底层程序架构,使用了异步多线程编程技术,使得检测、下载、修复单独进行,互不干扰,快速如飞。新程序更改了自我校验方式,因此使用新版本的程序时不会再出现自我校验失败的错误;但并非取消自我校验,因此程序安全性与之前版本相同,并未降低。 程序有自动更新c++功能。由于绝大多数软件运行时需要c++的支持,并且c++的异常也会导致0xc000007b错误,因此程序在检测修复的同时,也会根据需要更新系统中的c++组件。此功能仅限于增强版。 本程序有自动记录日志功能,可以记录每一次检测修复结果,方便在出现问题时,及时分析和查找原因,以便找到解决办法。 程序的“选项”对话框中包含了2项高级功能。点击其中的“注册系统中所有dll文件”按钮可以自动注册系统文件夹下的所有dll文件。该项功能不仅能修复DirectX的问题,还可以修复系统中很多其他由于dll未注册而产生的问题,颇为实用。点击第二个按钮可以为dll文件的右键菜单添加“注册”和“卸载”项,方便对单独的dll文件进行注册。请注意,并不是所有的dll文件都可以通过这种方式注册。 新版程序集成了用户反馈程序,可以在用户允许的前提下发送检测修复结果。用户也可以在出现问题时通过反馈程序和软件作者进行交流,共同查找问题。反馈是完全自愿和匿名(如果不填写E-mail地址)的。 本程序基于Microsoft .NET Framework 2.0开发,对于Windows 2000、Windows XP、Windows 2003的用户需要首先安装.NET Framework 2.0或更高版本方可运行程序。有关下载和安装的详细信息请参阅“致Windows XP用户.txt”文件。对于Windows Vista、Windows 7用户,可以直接运行程序。 本程序的官方博客地址为:http://blog.csdn.net/vbcom/article/details/6962388 所有的更新以及技术支持都可以到该博客上找到。
DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复。程序主要针对0xc000007b问题设计,可以完美修复该问题。本程序中包含了最新版的DirectX redist(Jun2010),并且全部DX文件都有Microsoft的数字签名,安全放心。 本程序为了应对一般电脑用户的使用,采用了傻瓜式一键设计,只要点击主界面上的“检测并修复”按钮,程序就会自动完成校验、检测、下载、修复以及注册的全部功能,无需用户的介入,大大降低了使用难度。 本程序适用于多个操作系统,如Windows XP(需先安装.NET 2.0,详情请参阅“致Windows XP用户.txt”文件)、Windows Vista、Windows 7、Windows 8、Windows 8.1、Windows 8.1 Update、Windows 10,同时兼容32位操作系统和64位操作系统。本程序会根据系统的不同,自动调整任务模式,无需用户进行设置。 本程序的V3.3版分为标准版、增强版以及在线修复版。其中的标准版以及增强版都包含完整的DirectX组件。除此之外,增强版中还额外包含了c++ Redistributable Package,因此增强版不但能解决DirectX组件的问题,而且还能解决c++组件异常产生的问题。增强版适合无法自行解决c++相关问题的用户使用。在线修复版的功能与标准版相同,只是其所需的文件将通过Internet下载,因此大大减小了程序的体积。本程序的各个版本之间,主程序完全相同,只是配套使用的数据包不同。因此,当您使用标准版数据包时,程序将进行标准修复;当您使用增强版的数据包时,程序将进行增强修复;当数据包不全或没有数据包(即只有DirectX Repair.exe程序)时,程序将进行在线修复。在线修复、离线修复可自由灵活组合,充分满足不同用户的需要。 本程序自V2.0版起采用全新的底层程序架构,使用了异步多线程编程技术,使得检测、下载、修复单独进行,互不干扰,快速如飞。新程序更改了自我校验方式,因此使用新版本的程序时不会再出现自我校验失败的错误;但并非取消自我校验,因此程序安全性与之前版本相同,并未降低。 程序有自动更新c++功能。由于绝大多数软件运行时需要c++的支持,并且c++的异常也会导致0xc000007b错误,因此程序在检测修复的同时,也会根据需要更新系统中的c++组件。自V3.2版本开始使用了全新的c++扩展包,可以大幅提高工业软件修复成功的概率。修复c++的功能仅限于增强版,标准版及在线修复版在系统c++异常时(非丢失时)会提示用户使用增强版进行修复。 程序有两种窗口样式。正常模式即默认样式,适合绝大多数用户使用。另有一种简约模式,此时窗口将只显示最基本的内容,修复会自动进行,修复完成10秒钟后会自动退出。该窗口样式可以使修复工作变得更加简单快速,同时方便其他软件、游戏将本程序内嵌,即可进行无需人工参与的快速修复。开启简约模式的方法是:打开程序所在目录下的“Settings.ini”文件(如果没有可以自己创建),将其中的“FormStyle”一项的值改为“Simple”并保存即可。 程序有高级筛选功能,开启该功能后用户可以自主选择要修复的文件,避免了其他不必要的修复工作。同时,也支持通过文件进行辅助筛选,只要在程序目录下建立“Filter.dat”文件,其中的每一行写一个需要修复文件的序号即可。该功能仅针对高级用户使用,并且必须在正常窗口模式下才有效(简约模式时无效)。 本程序有自动记录日志功能,可以记录每一次检测修复结果,方便在出现问题时,及时分析和查找原因,以便找到解决办法。 程序的“选项”对话框中包含了4项高级功能。点击其中的“注册系统文件夹中所有dll文件”按钮可以自动注册系统文件夹下的所有dll文件。该项功能不仅能修复DirectX的问题,还可以修复系统中很多其他由于dll未注册而产生的问题,颇为实用。点击该按钮旁边的小箭头,还可以注册任意指定文件夹下的dll文件,方便用户对绿色版、硬盘版的程序组件进行注册。点击第二个按钮可以为dll文件的右键菜单添加“注册”和“卸载”项,方便对单独的dll文件进行注册。请注意,并不是所有的dll文件都可以通过这种方式注册。点击“DirectX版本”选项卡可以自行修改系统中DirectX的版本信息。点击“DirectX加速”选项卡可以控制系统中DirectX加速的开启与关闭。 新版程序集成了用户反馈程序,可以在用户允许的前提下发送检测修复结果。用户也可以在出现问题时通过反馈程序和软件作者进行交流,共同查找问题。反馈是完全自愿和匿名(如果不填写E-mail地址)的。 本程序的通用版基于Microsoft .NET Framework 2.0开发,对于Windows 2000、Windows XP、Windows 2003的用户需要首先安装.NET Framework 2.0或更高版本方可运行程序。有关下载和安装的详细信息请参阅“致Windows XP用户.txt”文件。对于Windows Vista、Windows 7及后续用户,可以直接运行程序。 同时鉴于Windows 8(Windows 8.1、Windows 8.1 Update)、Windows 10系统中默认未包含.NET Framework 2.0,因此新版的程序文件夹内将包含一个DirectX_Repair_win8的特别版程序,该程序功能与通用版相同,基于.NET Framework 4.0开发,可以在Windows8(Windows 8.1、Windows 8.1 Update)、Windows 10系统中直接运行(其他系统如果安装了.NET Framework 4.0也可以运行这个特别版的程序)。 本程序的官方博客地址为:http://blog.csdn.net/vbcom/article/details/6962388 所有的更新以及技术支持都可以到该博客上找到。

51,402

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧