首页 > 其他分享 >9.20

9.20

时间:2024-09-20 23:45:19浏览次数:8  
标签:9.20 name void private sex public String

今天进行了java的二次测试,了解了java里基本的增删改查的功能;以及查找时报错等细节处理
student类

点击查看代码
package qixun;

public class student {
    private String stunumber;
    private String name;
    private int age;
    private boolean sex;
    private double score;

    public student(String stunumber,String name,int age,boolean sex,double score){
        this.stunumber=stunumber;
        this.name=name;
        this.age=age;
        this.sex=sex;
        this.score=score;
    }

    public String getStunumber(){
        return stunumber;
    }
    public void setStunumber(String stunumber){
        this.stunumber=stunumber;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        this.age=age;
    }
    public boolean getsex(){
        return sex;
    }
    public void setSex(boolean sex){
        this.sex=sex;
    }
    public double getScore(){
        return score;
    }
    public void setScore(double score){
        this.score=score;
    }
}

studentManage类

点击查看代码
package qixun;

import java.util.Scanner;

public class studentManage {
    public void Header(){
        System.out.println("***************************************************************\n");
        System.out.println("石家庄铁道大学软件工程系学生信息管理系统\n");
        System.out.println("****************************************************************\n");
    }
    public  void menu(){
        System.out.println("1、\t遍历输出学生信息;\n" +
                "2、\t新学生信息录入;\n" +
                "3、\t删除学生信息;\n" +
                "4、\t修改学生信息;\n" +
                "5、\t查询学生信息;\n" +
                "****************************************************************");
    }
    private student[] stds = new student[5];
    private int count=0;
    public void Menugo() {
        Scanner scanner = new Scanner(System.in);
        Header();
        while (true){
            menu();
            System.out.println("请选择:");
            int choice = scanner.nextInt();
            switch (choice){
                case 1:
                    showStdent();
                    break;
                case 2:
                    addStudent();
                    break;
                case 3:
                    deleteStudent();
                    break;
                case 4:
                    updateStudent();
                    break;
                case 5:
                    selectStudent();
                    break;
            }

        }
    }
    private void showStdent(){
        for(int i=0;i<count;i++){
            System.out.println("学号:"+stds[i].getStunumber());
            System.out.println("姓名:"+stds[i].getName());
            System.out.println("年零:"+stds[i].getAge());
            System.out.println("性别:"+stds[i].getsex());
            System.out.println("成绩:"+stds[i].getScore());
            System.out.println("****************************************************************\n");
        }
    }

    private void addStudent(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号:");
        String stunumber = scanner.nextLine();
        for(int i=0;i<count;i++) {
            if (stds[i].getStunumber().equals(stunumber)) {
                System.out.println("学号重复");
            }
        }
        System.out.println("请输入姓名:");
        String name = scanner.nextLine();
        System.out.println("请输入年龄:");
        int age = scanner.nextInt();
        System.out.println("请输入性别:");
        boolean sex = scanner.nextBoolean();
        System.out.println("请输入成绩:");
        double score = scanner.nextDouble();
        student newstudent=new student(stunumber,name,age,sex,score);
        stds[count]=newstudent;
        count++;
    }

    private void deleteStudent(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号:");
        String stunumber = scanner.nextLine();
        boolean flag=false;
        for(int i=0;i<count;i++) {
            if(stds[i].getStunumber().equals(stunumber)) {
                for(int j=i;j+1<count;j++){
                    stds[j].setStunumber(stds[j+1].getStunumber());
                    stds[j].setName(stds[j+1].getName());
                    stds[j].setAge(stds[j+1].getAge());
                    stds[j].setSex(stds[j+1].getsex());
                    stds[j].setScore(stds[j+1].getScore());
                }
                count--;
                flag=true;
            }
        }
        if(flag==false){
            System.out.println("未找到");
        }
    }

