报课、招生咨询电话:010-51268840/41

首页 > 计算机考试 > 试题汇编 > JAVA考试 > 试题 >
→论坛登陆 用户名  密码  
剑桥大学java期末考试题一份

作者: 发布时间:2008-07-16 17:09:41 来源:育路计算机考试

Write a simple Java program. This program is to record marks for a maximum of 10 people. Your program is to prompt the user for a person’s name and the mark that they got. After this it should ask if the user wants to enter another mark and if they do ask for and store another. It should continue to do this till the user answers no to entering another mark.

Once this happens it should print out all the names and marks. It should also specify the min and max marks and who achieved them. It should also print out the average mark.

Finish in1 hour and half.

翻译:

编辑一个简单的程序,本程序用于记录最多10个人的成绩。要求列出每个人的名子和成绩,之后系统提示是否继续纪录:Continue Yes/No. Yes:填写下一个人的名子和成绩, No: 列出已出入的全部名子和成绩。

当输入十人之后,程序结束,列出已出入十人的名子与成绩,最大值,最小值,平均值。

限时:90分钟

本人程序:
//程序名称: MainClass.java
import java.util.*;
import java.io.*;

class ManageCenter{
private static List list = new ArrayList();
public void addStudent(Student student){
List.add(student);
}
public static int getListSize(){
return list.size();
}
public void printScore(){
System.out.println("==================================");
for(int i=0;i<list.size();i++){
System.out.println((Student)list.get(i));
System.out.println("------------------------------");
}
System.out.println("==================================");
}
public int computeMaxScore(){
int []scoreCopy = sort(getScoresList());
return scoreCopy[sort(getScoresList()).length-1];
}
public int computeMinScore(){
int []scoreCopy = sort(getScoresList());
return scoreCopy[0];
}
public int computeAverSco(){
int sumScore = 0;
int []scoreCopy = sort(getScoresList());
for(int j=0;j<scoreCopy.length;j++){
sumScore+=scoreCopy[j];
}
return sumScore/scoreCopy.length;
}
private static int[] sort(int []score){
for(int i=score.length;i>1;i--){
for(int j=0;j<score.length-1;j++){
if(score[j+1]<score[j]){
int temp = score[j+1];
score[j+1] = score[j];
score[j] = temp;
}
}
}
return score;
}
private static int [] getScoresList(){
int []score = new int[list.size()];
for(int i=0;i<list.size();i++){
Student student = (Student)list.get(i);
score [i] =student.getScore();
}
return score;
}
public void printMaxScore(){
System.out.println("最高的成绩为: "+computeMaxScore());
}
public void printMinScore(){
System.out.println("最低的成绩为: "+computeMinScore());
}
public void printAverSco(){
System.out.println("平均成绩为: "+computeAverSco());
}
}
class Student{
private String name;
private int score;
public Student(){}
public Student(String name,int score){
this.name = name;
this.score = score;
}
public void setScore(int score){
this.score = score;
}
public int getScore(){
return this.score;
}
public String toString(){
return "Name: "+this.name+" Score: "+this.score;
}
}

public class MainClass{
public static void main(String args[])throws IOException{
ManageCenter manageCenter = new ManageCenter();
System.out.println("===================================");
System.out.println("请输入学生的姓名和成绩:格式如下所示:");
System.out.println("姓名,成绩(注意:限定格式,测试输入姓名为英文如:CoffeeCat,85)");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<10;i++){
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
int ind = s.indexOf(´,´);
System.out.println(ind);
Student student = new Student(s.substring(0,ind),new Integer(s.substring(ind+1)).intValue());
manageCenter.addStudent(student);
//manageCenter.printScore();
showMessage();
String str;
if((str=read.readLine())=="no"&&manageCenter.getListSize()<10){
manageCenter.printScore();
System.exit(0);
}
}
manageCenter.printScore();
manageCenter.printMaxScore();
manageCenter.printMinScore();
manageCenter.printAverSco();
}
private static void showMessage(){
System.out.println("是否继续输入记录?(answer yes/no)");
}
}

    育路网

 
 
                                        
评论】【加入收藏夹】【 】【打印】【关闭
育路网2007年夏令营联展
 更多有关新闻:
 
·[考试动态2008年医师资格考试网上报名须知 ·[考试动态2008年医师资格考试3月10日开始网
·[考试动态卫生部医师资格考试委员会公告 ·[考试动态2008年医师考试于9月20至21进行
·[考试动态关于北京考区2008年度国家医师资 ·[考试动态崇文区卫生局关于北京考区2008年
·[考试动态丰台区卫生局关于北京考区2008年 ·[考试动态2008年上海市医师资格考试(考区
·[考试动态2008年医师资格考试(天津考区) ·[考试动态惠州市卫生局关于2008医师资格考
·[考试动态无锡市关于2008年医师资格考试网 ·[考试动态关于珠海市2008年医师资格考试的
·[考试动态韶关市关于2008年医师资格考试网 ·[考试动态深圳市关于2008年医师资格考试深
·[考试动态杭州市卫生局关于2008年医师资格 ·[考试动态丽水市关于2008年医师资格考试报
发表评论
用户名: 密码:
验证码: 匿名发表
课程搜索:
选择分类:
课程关键字:
课程 学校
 2008年首都高校秋季招生
北京理工大学2008年招生简章
北京文理研修学院2008年招生简章
北京建设大学2008年招生简章
北京中山学院2008年招生简章
北京城市学院2008年招生简章
培黎职业学院2008年招生简章
北京金融学院2008年招生简章
北京吉利大学2008年招生简章
北方工商管理学院2008年招生简章
 本周推荐课程
·初中起点雅思半年脱产 ·启德雅思6分冲刺课程
·新概念1+2册慢速精讲课 ·环球新托福100分强化
·北文王长喜四级强化班 ·英语四、六级培训课程
·海文考研数学课程 ·海文考研英语课程
·北大企业管理高级研修班 ·清华企业领导人研修班
·中美高中生交换项目 ·北工大中加学院2+2本科
·劳动和社会保障部物流师 ·物业管理师职业培训
·市场营销经理国际资格 ·现场管理实务培训
清华大学留学
中法管理硕士预科班
课程咨询热线:010-51268840 51268841
 最新新闻
·学习潘作良先进事迹 争做党和人民满意公务员
·08三地市优秀村干部考录公务员拟录用人员名单
·陕西地方税务局08考录公务员面试成绩及体检通
·民航华北局对2008年新入公务员开班培训
·报考2008年咸阳市政府口公务员体检人员体检通
·广东社科院报告建议大幅提高公务员等工资水平
·公务员涨工资不能老向高处看
·重庆基层政法机关定向招录203公务员
·重庆本月启动教师医生公务员重点人群吸烟监测
· “名师”经典面试点评
 育路社区            进入>>
 
学员报名服务中心: 北京北三环西路32号恒润中心1806(交通位置图
咨询电话:北京- 010-51268840/41 传真:010-51418040 上海-021-64392659、64397431
育路网-中国新锐教育社区: 北京站 | 上海站 | 郑州站| 武汉站
本站法律顾问: 邱清荣律师
北京育路互联科技有限公司版权所有 | 京ICP备05012189号