Java大作业 | 学生成绩信息管理系统

**

Java大作业 学生成绩信息管理系统(无用户界面)

**

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
class Person{
public String name;
public String sex;
public int Id;
}

class Student extends Person{
int grade;
public Student(String name,int Id,String sex,int grade){
this.name= name;
this.Id= Id;
this.sex = sex;
this.grade = grade;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getStudentId(){
return Id;
}
public int getGrade(){
return grade;
}
public void setGrade(int g){
this.grade = g;
}
}

interface stuTest{
abstract void Tprint();
}

class stuIdException extends Exception{
String message;
public stuIdException(int m) {
message =”学生学号输入错误 “+m+”是错误学号 请输入正确四位数 学号”;
}
public String Warn() {
return message;
}
}

class menu extends JFrame
{
public menu()
{
super(“学生信息登录系统”);
JPanel root = new JPanel();

  root.add(new JLabel("用户名:"));
  root.add(new JTextField("       "));
  root.add(new JLabel("密码:"));
  root.add(new JTextField("请输入6位数字密码"));
  root.add(new JButton("点击登录"));
  add(root);
  setSize(300, 250);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);

}

}
public class Manager implements stuTest {
static List StudentList = new ArrayList();

public void Tprint(){
    System.out.println(" **----  请再次选择功能  ---- **   "); 
}
static void testselect(List<Student> StudentList ){
    System.out.println("          ");
    System.out.println(" **----   #大连海事大学   学生信息管理系统#   ---- **   "); 
    System.out.println("           ----- 系统功能如下-----      ");
    System.out.println("          ");
    System.out.println("           No 1.  进行学生的信息输入");
    System.out.println("           No 2.  进行学生的信息删除");
    System.out.println("           No 3.  进行学生的信息修改");
    System.out.println("           No 4.  进行学生的信息查询");
    System.out.println("          ");
    System.out.println("(///! 请先输入  数字 1  对所有学生的信息进行输入:///)"); 
    System.out.println("          ");
    System.out.println("{ 若已经输入完所有学生信息 "); 
    System.out.println("  则输入其他功能编号 对学生信息进行管理:}"); 
    System.out.println("          ");

    Scanner sc = new Scanner(System.in);
    int choice = sc.nextInt(); 

    if(choice>4) {
        throw new RuntimeException();
    }

    switch(choice){
    case 1:
        System.out.print("请输入该学生的姓名:");
        Scanner Sname = new Scanner(System.in);
        String name = Sname.nextLine();
        System.out.print("请输入该学生的性别:");
        Scanner Ssex = new Scanner(System.in);
        String sex = Ssex.nextLine();
        System.out.print("请输入该学生的学号(入学注册四位数号码):");
        Scanner SId = new Scanner(System.in);
        int studentId = SId.nextInt();

        if(studentId<=999) {
            throw new RuntimeException();
        }

        System.out.print("请输入该学生的java实验成绩分数:");
        Scanner Sgrade = new Scanner(System.in);
        int grade = Sgrade.nextInt();
        StudentList.add(new Student(name,studentId,sex,grade));
        System.out.println("已经完成信息输入");

        testselect(StudentList);
        break;

    case 2:
        System.out.print("请输入需要删除学生的学号:");
        Scanner Sid = new Scanner(System.in);
        int SstudentId = Sid.nextInt();
        for (int i = 0; i < StudentList.size(); i++) {
            if(SstudentId==(StudentList.get(i).getStudentId())){
                StudentList.remove(i);
                System.out.println("已经完成信息删除");                    
            }
        }

        testselect(StudentList);
        break;

    case 3:
        System.out.print("请输入需要修改成绩学生的学号:");
        Scanner GId = new Scanner(System.in);
        int GstudentId = GId.nextInt();
        if(GstudentId<=999) {
            throw new RuntimeException();
        }
        for (int j = 0; j < StudentList.size(); j++) {
            if(GstudentId==(StudentList.get(j).getStudentId())){

                System.out.print("请输入修改后学生的成绩:");
                Scanner Ggrade = new Scanner(System.in);
                int grade2 = Ggrade.nextInt();
                StudentList.get(j).setGrade(grade2);
                System.out.println("已经完成信息修改"); 
            }
            }
            testselect(StudentList);
            break;

        case 4:
            System.out.print("请输入需要查询学生的学号:");
            Scanner CId = new Scanner(System.in);
            int CstudentId = CId.nextInt();
            if(CstudentId<=999) {
                throw new RuntimeException();
            }
            for (int i = 0; i < StudentList.size(); i++) {
                if(CstudentId==(StudentList.get(i).getStudentId())){
                    System.out.println("************************");
                    System.out.println("          ");   
                    System.out.println("该学生名字:"+StudentList.get(i).getName());
                    System.out.println("          ");
                    System.out.println("该学生性别:"+StudentList.get(i).getSex());
                    System.out.println("          ");
                    System.out.println("该学生学号:"+StudentList.get(i).getStudentId());
                    System.out.println("          ");
                    System.out.println("该学生成绩:"+StudentList.get(i).getGrade());
                    System.out.println("          ");     
                    System.out.println("************************");   

                }
            }
            testselect(StudentList);
            break;
        }

    }

    public static void main(String[] args)
    {

       new menu();
       testselect(StudentList);                    
    }

}
发布了4 篇原创文章 · 获赞 20 · 访问量 9345
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览