一个初学者,请大侠们给出这个题目的完整程序(急) 不可能是毕业设计 作业还差不多 HOHO 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没写全,自己补import java.io.*;import java.math.*;import java.util.*;public class StudentDemo{ public static int sID = 0; public static void main(String[] argu) { Vector studentVect = new Vector(); boolean isFinished = false; BufferedReader in = null; String sMathScore = null; String sLangScore = null; String sPoliticsScore = null; String sComputerScore = null; String toNext = null; System.out.println("------学生信息登记程序-----"); try { while(true) { Student student = new Student(); sID = student.getStudentID(); student.setStudentID(sID); System.out.print("**请输入"+student.getStudentID()+"号学生的信息"); System.out.print("\n数学成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sMathScore = in.readLine(); System.out.print("\n英语成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sLangScore = in.readLine(); System.out.print("\n政治课成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sPoliticsScore = in.readLine(); System.out.print("\n计算机成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sComputerScore = in.readLine(); while(!isFinished) { student.setMathScore(Float.parseFloat(sMathScore)); student.setLangScore(Float.parseFloat(sLangScore)); student.setPoliticsScore(Float.parseFloat(sPoliticsScore)); student.setComputerScore(Float.parseFloat(sComputerScore)); studentVect.addElement(student); isFinished = true; } isFinished = false; for(int i = 0; i<studentVect.size(); i++) { System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore())); System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore())); System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore())); System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore())); } System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)"); in = new BufferedReader(new InputStreamReader(System.in)); if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N"))) { break; } } } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } private int getStudentID() { int maxStudentID = StudentDemo.sID + 1; return maxStudentID; }}class Student{ private int studentID = 0; private float mathScore = 0.0f; private float langScore = 0.0f; private float politicsScore = 0.0f; private float computerScore = 0.0f; //获得数学课分数 public float getMathScore() { return mathScore; } void setMathScore(float mathScore) { this.mathScore = mathScore; } //获得英语课的分数 public float getLangScore() { return langScore; } void setLangScore(float langScore) { this.langScore = langScore; } //获得政治课分数 public float getPoliticsScore() { return politicsScore; } void setPoliticsScore(float politicsScore) { this.politicsScore = politicsScore; } //获得计算机分数 public float getComputerScore() { return computerScore; } void setComputerScore(float computerScore) { this.computerScore = computerScore; } //获得各课分数总和 public float getTotalScore() { return mathScore + langScore + politicsScore + computerScore; } //获得学号 public void setStudentID(int studentID) { this.studentID = studentID; } public int getStudentID() { return studentID; }} 上边的代码,对单个学生的学号未能正确赋值,下面已改import java.io.*;import java.math.*;import java.util.*;public class StudentDemo{ public static int sID = 0; public static void main(String[] argu) { Vector studentVect = new Vector(); boolean isFinished = false; BufferedReader in = null; String sMathScore = null; String sLangScore = null; String sPoliticsScore = null; String sComputerScore = null; String toNext = null; System.out.println("------学生信息登记程序-----"); try { while(true) { Student student = new Student(); sID = StudentDemo.getStudentID(); student.setStudentID(sID); System.out.print("**请输入"+student.getStudentID()+"号学生的信息"); System.out.print("\n数学成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sMathScore = in.readLine(); System.out.print("\n英语成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sLangScore = in.readLine(); System.out.print("\n政治课成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sPoliticsScore = in.readLine(); System.out.print("\n计算机成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sComputerScore = in.readLine(); //给学生的各课成绩赋值 student.setMathScore(Float.parseFloat(sMathScore)); student.setLangScore(Float.parseFloat(sLangScore)); student.setPoliticsScore(Float.parseFloat(sPoliticsScore)); student.setComputerScore(Float.parseFloat(sComputerScore)); studentVect.addElement(student); System.out.print("\n"); //显示每个学生的各课成绩 for(int i = 0; i<studentVect.size(); i++) { System.out.println("** "+(((Student)(studentVect.elementAt(i))).getStudentID())+"号学生的成绩 ** "); System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore())); System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore())); System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore())); System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore())); System.out.print("\n"); } //询问是否要继续输入 System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)"); in = new BufferedReader(new InputStreamReader(System.in)); if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N"))) { break; } } } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } private static int getStudentID() { int maxStudentID = StudentDemo.sID + 1; return maxStudentID; }}class Student{ private int studentID = 0; private float mathScore = 0.0f; private float langScore = 0.0f; private float politicsScore = 0.0f; private float computerScore = 0.0f; //获得数学课分数 public float getMathScore() { return mathScore; } void setMathScore(float mathScore) { this.mathScore = mathScore; } //获得英语课的分数 public float getLangScore() { return langScore; } void setLangScore(float langScore) { this.langScore = langScore; } //获得政治课分数 public float getPoliticsScore() { return politicsScore; } void setPoliticsScore(float politicsScore) { this.politicsScore = politicsScore; } //获得计算机分数 public float getComputerScore() { return computerScore; } void setComputerScore(float computerScore) { this.computerScore = computerScore; } //获得各课分数总和 public float getTotalScore() { return mathScore + langScore + politicsScore + computerScore; } //获得学号 public void setStudentID(int studentID) { this.studentID = studentID; } public int getStudentID() { return studentID; }} 加入了排序后的代码:import java.io.*;import java.math.*;import java.util.*;public class StudentDemo{ public static int sID = 0; public static void main(String[] argu) { Vector studentVect = new Vector(); boolean isFinished = false; BufferedReader in = null; String sMathScore = null; String sLangScore = null; String sPoliticsScore = null; String sComputerScore = null; String toNext = null; System.out.println("------学生信息登记程序-----"); try { while(true) { Student student = new Student(); sID = StudentDemo.getStudentID(); student.setStudentID(sID); System.out.print("**请输入"+student.getStudentID()+"号学生的信息"); System.out.print("\n数学成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sMathScore = in.readLine(); System.out.print("\n英语成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sLangScore = in.readLine(); System.out.print("\n政治课成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sPoliticsScore = in.readLine(); System.out.print("\n计算机成绩:"); in = new BufferedReader(new InputStreamReader(System.in)); sComputerScore = in.readLine(); //给学生的各课成绩赋值 student.setMathScore(Float.parseFloat(sMathScore)); student.setLangScore(Float.parseFloat(sLangScore)); student.setPoliticsScore(Float.parseFloat(sPoliticsScore)); student.setComputerScore(Float.parseFloat(sComputerScore)); studentVect.addElement(student); System.out.print("\n"); //显示每个学生的各课成绩 printScore(studentVect); //询问是否要继续输入 System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)"); in = new BufferedReader(new InputStreamReader(System.in)); if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N"))) { //冒泡排序方法 sortProcedure(studentVect); //显示排序后每个学生的各课成绩 System.out.println("-----按总分从高到低输出显示每个学生的所有信息------"); printScore(studentVect); break; } } } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } private static int getStudentID() { int maxStudentID = StudentDemo.sID + 1; return maxStudentID; } private static void printScore(Vector studentVect)//打印每个同学的分数 { for(int i = 0; i<studentVect.size(); i++) { System.out.println("** "+(((Student)(studentVect.elementAt(i))).getStudentID())+"号学生的成绩 ** "); System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore())); System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore())); System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore())); System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore())); System.out.println("总分: "+(((Student)(studentVect.elementAt(i))).getTotalScore())); System.out.print("\n"); } } private static void sortProcedure(Vector studentVect)//冒泡排序方法 { Student temp; for(int pass=0;pass<studentVect.size();pass++)//扫描多次 { for(int i=0;i<studentVect.size()-pass-1;i++)//一次扫描过程 { float f1=((Student)studentVect.elementAt(i)).getTotalScore(); float f2=((Student)studentVect.elementAt(i+1)).getTotalScore(); if(f1<f2) { temp=(Student)studentVect.elementAt(i); studentVect.setElementAt((Student)studentVect.elementAt(i+1),i); studentVect.setElementAt(temp,i+1); } } } }}class Student{ private int studentID = 0; private float mathScore = 0.0f; private float langScore = 0.0f; private float politicsScore = 0.0f; private float computerScore = 0.0f; //获得数学课分数 public float getMathScore() { return mathScore; } void setMathScore(float mathScore) { this.mathScore = mathScore; } //获得英语课的分数 public float getLangScore() { return langScore; } void setLangScore(float langScore) { this.langScore = langScore; } //获得政治课分数 public float getPoliticsScore() { return politicsScore; } void setPoliticsScore(float politicsScore) { this.politicsScore = politicsScore; } //获得计算机分数 public float getComputerScore() { return computerScore; } void setComputerScore(float computerScore) { this.computerScore = computerScore; } //获得各课分数总和 public float getTotalScore() { return mathScore + langScore + politicsScore + computerScore; } //获得学号 public void setStudentID(int studentID) { this.studentID = studentID; } public int getStudentID() { return studentID; }} 程序入口处:public class manager extends JFrame{ private JMenuBar menubar ; private JMenu file,edit,about,salary,search; private JMenuItem New,Add,Remove,disp,addsalary,dispsalary,searcher; Container c; private Student input; private disp display; public JDesktopPane desktop = new JDesktopPane(); public manager(){ super(" MANAGER SYSTEM"); setJMenuBar(menubar=new JMenuBar()); c=getContentPane(); c.add(desktop); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); menubar.add(file=new JMenu("File")); menubar.add(edit=new JMenu("Edit")); menubar.add(search=new JMenu("Disp")); file.add(New=new JMenuItem("Exit")); edit.add(Add=new JMenuItem("Add")); search.add(searcher=new JMenuItem("Disp")); Add.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Thread runner = new Thread() { public void run() { input = new Student(); desktop.add(input); } }; runner.start(); } });searcher.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Thread runner = new Thread() { public void run() { display = new disp(); desktop.add(display); } }; runner.start(); } }); New.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ dispose(); System.exit(0); } }); setSize(800,550); setVisible(true); } public static void main(String args[]){ new thread().start(); }} import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Student extends JInternalFrame{ private JLabel title,name,studentid,math,english,politic,computer; private JButton jok,jcancel; private JTextField [] jt=new JTextField[6]; private JPanel jnorth,jcenter,jsouth; private Container c; public JDesktopPane desktop=new JDesktopPane(); private toDateBase toDate; private String [] data=new String [6]; private int sum=0; public boolean isok(){ for(int j=0;j<jt.length;j++){ if(!jt[j].getText().equals("")){ data[j]=jt[j].getText(); if(j>=2){ sum+=Integer.parseInt(data[j]); } } else return true; } return true; } public Student(){ c=getContentPane(); c.add(desktop); title=new JLabel("PLEASE INPUT STUDENTS INFORMATION"); name=new JLabel("NAME"); studentid=new JLabel("ID"); math=new JLabel("MATH"); english=new JLabel("ENGLISH"); politic=new JLabel("POLITIC"); computer=new JLabel("COMPUTER"); jnorth=new JPanel(); jcenter=new JPanel(); jsouth=new JPanel(); jok=new JButton("OK"); jcancel=new JButton("CANCEL"); GridLayout gl=new GridLayout(6,2,1,1); jcenter.setLayout(gl); for(int i=0;i<jt.length;i++){ jt[i]=new JTextField(10); } c.add(title,BorderLayout.NORTH); jcenter.add(name); jcenter.add(jt[0]); jcenter.add(studentid); jcenter.add(jt[1]); jcenter.add(math); jcenter.add(jt[2]); jcenter.add(english); jcenter.add(jt[3]); jcenter.add(politic); jcenter.add(jt[4]); jcenter.add(computer); jcenter.add(jt[5]); c.add(jcenter,BorderLayout.CENTER); jsouth.add(jok); jsouth.add(jcancel); c.add(jsouth,BorderLayout.SOUTH); setSize(400,300); setVisible(true); jok.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(isok()){ Thread runner= new Thread(){ public void run(){ toDate=new toDateBase(); toDate.update("INSERT INTO student(name,studentid,math,english,politic,computer,sum)values('"+data[0]+"','"+data[1]+"','"+data[2]+"','"+data[3]+"','"+data[4]+"','"+data[5]+"','"+sum+"')"); for(int i = 0; i < jt.length; i++) jt[i].setText(null); } }; runner.start(); } } }); jcancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ea){ dispose(); } }); }public static void main(String args[]){ Student app=new Student(); }} import java.sql.*; public class toDateBase { private Connection connection = null; private Statement statement = null; private ResultSet resultset = null; public boolean isDouble(String query) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException ea) { System.out.println(ea.toString()); } catch(Exception e) { System.out.println(e.toString()); } try { connection = DriverManager.getConnection("jdbc:odbc:student"); statement = connection.createStatement(); resultset = statement.executeQuery(query); while(resultset.next()) { return true; } resultset.close(); statement.close(); connection.close(); } catch(SQLException SQLe) { System.out.println(SQLe.toString()); } return false; } public void update(String query) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException ea) { System.out.println(ea.toString()); } catch(Exception e) { System.out.println(e.toString()); } try { connection = DriverManager.getConnection("jdbc:odbc:student"); statement = connection.createStatement(); statement.executeUpdate(query); statement.close(); connection.close(); } catch(SQLException SQLe) { System.out.println(SQLe.toString()); } } } JAVA SOCKET编成的问题 JAVA 输出中文,结果全是问号 如何求 4个List 的 交集?写查询用 如何用JAVA提取文本中的某些数据? 如何使用JMF来播放MP3文件 主程序如何知道子線程的運行狀態 .. java开发Windows桌面应用软件 请问在java中有没有一个用来显示字符串用的二维表的类呀,象JTable一样,不过要带滚动条的. 如何用java程序实现keytool的功能? 在win2000下java的设置 method parseInt 的问题 关于接口、抽像类在使用上的疑问
import java.math.*;
import java.util.*;public class StudentDemo
{
public static int sID = 0;
public static void main(String[] argu)
{
Vector studentVect = new Vector();
boolean isFinished = false;
BufferedReader in = null;
String sMathScore = null;
String sLangScore = null;
String sPoliticsScore = null;
String sComputerScore = null;
String toNext = null;
System.out.println("------学生信息登记程序-----");
try
{
while(true)
{
Student student = new Student();
sID = student.getStudentID();
student.setStudentID(sID);
System.out.print("**请输入"+student.getStudentID()+"号学生的信息");
System.out.print("\n数学成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sMathScore = in.readLine();
System.out.print("\n英语成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sLangScore = in.readLine();
System.out.print("\n政治课成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sPoliticsScore = in.readLine();
System.out.print("\n计算机成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sComputerScore = in.readLine();
while(!isFinished)
{
student.setMathScore(Float.parseFloat(sMathScore));
student.setLangScore(Float.parseFloat(sLangScore));
student.setPoliticsScore(Float.parseFloat(sPoliticsScore));
student.setComputerScore(Float.parseFloat(sComputerScore));
studentVect.addElement(student);
isFinished = true;
}
isFinished = false;
for(int i = 0; i<studentVect.size(); i++)
{
System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore()));
System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore()));
System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore()));
System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore()));
} System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)");
in = new BufferedReader(new InputStreamReader(System.in));
if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N")))
{
break;
}
}
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
private int getStudentID()
{
int maxStudentID = StudentDemo.sID + 1;
return maxStudentID;
}
}class Student
{
private int studentID = 0;
private float mathScore = 0.0f;
private float langScore = 0.0f;
private float politicsScore = 0.0f;
private float computerScore = 0.0f;
//获得数学课分数
public float getMathScore()
{
return mathScore;
}
void setMathScore(float mathScore)
{
this.mathScore = mathScore;
}
//获得英语课的分数
public float getLangScore()
{
return langScore;
}
void setLangScore(float langScore)
{
this.langScore = langScore;
}
//获得政治课分数
public float getPoliticsScore()
{
return politicsScore;
}
void setPoliticsScore(float politicsScore)
{
this.politicsScore = politicsScore;
}
//获得计算机分数
public float getComputerScore()
{
return computerScore;
}
void setComputerScore(float computerScore)
{
this.computerScore = computerScore;
}
//获得各课分数总和
public float getTotalScore()
{
return mathScore + langScore + politicsScore + computerScore;
}
//获得学号
public void setStudentID(int studentID)
{
this.studentID = studentID;
}
public int getStudentID()
{
return studentID;
}
}
import java.math.*;
import java.util.*;public class StudentDemo
{
public static int sID = 0;
public static void main(String[] argu)
{
Vector studentVect = new Vector();
boolean isFinished = false;
BufferedReader in = null;
String sMathScore = null;
String sLangScore = null;
String sPoliticsScore = null;
String sComputerScore = null;
String toNext = null;
System.out.println("------学生信息登记程序-----");
try
{
while(true)
{
Student student = new Student();
sID = StudentDemo.getStudentID();
student.setStudentID(sID);
System.out.print("**请输入"+student.getStudentID()+"号学生的信息");
System.out.print("\n数学成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sMathScore = in.readLine();
System.out.print("\n英语成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sLangScore = in.readLine();
System.out.print("\n政治课成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sPoliticsScore = in.readLine();
System.out.print("\n计算机成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sComputerScore = in.readLine();
//给学生的各课成绩赋值
student.setMathScore(Float.parseFloat(sMathScore));
student.setLangScore(Float.parseFloat(sLangScore));
student.setPoliticsScore(Float.parseFloat(sPoliticsScore));
student.setComputerScore(Float.parseFloat(sComputerScore));
studentVect.addElement(student); System.out.print("\n");
//显示每个学生的各课成绩
for(int i = 0; i<studentVect.size(); i++)
{
System.out.println("** "+(((Student)(studentVect.elementAt(i))).getStudentID())+"号学生的成绩 ** ");
System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore()));
System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore()));
System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore()));
System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore()));
System.out.print("\n");
} //询问是否要继续输入
System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)");
in = new BufferedReader(new InputStreamReader(System.in));
if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N")))
{
break;
}
}
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
private static int getStudentID()
{
int maxStudentID = StudentDemo.sID + 1;
return maxStudentID;
}
}class Student
{
private int studentID = 0;
private float mathScore = 0.0f;
private float langScore = 0.0f;
private float politicsScore = 0.0f;
private float computerScore = 0.0f;
//获得数学课分数
public float getMathScore()
{
return mathScore;
}
void setMathScore(float mathScore)
{
this.mathScore = mathScore;
}
//获得英语课的分数
public float getLangScore()
{
return langScore;
}
void setLangScore(float langScore)
{
this.langScore = langScore;
}
//获得政治课分数
public float getPoliticsScore()
{
return politicsScore;
}
void setPoliticsScore(float politicsScore)
{
this.politicsScore = politicsScore;
}
//获得计算机分数
public float getComputerScore()
{
return computerScore;
}
void setComputerScore(float computerScore)
{
this.computerScore = computerScore;
}
//获得各课分数总和
public float getTotalScore()
{
return mathScore + langScore + politicsScore + computerScore;
}
//获得学号
public void setStudentID(int studentID)
{
this.studentID = studentID;
}
public int getStudentID()
{
return studentID;
}
}
import java.io.*;
import java.math.*;
import java.util.*;public class StudentDemo
{
public static int sID = 0;
public static void main(String[] argu)
{
Vector studentVect = new Vector();
boolean isFinished = false;
BufferedReader in = null;
String sMathScore = null;
String sLangScore = null;
String sPoliticsScore = null;
String sComputerScore = null;
String toNext = null;
System.out.println("------学生信息登记程序-----");
try
{
while(true)
{
Student student = new Student();
sID = StudentDemo.getStudentID();
student.setStudentID(sID);
System.out.print("**请输入"+student.getStudentID()+"号学生的信息");
System.out.print("\n数学成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sMathScore = in.readLine();
System.out.print("\n英语成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sLangScore = in.readLine();
System.out.print("\n政治课成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sPoliticsScore = in.readLine();
System.out.print("\n计算机成绩:");
in = new BufferedReader(new InputStreamReader(System.in));
sComputerScore = in.readLine();
//给学生的各课成绩赋值
student.setMathScore(Float.parseFloat(sMathScore));
student.setLangScore(Float.parseFloat(sLangScore));
student.setPoliticsScore(Float.parseFloat(sPoliticsScore));
student.setComputerScore(Float.parseFloat(sComputerScore));
studentVect.addElement(student); System.out.print("\n");
//显示每个学生的各课成绩
printScore(studentVect);
//询问是否要继续输入
System.out.print("你还要继续登记下一个学生的成绩么?(Y/N)");
in = new BufferedReader(new InputStreamReader(System.in));
if(((toNext = in.readLine()) != null)&&(toNext.toUpperCase().equals("N")))
{
//冒泡排序方法
sortProcedure(studentVect);
//显示排序后每个学生的各课成绩
System.out.println("-----按总分从高到低输出显示每个学生的所有信息------");
printScore(studentVect);
break;
}
}
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
private static int getStudentID()
{
int maxStudentID = StudentDemo.sID + 1;
return maxStudentID;
}
private static void printScore(Vector studentVect)//打印每个同学的分数
{
for(int i = 0; i<studentVect.size(); i++)
{
System.out.println("** "+(((Student)(studentVect.elementAt(i))).getStudentID())+"号学生的成绩 ** ");
System.out.println("数学成绩:"+(((Student)(studentVect.elementAt(i))).getMathScore()));
System.out.println("英语成绩:"+(((Student)(studentVect.elementAt(i))).getLangScore()));
System.out.println("政治课成绩:"+(((Student)(studentVect.elementAt(i))).getPoliticsScore()));
System.out.println("计算机成绩:"+(((Student)(studentVect.elementAt(i))).getComputerScore()));
System.out.println("总分: "+(((Student)(studentVect.elementAt(i))).getTotalScore()));
System.out.print("\n");
}
}
private static void sortProcedure(Vector studentVect)//冒泡排序方法
{
Student temp;
for(int pass=0;pass<studentVect.size();pass++)//扫描多次
{
for(int i=0;i<studentVect.size()-pass-1;i++)//一次扫描过程
{
float f1=((Student)studentVect.elementAt(i)).getTotalScore();
float f2=((Student)studentVect.elementAt(i+1)).getTotalScore();
if(f1<f2)
{
temp=(Student)studentVect.elementAt(i);
studentVect.setElementAt((Student)studentVect.elementAt(i+1),i);
studentVect.setElementAt(temp,i+1);
}
}
}
}
}class Student
{
private int studentID = 0;
private float mathScore = 0.0f;
private float langScore = 0.0f;
private float politicsScore = 0.0f;
private float computerScore = 0.0f;
//获得数学课分数
public float getMathScore()
{
return mathScore;
}
void setMathScore(float mathScore)
{
this.mathScore = mathScore;
}
//获得英语课的分数
public float getLangScore()
{
return langScore;
}
void setLangScore(float langScore)
{
this.langScore = langScore;
}
//获得政治课分数
public float getPoliticsScore()
{
return politicsScore;
}
void setPoliticsScore(float politicsScore)
{
this.politicsScore = politicsScore;
}
//获得计算机分数
public float getComputerScore()
{
return computerScore;
}
void setComputerScore(float computerScore)
{
this.computerScore = computerScore;
}
//获得各课分数总和
public float getTotalScore()
{
return mathScore + langScore + politicsScore + computerScore;
}
//获得学号
public void setStudentID(int studentID)
{
this.studentID = studentID;
}
public int getStudentID()
{
return studentID;
}
}
public class manager extends JFrame{
private JMenuBar menubar ;
private JMenu file,edit,about,salary,search;
private JMenuItem New,Add,Remove,disp,addsalary,dispsalary,searcher;
Container c;
private Student input;
private disp display;
public JDesktopPane desktop = new JDesktopPane();
public manager(){
super(" MANAGER SYSTEM");
setJMenuBar(menubar=new JMenuBar());
c=getContentPane();
c.add(desktop);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
menubar.add(file=new JMenu("File"));
menubar.add(edit=new JMenu("Edit"));
menubar.add(search=new JMenu("Disp"));
file.add(New=new JMenuItem("Exit"));
edit.add(Add=new JMenuItem("Add"));
search.add(searcher=new JMenuItem("Disp"));
Add.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Thread runner =
new Thread() {
public void run() {
input = new Student();
desktop.add(input); }
};
runner.start(); }
});
searcher.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Thread runner =
new Thread() {
public void run() {
display = new disp();
desktop.add(display); }
};
runner.start(); }
});
New.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
System.exit(0);
}
}); setSize(800,550);
setVisible(true);
} public static void main(String args[]){
new thread().start(); }
}
import java.awt.event.*;
import javax.swing.*;
public class Student extends JInternalFrame{
private JLabel title,name,studentid,math,english,politic,computer;
private JButton jok,jcancel;
private JTextField [] jt=new JTextField[6];
private JPanel jnorth,jcenter,jsouth;
private Container c;
public JDesktopPane desktop=new JDesktopPane();
private toDateBase toDate;
private String [] data=new String [6];
private int sum=0;
public boolean isok(){
for(int j=0;j<jt.length;j++){
if(!jt[j].getText().equals("")){
data[j]=jt[j].getText();
if(j>=2){
sum+=Integer.parseInt(data[j]);
}
}
else
return true;
}
return true;
}
public Student(){
c=getContentPane();
c.add(desktop);
title=new JLabel("PLEASE INPUT STUDENTS INFORMATION");
name=new JLabel("NAME");
studentid=new JLabel("ID");
math=new JLabel("MATH");
english=new JLabel("ENGLISH");
politic=new JLabel("POLITIC");
computer=new JLabel("COMPUTER");
jnorth=new JPanel();
jcenter=new JPanel();
jsouth=new JPanel();
jok=new JButton("OK");
jcancel=new JButton("CANCEL");
GridLayout gl=new GridLayout(6,2,1,1);
jcenter.setLayout(gl);
for(int i=0;i<jt.length;i++){
jt[i]=new JTextField(10);
}
c.add(title,BorderLayout.NORTH);
jcenter.add(name);
jcenter.add(jt[0]);
jcenter.add(studentid);
jcenter.add(jt[1]);
jcenter.add(math);
jcenter.add(jt[2]);
jcenter.add(english);
jcenter.add(jt[3]);
jcenter.add(politic);
jcenter.add(jt[4]);
jcenter.add(computer);
jcenter.add(jt[5]);
c.add(jcenter,BorderLayout.CENTER);
jsouth.add(jok);
jsouth.add(jcancel);
c.add(jsouth,BorderLayout.SOUTH);
setSize(400,300);
setVisible(true);
jok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(isok()){
Thread runner=
new Thread(){
public void run(){
toDate=new toDateBase();
toDate.update("INSERT INTO student(name,studentid,math,english,politic,computer,sum)values('"+data[0]+"','"+data[1]+"','"+data[2]+"','"+data[3]+"','"+data[4]+"','"+data[5]+"','"+sum+"')");
for(int i = 0; i < jt.length; i++)
jt[i].setText(null);
}
};
runner.start();
}
}
});
jcancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ea){
dispose();
}
});
}
public static void main(String args[]){
Student app=new Student();
}
}
private Connection connection = null;
private Statement statement = null;
private ResultSet resultset = null;
public boolean isDouble(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(e.toString());
}
try {
connection = DriverManager.getConnection("jdbc:odbc:student");
statement = connection.createStatement();
resultset = statement.executeQuery(query);
while(resultset.next()) {
return true;
}
resultset.close();
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
return false;
}
public void update(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(e.toString());
}
try {
connection = DriverManager.getConnection("jdbc:odbc:student");
statement = connection.createStatement();
statement.executeUpdate(query);
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
}
}