选秀节目打分

选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分  * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。

            函数接口   int cal_score(int score[], int judge_type[], int n) 


package com.campu; /** * @author 码农小江 * H20120906.java * 2012-9-30下午3:40:18 */ public class H20120906 { /** * 函数接口功能 * @param score[] 数组里存储每个评委的打分 * @param judge_tye[] 存储与score[]数组对应的评委类型 i=1 专家评委 i=2大众评委 * @param n 评委总数 * @return 返回选手得分 * 总分:专家评委平均分*0.6+大众评委*0.4 总分取整 */ public static int cal_score(int score[],int judge_type[],int n){ int exportNumber = 0; int exportAverageScore = 0; int audioAverageScore = 0; int endResult; double exportValue = 0; double audioValue = 0; for(int i=0; i<judge_type.length;i++){ if(judge_type[i] == 1){ exportValue = exportValue + score[i]; exportNumber = exportNumber + 1; }else{ audioValue = audioValue +score[i]; } } audioAverageScore = averageValue(audioValue, judge_type.length - exportNumber); exportAverageScore = averageValue(exportValue, exportNumber); endResult = (int) Math.rint(0.6* exportAverageScore + 0.4 * audioAverageScore); return endResult; } /** * 把专家评分和观众评分的平均分功能抽象出来封装成一个方法 * @param sum :评分总和 * @param n:评委数量 * @return:平均分 :采用四舍五入取整方法 */ public static int averageValue(double sum, int n){ double temp = (sum/n); int result = (int) Math.rint(temp);//四舍五入取整 return (int)result; } public static void main(String args[]){ int score[] = {90,100,23,78}; int judge_tye[]={1,2,2,1}; int n; n = score.length; if(score.length != judge_tye.length){ System.out.println("数据不匹配:分数个数必须等于评委个数,请重新输入"); return; } for(int i=0; i<score.length; i++){ if(score[i]<0 || score[i]>100){ System.out.println("错误:分数必须是0-100之间,请重新输入"); return; } if((judge_tye[i]<1) || (judge_tye[i] >2) ){ System.out.println("错误:评委类型只能是1或者2,请重新输入"); return; } } System.out.print(cal_score(score, judge_tye, n)); } }

 

选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 专家评委平均分  * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 专家评委平均分,总分取整。函数最终返回选手得分。

            函数接口   int cal_score(int score[], int judge_type[], int n) 

 

 

 

posted @ 2012-09-30 21:27  码农小江  阅读(1677)  评论(0编辑  收藏  举报