我用的是Eclipse
StudentApp.java
package model;import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
import java.util.Vector;public class StudentApp {

public static void main(String[] args)throws IOException{
Vector stuVector = new Vector();
InputStreamReader in= new InputStreamReader(System.in);
BufferedReader reader =new BufferedReader(in);

do{
Business.printMenu();
Business.switchMenu(Business.inputInt("choice:",reader),stuVector);
}while(true);
}
}
Student.java
package model;public class Student { private String stuNum;
private String name;
private int age;
private double result;

public void setStuNum(String stuNum){
this.stuNum=stuNum;
}
public String getStuNum(String stuNum){
return this.stuNum;
}
public void setName(String name){
this.name=name;
}
public String getName(String name){
return this.name;
}
public void setAge(int age){
this.age= age;
}
public int getAge(int age){
return this.age;
}
public void setResult(double result){
this.result=result;
}
public double getResult(double result){
return this.result;
}
public boolean hasSuchStudent(String stuNum){
return this.stuNum.equals(stuNum);
}
public void printStuInfor(){
System.out.println("学号:"+this.stuNum);
System.out.println("姓名:"+this.name);
System.out.println("年龄:"+this.age);
System.out.println("成绩:"+this.result);
}}
Business.java
package model;import java.io.IOException;
import  java.util.Vector;
import java.io.*;public class Business {
Vector stuVector=new Vector();
public static void switchMenu(int d,Vector stuVector) throws IOException{
switch(d){

case 1:
enterStudentResult(stuVector);
break;
case 2:
searchStuInfor(stuVector);
break;
case 3:
statisticAll(stuVector);
break;
case 4:
statisticAvg(stuVector);
break;
case 5:
exit();
    break;
  default:
  System.out.println("输入错误,请重试。");
}
}  


public static void printMenu(){
printLine();
System.out.println("\t======菜单======");
System.out.println("\t1:输入学生成绩");
System.out.println("\t2:查询学生成绩");
System.out.println("\t3:统计总成绩");
System.out.println("\t4:统计平均成绩");
System.out.println("\5:退出系统");
System.out.println("\n请输入您的选择");
}


public static void enterStudentResult(Vector stuVector)throws IOException{
printLine();
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(in);
String yesOrNo;
do{
            System.out.println("请输入学生基本信息");
Student student = new Student();
student.setStuNum(inputStuNum("学号",reader,stuVector));
student.setName(inputString("姓名",reader));
student.setAge(inputInt("年龄",reader));
student.setResult(inputDouble("成绩",reader));
stuVector.addElement(student);
System.out.println();
System.out.println("输入成功!按q终止输入。");
yesOrNo=reader.readLine();
}while(!yesOrNo.toLowerCase().equals("q"));
}


public static void searchStuInfor(Vector stuVector)throws IOException{
printLine();
InputStreamReader in =new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(in);
String yesOrNo;
boolean flag =false;
do{
System.out.println("查询成绩:请输入学号");
String stuNum=reader.readLine();
for(int i=0;i<stuVector.size();i++){
Student student =(Student)stuVector.elementAt(i);
if(student.hasSuchStudent(stuNum)){
student.printStuInfor();
flag=true;
break;
}
}
if(flag==false)
System.out.println("对不起,没有您要的学生成绩信息,");
System.out.println("继续查询吗?按q终止.");
yesOrNo=reader.readLine();
}while(!yesOrNo.toLowerCase().equals("q"));
}


public static String inputStuNum(String prompt,BufferedReader reader,Vector stuVector){
String ret="";
do{
try{
ret=inputStream(prompt,reader);
if(!stuNoUnique(stuVector,ret))
throw new Exception();
return ret;
}catch(Exception e){
System.out.println("您输入的学号"+ret+"已经存在,请重试");
continue;
}
}while(true);
}


public static String inputString(String prompt,BufferedReader reader){
String ret;
do{
try{
System.out.print(prompt);
ret=reader.readLine();
if(ret.trim().length()==0)
throw new Exception();
return ret;
}catch(Exception e){
System.out.println("您还没有输入字符。请重试");
continue;
}
}while(true);
}

public static int inputInt(String prompt,BufferedReader reader){
int ret =0;
do{
try{
System.out.print(prompt);
ret=Integer.parseInt(reader.readLine());
return ret;
}catch(Exception e){
System.out.println("您输入的不是整数,请重试");
continue;
}
}while(true);
}



public static String inputStream(String prompt,BufferedReader reader){
String ret;
do{
try{
System.out.println(prompt);
ret=reader.readLine();
if(ret.trim().length()==0)
throw new Exception();
return ret;
}catch(Exception e){
System.out.println("您还没有输入字符,请重试");
continue;
}
}while(true);
}


public static boolean stuNoUnique(Vector stuVector,String stuNum)throws IOException{
for(int i=0;i<stuVector.size();i++){
Student student = (Student)stuVector.elementAt(i);
if(student.hasSuchStudent(stuNum)){
return false;
}
}
return true;
}

public static void statisticAll(Vector stuVector){
printLine();
System.out.println("正在统计总成绩......");
System.out.println("您总共输入了"+stuVector.size()+"个学生成绩信息,总成绩信息是");
double result=0;
for(int i=0;i<stuVector.size();i++){
result+=((Student)stuVector.elementAt(i)).getResult(result);

}System.out.println(result);
}

public static void statisticAvg(Vector stuVector){
printLine();
System.out.println("正在统计平均成绩......");
System.out.println("您总共输入了"+stuVector.size()+"个学生成绩信息,平均成绩是");
double result=0;
for(int i=0;i<stuVector.size();i++){
result+=((Student)stuVector.elementAt(i)).getResult(result);

}System.out.print(result/stuVector.size());
}


public static double inputDouble(String prompt,BufferedReader reader){
double ret =0;
do{
try{
System.out.print(prompt);
ret=Double.parseDouble(reader.readLine());
return ret;
}catch(Exception e){
System.out.println("您输入的不是数字,请重试");
continue;
}
}while(true);
}


public static void printLine(){
System.out.println("======================学生成绩管理系统======================");
}

public static void exit(){
System.out.println("谢谢您的使用,再见");
System.exit(0);
}
}

解决方案 »

  1.   

    补充: 类型安全:方法 addElement 属于原始类型Vector,应该将对通用类型Vector<e>的引用参数化java.lang.NoClassDefFoundError: model/StudentApp
      

  2.   

    1、方法 addElement 属于原始类型Vector,应该将对通用类型Vector<e>的引用参数化
     这个是没使用泛型的编译警告吧?2、java.lang.NoClassDefFoundError: model/StudentApp 是找不到你的类
      

  3.   

    第一个没事不用管它
    第二个已经写的很清楚了NoClassDefFoundError应该没有一个生词吧?