java真的代码 java代码可以直接被执行吗( 二 )


this.penaltyKickRate = penaltyKickRate;
}
//返回分数信息
@Override
public String toString() {
return "** PLAYER ADDED **"+ player.toString()+"; Points:"+ spointsScored + "; Assists: "+ assists +"; Penalty Kick %:" + penaltyKickRate;
}
}
这里是主类:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
/**
* 主类
* @author songfeng163
*/
public class MyMain {
//添加方法
public ListSoccerPlayerStats add(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
SoccerPlayerStats score=new SoccerPlayerStats();
System.out.println("请输入运动类型:足球,高尔夫,田径:");
player.setLx(in.next());
System.out.println("请输入姓:");
player.setXing(in.next());
System.out.println("请输入名:");
player.setMing(in.next());
System.out.println("请输入该运动员的点球得分:");
score.setSpointsScored(in.nextDouble());
System.out.println("请输入该运动员的助攻得分:");
score.setAssists(in.nextDouble());
System.out.println("请输入该运动员的罚球得分概率:");
score.setPenaltyKickRate(in.nextDouble());
score.setPlayer(player);
System.out.println(score);//显示新添加的人员
list.add(score);
return list;
}
//删除方法
public ListSoccerPlayerStats del(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
System.out.println("请输入要删除运动员的姓:");
player.setXing(in.next());
System.out.println("请输入要删除运动员的名:");
player.setMing(in.next());
for(SoccerPlayerStats score:list){
if(score.getPlayer().getXing().equals(player.getXing())
score.getPlayer().getMing().equals(player.getMing())){
list.remove(score);
【java真的代码 java代码可以直接被执行吗】break;
}
}
return list;
}
//显示方法
public void show(ListSoccerPlayerStats list){
System.out.println("当前共有:"+list.size()+"条记录,内容如下:");
for(SoccerPlayerStats score:list){
System.out.println(score);
}
}
//保存方法
public ListSoccerPlayerStats save(ListSoccerPlayerStats list){
System.out.println("请输入要保存的文件名:");
Scanner in=new Scanner(System.in);
String fileName=in.next();
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("C:/"+fileName));
for(SoccerPlayerStats score:list){
bw.write(score.toString());
bw.newLine();
}
bw.flush();
bw.close();
}catch(Exception ex){
ex.printStackTrace();
}
System.out.println("** 1 RECORD SAVED TO "+fileName+" **");
return list;
}
public static void main(String[] args) {
MyMain myMain=new MyMain();
Scanner in=new Scanner(System.in);
//如果像你说的是数组的话 , 数据没有办法动态变化,所以我用了list
ListSoccerPlayerStats list=new ArrayListSoccerPlayerStats();
String cz="QUIT";//默认的操作为退出
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");
String czin=in.next();//输入数据
cz=czin.toUpperCase();//转换成大写
while(!cz.equals("QUIT")){//不是退出
if(cz.equals("ADD")){//添加数据
list = myMain.add(list);
}else if(cz.equals("REMOVE")){//删除数据
list = myMain.del(list);
}else if(cz.equals("SHOW")){//显示数据
myMain.show(list);
}else if(cz.equals("SAVE")){//保存数据
myMain.save(list);
}
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");

推荐阅读