实训一
1.实训内容:
黄金点:
阿超的课都是下午两点钟,这时班上不少的同学都昏昏欲睡,为了让大家兴奋起来,阿超让同学玩一个叫“黄金点”的游戏:
N个同学(N通常大于10),每人写一个0~100之间的有理数 (不包括0或100),交给裁判,裁判算出所有数字的平均值,然后乘以0.618(所谓黄金分割常数),得到G值。提交的数字最靠近G(取绝对值)的同学得到N分,离G最远的同学得到-2分,其他同学得0分。记录每一次游戏每名同学的数字和分数。
2.成员:
16012108于谦
16012124于俊渤
码云地址:https://gitee.com/yujuncc/codes/ht4w3nackdbzeis92flur22
过程照片:
3代码:
hile (true) {
System.err.println("1、开始游戏");
Scanner scanner=new Scanner(System.in);
int choice=scanner.nextInt();
switch (choice) {
case 1:
welcome();
break;
default:
break;
}
}
private static void welcome() {
System.out.println("游戏默认初试玩家的分数为100");
System.out.print("请输入游戏人数: ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
creatPlayer(n);
}
private static void creatPlayer(int n) {
persons = new Person[n];
for (int i = 0; i < persons.length; i++) {
persons[i] = new Person();
}
for (int i = 0; i < n; i++) {
Scanner scanner = new Scanner(System.in);
int temp = 0;
temp = i + 1;
System.out.print("请输入第" + temp + "个玩家的姓名:");
persons[i].setName(scanner.next());
persons[i].setScore(SCORE_START);
}
try {
playGame();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
for (int i = 0; i < persons.length; i++) {
Scanner scanner = new Scanner(System.in);
System.out.print("请" + persons[i].getName() + "输入数值:");
persons[i].setNum(scanner.nextInt());
}
int numG = getG();
int recordMax = 0;
int max = Math.abs(persons[0].getNum() - numG);
for (int i = 0; i < persons.length; i++) {
if (max < (Math.abs(persons[i].getNum() - numG))) {
max = Math.abs(persons[i].getNum() - numG);
recordMax = i;
}
}
int min = Math.abs(persons[0].getNum() - numG);
int recordMin = 0;
for (int i = 0; i < persons.length; i++) {
if (min > Math.abs(persons[i].getNum() - numG))
{ min = Math.abs(persons[i].getNum() - numG); recordMin = i;
}
}
private static void showMessage() {
System.out.println();
System.out.println("姓名" + "\t" + "输入的数"+"\t"+"分数");
for (int i = 0; i < persons.length; i++) {
System.out.println(persons[i].getName() + "\t" + persons[i].getNum()+"\t"+persons[i].getScore());
}
System.out.println();
}
4.运行结果:
5.感受和体会: 学习使我快乐,我的组长学习特别认真,教我很多东西 1+1>2 在实训中学到了很多东西