| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 829 人关注过本帖
标题:比考试分数问题
只看楼主 加入收藏
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
结帖率:41.67%
收藏
 问题点数:0 回复次数:4 
比考试分数问题
要求是先要用户输入2个学生的名字, 然后输入每个学生的3个考试分数, 然后算出平均分, 再找出最高的一个分数(6个分数里的最高分), 最后还要显示出一个string显示学生名字和他的三个分数。
****************************************************************************************
//大概的结果应该像这样

学生1姓名:王X    分数: 100, 100, 100    平均分: 100
学生2姓名:李X    分数: 90, 90, 90          平均分: 90
最高分:100
****************************************************************************************
 
需要用7个methods来完成:

1.void setName(aString) //设置学生名字
2.String getName() //return学生的名字
3.void setScore (whichTest, testScore) //设置第3个考试为95(str=stu.setScore(3,95)), 如果whichTest不是1,2,3, 然后3自动代替
4.int getScore(whichTest) //return 分数
5.int getAverage() //return 3个考试的平均分数。
6.int getHighScore() //return 最高分
7.string toString() //return string 装有学生名字和3个考试分数

[[it] 本帖最后由 suckdog 于 2008-10-24 13:50 编辑 [/it]]
搜索更多相关主题的帖子: 分数 考试 
2008-10-24 13:47
hacker507
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2008-10-6
收藏
得分:0 
你是要我们给你做 还是给你们分析!!
2008-10-24 16:12
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
收藏
得分:0 
分析也可以, 最好写个例子出来, 因为我还不太懂java语言, 我用C++的方法做好像不行, 所以写出来最好, 逻辑我是懂得(因为逻辑是和C++一样),语言变成java我一窍不通了, 谢谢高手帮忙
2008-10-25 02:22
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
收藏
得分:0 
程式我写好了, 但是好像还跑不起来, 谁能帮我改一下, 最好是能改好后发个完整的上来, 因为光说有时候我还是搞不清楚, 谢谢各位帮忙了
public class Student
{
    public String name = "";
    public double test1;
    public double test2;
    public double test3;
    public double sum;
    public double average;
    public double highScore;
    public String statement = "";
    
    public void setName(String newName ) {
        name = newName;
    }
    public String getName() {
        return name;
    }
    public void setScore(int whichTest, double testScore) {
        //case statement for each test
        switch (whichTest){
            case 1: test1 = testScore; break;
            case 2: test2 = testScore; break;
            case 3: test3 = testScore; break;
        }
    }
    public double getAverage() {
        sum = test1 + test2 + test3;
        average = sum / 3.0;
        return average;
    }
    public double getHighScore() {
        if (test1 > test2 && test1 > test3){
            highScore = test1;
        }else if (test2 > test1 && test2 > test3) {
            highScore = test2;
        }else if (test3 > test1 && test3 > test2){
            highScore = test3;
        }
        return highScore;     
    }
    public String toString() {
        statement = "Name: " + name + "\nTest One: " + test1 + "\nTest Two: " + test2 + "\nTest Three: " + test3 + "\n";
        return statement;        
    }
}


class StudentDemo
{
     public static void main(String[] args) {
          Student stu1 = new Student(); //Creates student one,
          Student stu2 = new Student(); //Creates student two,
            
            stu1.setName("Mark Richter"); //Name for student one
            stu1.setScore(1, 90); //scores for student one
            stu1.setScore(2, 80);
            stu1.setScore(3, 85);
            
            stu2.setName("Bad Student"); //Name for student two
            stu2.setScore(1, 42); //scores for student two
            stu2.setScore(2, 61);
            stu2.setScore(3, 55);
            
            //System.out.print("Name: " + stu1.getName() + "\nAverage Score: " + stu1.getAverage() + "\nHigh Score: " + stu1.getHighScore());    
            
            System.out.print(stu1.toString() + "\n\n" + stu2.toString());
     }
}
2008-10-26 15:12
cqusnail
Rank: 1
等 级:新手上路
威 望:1
帖 子:50
专家分:0
注 册:2008-9-5
收藏
得分:0 
程序基本没有问题,我试了一下,我把 StudentDemo 类设为的 public 因为main 函数在StudentDemo类中

还有一点就是你的结果没有返回 最高分
2008-10-26 16:55
快速回复:比考试分数问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035035 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved