
正文
Java代码评分比赛 十个评委打分编程简单java
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Java里怎么写 这个代码 某次程序大赛,3 个班级各 4 名学员参赛,计算每个班参赛学员的平均分 谢谢!
package com.baidu.map;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class TestMap02 {
public static void main(String[] args) {
ListStudent list=new ArrayListStudent();
exam(list);
MapString, ClassRoom rooms=new HashMapString, ClassRoom();
count(rooms, list);
printScore(rooms);
}
/**
* 打印
*/
private static void printScore(MapString, ClassRoom rooms) {
SetMap.EntryString, ClassRoom entrySet=rooms.entrySet();
IteratorMap.EntryString, ClassRoom it=entrySet.iterator();
while(it.hasNext()){
Map.EntryString, ClassRoom entry=it.next();
ClassRoom room=entry.getValue();
System.out.println("班号:"+room.getNo()+"总成绩:"+room.getTotal()+"平均成绩:"+room.getTotal()/room.getStus().size());
}
}
/**
* 统计班级的分数
*/
public static void count(MapString, ClassRoom rooms,ListStudent list){
for (Student student : list) {
ClassRoom room=rooms.get(student.getNo());
if(null==room){
room=new ClassRoom(student.getNo());
rooms.put(student.getNo(), room);
}
room.setTotal(room.getTotal()+student.getScore());
room.getStus().add(student);
}
}
/**
* 数据源
*/
public static void exam(ListStudent list){
//可以使用循环遍历进去
list.add(new Student(80, "a", "001"));
list.add(new Student(80, "b", "001"));
list.add(new Student(80, "c", "001"));
list.add(new Student(80, "d", "001"));
list.add(new Student(80, "e", "002"));
list.add(new Student(80, "f", "002"));
list.add(new Student(80, "g", "002"));
list.add(new Student(80, "h", "002"));
list.add(new Student(80, "i", "003"));
list.add(new Student(80, "j", "003"));
list.add(new Student(80, "k", "003"));
list.add(new Student(83, "l", "003"));
}
}
package com.baidu.map;
public class Student {
private double score;
private String name;
private String no;
public Student() {
}
public Student(double score, String name, String no) {
super();
this.score = score;
this.name = name;
this.no = no;
}
@Override
public String toString() {
return "Student [score=" + score + ", name=" + name + ", no=" + no
+ "]";
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
}
package com.baidu.map;
import java.util.ArrayList;
import java.util.List;
public class ClassRoom {
private String no;
private double total;
private ListStudent stus;
public ClassRoom() {
stus=new ArrayListStudent();
}
public ClassRoom(String no) {
this();
this.no = no;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public ListStudent getStus() {
return stus;
}
public void setStus(ListStudent stus) {
this.stus = stus;
}
}
相关问答
Q1: 求JAVA评委打分代码
正好我闲着,给你写一个吧。
我写的这个评委分数是在代码里固定到数组里了,如果你需要运行时手动输入评分,可以将oldScores里的数据改成手动输入就行了(这个不用我再写了吧,如果不会再追问,再告诉你)。
你先新建一个类,将下面的main方法全部复制进去就能运行了,自己看一下吧。
/** 主方法 */
public static void main(String[] args)
{
/** 保存原始评分的数组(如果你需要运行时手动输入分数,将 oldScores中的数据改成手动输入就行了 */
double[] oldScores = {15, 77, 55, 88, 79, 98, 67, 89, 68, 88};
/** 最终将用来保存排序后的数组 */
double[] scores = new double[oldScores.length];
double temp;
/** 平均分 */
double avg = 0;
int k;
/** 将原始评分放入最终排序数组 */
for (int i = 0; i oldScores.length; i++)
{
scores[i] = oldScores[i];
}
/** 开始排序 */
for (int i = 0; i scores.length - 1; i++)
{
k = i;
for (int j = i + 1; j scores.length; j++)
{
if (scores[k] scores[j])
{
k = j;
}
}
if (i != k)
{
temp = scores[k];
scores[k] = scores[i];
scores[i] = temp;
}
}
/** 计算去掉最高分和最低分之后的和 */
double sum = 0;
/** 记录计算平均分的分数个数 */
double num = 0;
for (int i = 1; i scores.length - 1; i++)
{
num++;
sum += scores[i];
}
/** 计算平均分 */
avg = sum / num;
/** 最公平的肯定不是在scores数组两端 */
double zgp = 0;
double cha = 0;
/** 标记与平均值差值最小的分数位置 */
int flag = 0;
/** 开始寻找最公平评分 */
for (int i = 1; i scores.length - 1; i++)
{
/** 为cha赋初始值,注意比较差值要使用绝对值比较 */
if (i == 1)
{
cha = Math.abs(scores[i] - avg);
}
double cha1 = Math.abs(scores[i] - avg);
if (cha1 cha)
{
cha = cha1;
flag = i;
}
}
zgp = scores[flag];
/** 由于最不公平的分数肯定在scores数组的第一个或者是最后一个 */
double bgp = 0;
if (Math.abs(scores[0] - avg) Math.abs(scores[scores.length - 1] - avg))
{
bgp = scores[0];
}
else
{
bgp = scores[scores.length - 1];
}
/** 全部计算完成,下面开始输出结果 */
System.out.println("原始评委分数如下:");
for (int i = 0; i oldScores.length; i++)
{
System.out.print(oldScores[i] + ", ");
}
System.out.println();
System.out.println("排序后分数如下:");
for (int i = 0; i scores.length; i++)
{
System.out.print(scores[i] + ", ");
}
System.out.println();
System.out.println("去掉最高分和最低分后平均分:" + avg);
System.out.println("最公平分数:" + zgp);
System.out.println("最不公平分数:" + bgp);
}
Q2: 一个java歌唱比赛评分应用程序,急需,明晚上10点截至
每个歌手可以看成一个对象,这样就可以建一个歌手的类,添加一些属性和get,set方法 ,主程序可以将路人的对象保存起来,评委打分可以通过循环来对每个歌手进行打分,将打好的分保存起来,进行数据处理,存到一个数组或者链表中,查找时可以通过输入编号得到对应的选手,再通过选手得到对应的分数;排序得分就更简单了,使用排序算法就可以解决,什么冒泡,快速排序都行的。。。楼主代码还得自己敲
Q3: java编写歌曲比赛评分程序,评委给出8个成绩,去掉一个最高分,去掉一个最低分,剩余的求平均得到成绩。
import java.util.Scanner;
public class Grade {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double arr[] = new double[5];
for (int i = 0; i arr.length; i++) {
arr[i] = scan.nextDouble();
}
sort(arr);
average(arr);
}
public static void sort(double arr[]) {
for (int i = 0; i arr.length; i++) {
double max = arr[0];
for (int j = i; j arr.length; j++) {
if (arr[i] arr[j]) {
double temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
public static void average(double arr[]) {
double temp = 0, sum = 0;
for (int i = 1; i arr.length - 1; i++) {
sum += arr[i];
temp = sum / (arr.length - 2);
}
System.out.println(temp);
}
}
Java代码评分比赛的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于十个评委打分编程简单java、Java代码评分比赛的信息别忘了在本站进行查找喔。






