重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
用易查分就可以做,把你需要查詢的信息做成excel表格,上傳到易查分,設置“學號”“姓名”為查詢條件,設置完成后,點生成,就可以得到一個查詢鏈接,你可以把這個鏈接放到你所說的網站上,學員點鏈接 輸入學號姓名就能查到!另外如果信息有錯誤,你可以在易查分的后臺,在線編輯,不用再次上傳就能實現,非常簡單的!
網站建設哪家好,找成都創新互聯!專注于網頁設計、網站建設、微信開發、微信小程序定制開發、集團企業網站建設等服務項目。為回饋新老客戶創新互聯還提供了晉州免費建站歡迎大家使用!
我剛寫的,可能還有點漏洞
import?java.util.*;
import?java.util.Scanner;
public?class?Bd05?{
public?static?final?Scanner?s?=?new?Scanner(System.in);
public?static?void?main(String[]?args)?{
ArrayListStudent?al?=?new?ArrayListStudent();
home(al);
}
public?static?void?home(ListStudent?list){
while(true){
System.out.println("1.錄入學生信息?????2.查詢學生信息?????3.刪除學生信息?????4.退出\n輸入數字選擇:");
int?num?=?s.nextInt();
switch(num){
case?1:
inputInfo(list);
break;
case?2:
findInfo(list);
break;
case?3:
remove(list);
break;
case?4:
System.exit(0);
}
}
}
public?static?void?findInfo(ListStudent?list){ //查詢信息
System.out.println("1.升序?????2.降序??????3.返回\n輸入數字選擇查詢方式(兩科的總分):");
int?num?=?0;
while(true){
num?=?s.nextInt();
if(num==1){ //升序
Collections.sort(list,new?ComparatorStudent(){
public?int?compare(Student?s1,?Student?s2)?{
int?n?=?new?Integer(s1.getChinese()+s1.getMath()).compareTo(new?Integer(s2.getChinese()+s2.getMath()));
if(n==0)
return?s1.getName().compareTo(s2.getName());
return?n;
}
});
printAll(list);
}
else?if(num==2){ //降序
Collections.sort(list,new?ComparatorStudent(){
public?int?compare(Student?s1,?Student?s2)?{
int?n?=?new?Integer(s2.getChinese()+s2.getMath()).compareTo(new?Integer(s1.getChinese()+s1.getMath()));
if(n==0)
return?s2.getName().compareTo(s1.getName());
return?n;
}
});
printAll(list);
}
else?if(num==3)
break;
else
System.out.println("輸入錯誤,重新輸入:");
}
home(list);
}
public?static?void?remove(ListStudent?list){ //刪除信息
System.out.print("輸入需要刪除的姓名:");
String?name?=?s.next();
IteratorStudent?it?=?list.listIterator();
while(it.hasNext()){
Student?str?=?it.next();
if(name.equals(str.getName())){
it.remove();
System.out.println(name+"?刪除成功!");
}
}
System.out.println("1.繼續?????2.返回\n輸入數字選擇:");
while(true){
int?num?=?s.nextInt();
if(num==1){
remove(list);
}
else?if(num==2)
break;
else
System.out.println("輸入錯誤,重新輸入:");
}
home(list);
}
public?static?void?printAll(ListStudent?list){
int?num?=?1;
System.out.println("--------------(查詢)----------------");
for(Student?stu:list){
System.out.println(num++?+".姓名:"+stu.getName()+"|語文成績:"+stu.getChinese()+"|數學成績:"+stu.getMath()+"---|總分:"+(stu.getChinese()+stu.getMath()));
}
System.out.println("-----------------------------------");
home(list);
}
public?static?void?inputInfo(ListStudent?list){ //輸入信息
System.out.println("輸入學生姓名:");
String?name?=?s.next();
System.out.println("輸入數學成績:");
int?Math?=?s.nextInt();
System.out.println("輸入語文成績:");
int?chinese?=?s.nextInt();
list.add(new?Student(name,Math,chinese));
System.out.println("1.返回?????2.繼續錄入\n輸入數字選擇:");
while(true){
int?num?=?s.nextInt();
if(num==1)
break;
else?if(num==2)
inputInfo(list);
else
System.out.println("輸入錯誤,重新輸入:");
}
home(list);
}
}
class?Student{
private?String?name;
private?int?chinese;
private?int?math;
Student(String?name,int?math,int?chinese){
this.name?=?name;
this.chinese?=?chinese;
this.math?=?math;
}
public?String??getName(){
return?name;
}
public?int?getChinese(){
return?chinese;
}
public?int?getMath(){
return?math;
}
}
import?java.util.HashMap;
import?java.util.LinkedList;
import?java.util.Map;
import?java.util.Scanner;
public?class?Test?{
LinkedListHashMapString,?Integer?examList;
public?Test()?{
LinkedListHashMapString,?Integer?examList?=?new?LinkedListHashMapString,Integer();
//第一次
HashMapString,?Integer?first?=?new?HashMapString,?Integer();
first.put("張三",?80);
first.put("李四",?65);
first.put("王五",?35);
first.put("薛六",?90);
first.put("趙七",?70);
//第二次
HashMapString,?Integer?second?=?new?HashMapString,?Integer();
second.put("張三",?88);
second.put("李四",?75);
second.put("王五",?45);
second.put("薛六",?92);
second.put("趙七",?75);
//第三次
HashMapString,?Integer?third?=?new?HashMapString,?Integer();
third.put("張三",?86);
third.put("李四",?67);
third.put("王五",?55);
third.put("薛六",?98);
third.put("趙七",?65);
//第四次
HashMapString,?Integer?fourth?=?new?HashMapString,?Integer();
fourth.put("張三",?88);
fourth.put("李四",?80);
fourth.put("王五",?59);
fourth.put("薛六",?88);
fourth.put("趙七",?68);
examList.add(first);
examList.add(second);
examList.add(third);
examList.add(fourth);
this.examList?=?examList;
}
//通過次數獲得總成績
public?int?getExamCount(int?times)?{
int?count?=?0;
HashMapString,?Integer??exam?=?examList.get(times-1);?
for(String?studentName?:exam.keySet())?{
int?score?=?exam.get(studentName);
count?+=?score;
}?
return?count;
}
//通過學生姓名獲得學生總成績
public?int?getStudentExamCount(String?name)?{
int?count?=?0;
for(HashMapString,?Integer??exam??:?examList)?{
int?score?=?exam.get(name);
count?+=?score;
}
return?count;
}
//通過學生姓名獲得學生的平局成績
public?int?getStudentExamAvg(String?name)?{
int?count?=?0;
int?times?=?0;
for(HashMapString,?Integer??exam??:?examList)?{
times++;
int?score?=?exam.get(name);
count?+=?score;
}
return?count/times;
}
//查詢全班平均分最高的一次
public?MapInteger,Integer?getClassMaxAvg()?{
MapInteger,Integer?result?=?new?HashMapInteger,Integer();
int?time?=?0;//存儲考試次數
int?maxScoreAvg=0;//存儲最高的考試成績
int?i?=?0;//當前考試次數
for(HashMapString,?Integer??exam??:?examList)?{
i++;
int?scoreCount?=?0;//存儲考試成績總和
for(String?name?:?exam.keySet())?{
int?score?=?exam.get(name);
scoreCount?+=?score;
}
if((scoreCount/4)?maxScoreAvg)?{
time?=?i;
maxScoreAvg?=?scoreCount/4;
}
}
result.put(time,?maxScoreAvg);
return?result;
}
//通過學生姓名和考試次數獲得學生的某次考試成績
public?int?getStudentExam(String?name,int?times)?{
MapString,Integer?exam?=?examList.get(times-1);
int?score?=?exam.get(name);
return?score;
}
public?void?showTitle()?{
System.out.println("==========成績查詢說明==========");
System.out.println("輸入?1@[考試次數]?查詢某次考試總成績??如?1@2");
System.out.println("輸入?2@[學生姓名]?查詢某考生總成績??如?2@李四");
System.out.println("輸入?3@[學生姓名]?查詢某考生平均成績??如?3@李四");
System.out.println("輸入?4?查詢全班平均分最高的次數和成績??如?4");
System.out.println("輸入?5@[學生姓名]@[考試次數]?查詢某考生某次成績??如?5@張三@2");
System.out.println("==========成績查詢說明==========");
}
public?static?void?main(String[]?args)?{
Test?test?=?new?Test();
test.showTitle();
Scanner?s?=?new?Scanner(System.in);
String?input;
while(s.hasNext())?{
try?{
input?=?s.next();
if(input.startsWith("1"))?{
String[]?inputs?=?input.split("@");
System.out.println("第"+inputs[1]+"次總成績為:"+test.getExamCount(Integer.valueOf(inputs[1])));
}else?if(input.startsWith("2"))?{
String[]?inputs?=?input.split("@");
System.out.println(inputs[1]+"的總成績為:"+test.getStudentExamCount(inputs[1]));
}else?if(input.startsWith("3"))?{
String[]?inputs?=?input.split("@");
System.out.println(inputs[1]+"平均成績為:"+test.getStudentExamAvg(inputs[1]));
}else?if(input.startsWith("4"))?{
System.out.println("全班平均分最高的次數和成績為:"+test.getClassMaxAvg());
}else?if(input.startsWith("5"))?{
String[]?inputs?=?input.split("@");
System.out.println(inputs[1]+"第"+inputs[2]+"次考試成績為:"+test.getStudentExam(inputs[1],Integer.valueOf(inputs[2])));
}else?{
test.showTitle();
}
}catch(Exception?e)?{
test.showTitle();
}
}
}
}
先判 范圍 再 case 搞一方法
private int check(int a)
{
if (a90)
return 1;
else if(90=a a=80)
return 2;
.........
}
switch(check(a)){
case 1:
System.out.println("成績優秀");
.......
}
}
可使用jdbc鏈接。
下面是針對MySql的鏈接!
-----------------------------------------
package com.dgy.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestJDBC {
/**
* 1、所使用的mysql驅動包為mysql-connector-java-5.0.8-bin.jar
* 2、Statement 用于執行靜態 SQL 語句并返回它所生成結果的對象
* 在默認情況下,同一時間每個 Statement 對象在只能打開一個 ResultSet 對象。
* 因此,如果讀取一個 ResultSet 對象與讀取另一個交叉,
* 則這兩個對象必須是由不同的Statement 對象生成的。
* 如果存在某個語句的打開的當前 ResultSet 對象,
* 則Statement 接口中的所有執行方法都會隱式關閉它。
* 3、ResultSet 表示數據庫結果集的數據表,通常通過執行查詢數據庫的語句生成。
* ResultSet 對象具有指向其當前數據行的指針。最初,指針被置于第一行之前。
* next 方法將指針移動到下一行;
* 因為該方法在 ResultSet 對象中沒有下一行時返回 false,
* 所以可以在 while 循環中 使用它來迭代結果集。
**/
static Connection conn = null;
public static Connection getConnectionByJDBC() {
try {
//裝載驅動包類
Class.forName(com.mysql.jdbc.Driver");//加載驅動
}catch(ClassNotFoundException e) {
System.out.println("裝載驅動包出現異常!請查正!");
e.printStackTrace();
}
try{
/** 建立jdbc連接,但要注意此方法的第一個參數,
* 如果127.0.0.1出現CommunicationsException異常,
* 可能就需要改為localhost才可以
**/
//jdbc:mysql://localhost:3306/test,test是數據庫
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
}catch(SQLException e) {
System.out.println("鏈接數據庫發生異常!");
e.printStackTrace();
}
return conn;
}
public static void test(){
String sql = "select * from user";
getConnectionByJDBC();
try{
//創建一個jdbc聲明
Statement stmt = conn.createStatement();
//執行查詢
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
String username = rs.getString("username");
String password= rs.getString("password");
System.out.println(username +""+ password);
}
}catch (SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
}finally{
//預防性關閉連接(避免異常發生時在try語句塊關閉連接沒有執行)
try{
if(conn != null) conn.close();
} catch(SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
public static void main(String[] args){
TestJDBC testjdbc = new TestJDBC();
testjdbc.test();
}
}
以下方法實現了用戶界面登陸
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創建一個用戶名標簽
TextField t1=new TextField();//創建一個文本框對象
Label password=new Label("密碼:");//創建一個密碼標簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創建登陸按鈕
Button b2=new Button("取消");//創建取消按鈕
public DengLuJieMian()
{
this.setTitle("學生信息管理系統");//設置窗口標題
this.setLayout(null);//設置窗口布局管理器
username.setBounds(50,40,60,20);//設置姓名標簽的初始位置
this.add(username);// 將姓名標簽組件添加到容器
t1.setBounds(120,40,80,20);// 設置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標簽的初始位置
this.add(password);//將密碼標簽組件添加到容器
t2.setBounds(120,100,80,20);//設置密碼標簽的初始位置
this.add(t2);//將密碼標簽組件添加到容器
b1.setBounds(50,150,60,20);//設置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監聽器
b2.addActionListener(this);// 給取消按鈕添加監聽器
this.setVisible(true);//設置窗口的可見性
this.setSize(300,200);//設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過內部類重寫關閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判斷語句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數
{
new DengLuJieMian();
}
}
以下方法實現了學生界面設計
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創建菜單欄
Menu m1=new Menu("信息");//創建菜單“信息”
MenuItem m11=new MenuItem("插入");//創建“插入”的菜單項
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績");//創建菜單“成績”
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學生界面");//設置窗口標題
this.setLayout(new CardLayout());//設置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將“插入”菜單項添加到“信息”菜單
m1.add(m12); //將“查詢”菜單項添加到“信息”菜單
m2.add(m21); //將“查詢”菜單項添加到“成績”菜單
m11.addActionListener(this); //給“插入”菜單項添加監聽器
m12.addActionListener(this); //給“查詢”菜單項添加監聽器
m21.addActionListener(this); //給“查詢”菜單項添加監聽器
this.setVisible(true); //設置窗口的可見性
this.setSize(300,200); //設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理“查詢信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理“查詢成績”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創建一個對象 }