码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-07-31 21:49:11      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:package   完成   功能   switch   equals   class   show   导出   repeat   

今天完成了一个小测试

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

他的存储结构十分简单

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

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

在此附上代码

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\n");
 }
 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\n");
 }
 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+"\n");
 }
}
 
 
 
 
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\n");
   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!\n");
  }
}
 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!\n");
  }
 }
 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\n");
  }
 }
 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\n");
  }
 }
 public static void mune(){
  System.out.print("*******************************************\n\n");
  System.out.print("                                                                \n");
  System.out.print("            学生信息管理系统 v2.0               \n");
  System.out.print("*******************************************\n\n");
  System.out.print("             1·遍历输出学生信息;                                       \n");
  System.out.print("             2·新学生信息录入;                                           \n");
  System.out.print("             3·删除学生信息;                                               \n");
  System.out.print("             4·修改学生信息;                                               \n");
  System.out.print("             5·查询学生信息;                                               \n\n");
  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 千锤百炼软工人第二十六天

标签:package   完成   功能   switch   equals   class   show   导出   repeat   

原文地址:https://www.cnblogs.com/huangmouren233/p/13411948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!