当前位置: 代码迷 >> J2SE >> 学生管理程序,该如何处理
  详细解决方案

学生管理程序,该如何处理

热度:65   发布时间:2016-04-24 13:19:03.0
学生管理程序
辛苦大家帮我写一个学生管理程序,是这样的: 有成绩 98、79、 67、 90、 88、 64、 53、 97 不要求有图形界面,在Editplus里面能运行就可以,当我输入1时 显示平均成绩 当输入2时显示总和。多谢!

------解决方案--------------------
多少钱?

你以为每个人都很闲吗?
------解决方案--------------------
就是啊,哪有这么多闲人
------解决方案--------------------
Java code
大哥,不会吧,这样的问题也要求人。。。。。。import java.io.*;class NotValidNumException extends Exception{}public class Score{   public static int getChoose()              throws IoException,NumberNotFormatException,NotValidNumException{      InputStreamReader ir = new InputStreamReader(System.in);      BufferedReader br = new BufferedReader(ir);      int i = 0;      i = Integer.parseInt(br.readLine());      if(i != 1 || i != 2){         throw new NotValidNumException();      }      return i;   }      public static int getArraySum(int[] num){      int sum = 0;      for(int i = 0 ; i < num.length ; i++ ){         sum += num[i];      }      return sum;   }      public static int getArrayAvg(int[] num){      int sum = Score.getArraySum(num);      int avg = sum/num.length;      return avg;   }   public static void main(String[] args){      int[] num = {98,79,67,90,88,64,53,97};      boolean flag = true;      Integer choose = null;      while(flag){          System.out.println("please input your choose:");          try{             choose = Score.getChoose();          }catch(NumberNotFormatException e){             System.out.println("the inputed number is error!please input again!");             continue;          }catch(NotValidNumException ee){             System.out.println("the inputed number is invalid number!"                        + "please input again!");             continue;          }catch(IOException eee){             System.out.println(eee.getMessage());             continue;          }          flag = false;       }       if(choose == 1){          System.out.println("These number's Avg :  " + getArrayAvg);       }       if(choose == 2){          System.out.println("These number's Sum :  " + getArraySum);       }   }}
------解决方案--------------------
呵呵,按楼主的要求,应该不用写的这么麻烦吧~~
------解决方案--------------------
if(choose == 1){
System.out.println("These number's Avg : " + getArrayAvg);
}
if(choose == 2){
System.out.println("These number's Sum : " + getArraySum);
}
红色部分编绎能过么???

------解决方案--------------------
上面楼主写的不错啊,
public static float getAverage(float[] temp) {
float tempV = 0;
int m = 0;
for (int i = 0; i < temp.length; i++) {
tempV += temp[i];
m++;
}

return tempV / m;
}

public static float getSum(float[] temp) {
float tempV = 0;
for (int i = 0; i < temp.length; i++) {
tempV += temp[i];
}
return tempV;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
float[] temp = { 89, 97, 23, 47, 86, 80, 32, 128 };
while(true){
System.out.println("start");
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(input);
char tempCharater = (char) br.read();
System.out.println(tempCharater);

if (tempCharater == '1') {
System.out.println("成绩的平均数:");
System.out.println(getAverage(temp));
} else if (tempCharater == '2') {
System.out.println("成绩的总和:");
  相关解决方案