20200731 千锤百炼软工人第二十六天

Posted huangmouren233

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20200731 千锤百炼软工人第二十六天相关的知识,希望对你有一定的参考价值。

今天完成了一个小测试

是一个十分简单的学生信息管理系统

他的存储结构十分简单

而且没有文件的导入和导出功能

所以就花了点时间完成了该程序

在此附上代码

package a20200731;
public class Student {
 private String name;
 private String stunumber;
 private int age;
 private int sex;
 private double score;
 public String getStunumber() {
  return stunumber;
 }
 public String getName() {
  return name;
 }
 public int getAge() {
  return age;
 }
 public void setStunumber(String no) {
  this.stunumber = no;
 }
 public void setName(String name) {
  this.name = name;
 }
 public void setAge(int age) {
  this.age = age;
 }
 Student() {
  this.stunumber="0";
  this.name="无名氏";
  this.age=0;
  this.sex=1;
  this.score=0;
  System.out.print("Constructor run ");
 }
 Student(String no,String name, int age,int sex,double S) {
  this.name = name;
  this.stunumber=no;
  this.sex=sex;
  this.score=S;
  this.age = age;
  System.out.print("Constructor run ");
 }
 public void setSex(int sex) {
  this.sex=sex;
 }
 public int getSex() {
  return this.sex;
 }
 public void setScore(double s) {
  this.score=s;
 }
 public double getScore() {
  return this.score;
 }
 public void show() {
  System.out.print("stunumber="+this.stunumber+",name="+this.name+",sex="+this.sex+",age="+this.age+",score="+this.score+" ");
 }
}
 
 
 
 
package a20200731;
import java.util.Scanner;
import a20200731.Student;
public class main{
 public  Student[] s =new Student[5];
 public void showStudent() {
  for(int i=0;i<5;i++) {
   if(!s[i].getStunumber().equals(null)) {
    s[i].show();
   }
  }
 }
 public void addStudent(String stu,String n,int a,int sex,double S) {
  int i;
  int j;
  for(j=0;j<5;j++) {
   if(this.s[j].getStunumber().equals(stu)) {
    System.out.print("Repeat of user name ");
   break;
   }
  }
  for(i=0;i<5;i++) {
   if(s[i].getStunumber().equals(null)) {
    s[i].setAge(a);
    s[i].setName(n);
    s[i].setScore(S);
    s[i].setSex(sex);
    s[i].setStunumber(stu);
    break;
   }
   }
  if(i==5) {
   System.out.print("User full! ");
  }
}
 public void deleteStudent(String stu) {
  int i;
  for(i=0;i<5;i++) {
   if(s[i].getStunumber().equals(stu)) {
    s[i]=null;
   break;
   }
  }
  if(i==5) {
   System.out.print("User name falue! ");
  }
 }
 public void updateStudent(String stu,String n,int a,int sex,double score) {
  int i;
  for(i=0;i<5;i++) {
   if(s[i].getStunumber().equals(stu)) {
    s[i].setAge(a);
    s[i].setName(n);
    s[i].setScore(score);
    s[i].setSex(sex);
    s[i].setStunumber(stu);
    break;
   }
  }
  if(i==5) {
   System.out.print("User name falue ");
  }
 }
 public void selectStudent(String stu) {
  int i;
  for(i=0;i<5;i++) {
   if(s[i].getStunumber().equals(stu)) {
    s[i].show();
    break;
   }
  }
  if(i==5) {
   System.out.print("User name falue ");
  }
 }
 public static void mune(){
  System.out.print("******************************************* ");
  System.out.print("                                                                ");
  System.out.print("            学生信息管理系统 v2.0               ");
  System.out.print("******************************************* ");
  System.out.print("             1·遍历输出学生信息;                                       ");
  System.out.print("             2·新学生信息录入;                                           ");
  System.out.print("             3·删除学生信息;                                               ");
  System.out.print("             4·修改学生信息;                                               ");
  System.out.print("             5·查询学生信息;                                               ");
  System.out.print("********************************************");
 }
 }
 
 
 
 
 
package a20200731;
import java.util.Scanner;
import a20200731.Student;
import java.util.Scanner;
public class maina {
 public static void main(String[] arg) {
  main x = new main();
     int  b;
     x.s[0] = new Student();
     x.s[1] = new Student();
     x.s[2] = new Student();
     x.s[3] = new Student();
     x.s[4] = new Student();
     x.mune();
     Scanner a =new Scanner(System.in);
  b=a.nextInt();
     a:
     for(;;) {
     if(b==6) break a;
     switch(b){
  case 1:
   x.showStudent();
   x.mune();
   Scanner a1 =new Scanner(System.in);
   b=a1.nextInt();
   break;
  case 2:
   System.out.print("请输入学号:");
   Scanner stu = new Scanner(System.in);
   System.out.print("请输入姓名:");
   Scanner n = new Scanner(System.in);
   System.out.print("请输入年龄:");
   Scanner age = new Scanner(System.in);
   System.out.print("请输入性别:");
   Scanner sex = new Scanner(System.in);
   System.out.print("请输入分数:");
   Scanner S = new Scanner(System.in);
   String stu1 = new String();
   String n1 = new String();
   int age1;
   double S1;
   int sex1;
   stu1=stu.next();
   n1=n.next();
   age1=age.nextInt();
   sex1=sex.nextInt();
   S1=S.nextDouble();
   x.addStudent(stu1,n1,age1,sex1,S1);
   x.mune();
   Scanner a2 =new Scanner(System.in);
   b=a2.nextInt();
   break;
  case 3:
   System.out.print("请输入学号:");
   Scanner stu2 = new Scanner(System.in);
   String stu3 = new String();
   stu3 = stu2.next();
   x.deleteStudent(stu3);
   x.mune();
   Scanner a3 =new Scanner(System.in);
   b=a3.nextInt();
   break;
  case 4:
   System.out.print("请输入学号:");
   Scanner stu4 = new Scanner(System.in);
   System.out.print("请输入姓名:");
   Scanner n4 = new Scanner(System.in);
   System.out.print("请输入年龄:");
   Scanner age4 = new Scanner(System.in);
   System.out.print("请输入性别:");
   Scanner sex4 = new Scanner(System.in);
   System.out.print("请输入分数:");
   Scanner S4 = new Scanner(System.in);
   String stu5 = new String();
   String n5 = new String();
   int age5;
   double S5;
   int sex5;
   stu5=stu4.next();
   n5=n4.next();
   age5=age4.nextInt();
   S5=S4.nextDouble();
   sex5=sex4.nextInt();
   x.updateStudent(stu5, n5, age5, sex5, S5);
   x.mune();
   Scanner a4 =new Scanner(System.in);
   b=a4.nextInt();
   break;
  case 5:
   System.out.print("请输入学号:");
   Scanner stu6 = new Scanner(System.in);
   String stu7 = new String();
   stu7 = stu6.next();
   x.selectStudent(stu7);
   x.mune();
   Scanner a5 =new Scanner(System.in);
   b=a5.nextInt();
   break;
     }
 }
     }
}
 
 

以上是关于20200731 千锤百炼软工人第二十六天的主要内容,如果未能解决你的问题,请参考以下文章

马哥教育第二十四至二十六天学习总结

第二十六天

第二十六天打卡

第二十六天

Mysql基础第二十六天,使用存储过程

第二十六天Python学习记录