    private void updateStudent(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号:");
        String stunumber = scanner.nextLine();
        boolean flag=false;
        for(int i=0;i<count;i++){
            if(stds[i].getStunumber().equals(stunumber)){
                System.out.println("请选择修改内容:\n" +
                                   "1.学号 2.姓名 3.年龄 4.性别 5.成绩");
                int choice1 = scanner.nextInt();
                switch (choice1){
                    case 1:
                        System.out.println("请输入学号:");
                        String stunumber1 = scanner.nextLine();
                        stds[i].setStunumber(stunumber1);
                        break;
                    case 2:
                        System.out.println("请输入姓名:");
                        String name = scanner.nextLine();
                        stds[i].setName(name);
                        break;
                    case 3:
                        System.out.println("请输入年龄:");
                        int age = scanner.nextInt();
                        stds[i].setAge(age);
                        break;
                    case 4:
                        System.out.println("请输入性别:");
                        boolean sex = scanner.nextBoolean();
                        stds[i].setSex(sex);
                        break;
                    case 5:
                        System.out.println("请输入成绩:");
                        double score = scanner.nextDouble();
                        stds[i].setScore(score);
                        break;
                }
                flag=true;
            }
        }
        if(flag==false){
            System.out.println("未找到");
        }
    }

    private void selectStudent(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号:");
        String stunumber = scanner.nextLine();
        for(int i=0;i<count;i++) {
            if(stds[i].getStunumber().equals(stunumber)){
                System.out.println("学号:"+stds[i].getStunumber());
                System.out.println("姓名:"+stds[i].getName());
                System.out.println("年零:"+stds[i].getAge());
                System.out.println("性别:"+stds[i].getsex());
                System.out.println("成绩:"+stds[i].getScore());
                System.out.println("****************************************************************\n");
            }
        }
    }
    public static void main(String[] args) {
        studentManage management = new studentManage();
        management.Menugo();
    }
}

标签:9.20,name,void,private,sex,public,String
From: https://www.cnblogs.com/qiixunlu/p/18423464

相关文章

  • 2024.9.20
    publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);StudentManagermanager=newStudentManager(5);while(true){System.out.println("");System.out.println("石家庄铁道大学软件工程系学生信息管理系统");System.out.println(&q......
  • java学习9.20
    今天是简单的java小测验,实现简单的增删改查操作。我先用数组完成。后面的话想实现连接数据库的增删改查,但是始有bug不知道咋改,写的少不清楚问题出在哪,多写几回应该就能对症下药。下面是数组的代码Student类publicclassStudent{Stringstunumber;Stringname;......
  • 9.20~
    9.20上午晚上学校空调好像半夜就断电了(byd之前用薄被子就给我冻醒现在拿厚被子来就热死我是吧......
  • 9.20 模拟赛
    C.[CSP-S--三十连测第二十七套]--T3--fac-S---【云智计划】---6月30日---模拟测#27div2【补题】-比赛-梦熊联盟(mna.wang)题意\(n\)次询问,给定\(a,k\)。有一个可重集合,初始只有一个元素\(a\)。每次操作将集合中所有元素替换为它的所有约数。求\(k\)次操作后集......
  • 9.20 斜率优化复习
    看我之前写的狗屎:https://www.becoder.com.cn/article/11836。当时根本就不懂斜率优化是什么。今天真的懂了,来写总结。1问题转化对于一类dp方程式:\(f(i)=\min\{f(j)+A(j)*g(i)+B(j)+t(i)\}\)。可以用斜率优化。设\(b=f(i)-t(i)\)。把当前dp转移当成是一条斜率......
  • 活动召集丨实时多模态 AI Builder 团聚!RTE Open Day@S创上海,9.20/21
       9月20~21日,上海,S创上海2024,看见不一样的创新和技术。 这场年轻、多元、活力十足的科技盛会,将汇聚创业者、开发者、艺术家和众多无法定义边界的跨界者。RTE开发者社区的Builders和RTEOpenDay也将玩乐其中! 「有一群人在一起,就很好」。来到第四期的RTE......
  • Cisco Secure Firewall 4200 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布
    CiscoSecureFirewall4200SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-4200/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSe......
  • Cisco Secure Firewall 3100 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布
    CiscoSecureFirewall3100SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:CiscoSecureFirewall3100SeriesFTDSoftware7.4.2&ASASoftware9.20.3,查看最新版。原创作品,转载请......
  • Cisco Firepower 9300 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布下载 -
    CiscoFirepower9300SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-9300/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSecure......
  • Cisco Firepower 4100 Series FTD Software 7.4.2 & ASA Software 9.20.3 发布下载 -
    CiscoFirepower4100SeriesFTDSoftware7.4.2&ASASoftware9.20.3发布下载-思科防火墙系统软件FirepowerThreatDefense(FTD)Software请访问原文链接:https://sysin.org/blog/cisco-firepower-4100/,查看最新版。原创作品,转载请保留出处。为什么选择CiscoSecure......