• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

java初学者学了点学生信息管理系统

互联网 diligentman 4周前 (11-08) 15次浏览

student的类

package box;

public class student {
    private double grade;/* 成绩 */
    private String gender;/* 性别 */
    private int number;/* 学号 */
    private String name;/* 姓名 */
    public boolean setname(String name)
    {
        this.name=name;
        return true;
    }
    public boolean setgrade(double grade)
    {
        this.grade=grade;
        return true;
    }
    public  boolean setgender(String gender)
    {   
        this.gender=gender;
        return true;
    }
    public  boolean setnumber(int number)
    {
        this.number=number;
        return true;
    }
    public double outgrade()
    {
        return this.grade;
    }
    public String outgender()
    {
        return this.gender;
    }
    public int  outnumber()
    {
        return this.number;
    }
    public String outname()
    {
        return this.name;
    }
    
    public int findinnum()
    {
        return number;
    }
    public String all()
    {
        String alltext="";
        alltext =alltext+"姓名:"+outname()+"学号:"+this.number+"性别:"+outgender()+"成绩"+this.grade;
        return alltext;
    }
    
  
}

teacher的类


public class teacher {
    private String key="8888";
    private String teachername;
    public void setKey(String key) {
        this.key = key;
    }
    public void setTeachername(String teachername) {
        this.teachername = teachername;
    }
    public String outkey()
    {
        return key;
    }
}

其实现方式




import java.sql.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

import javax.swing.text.DateFormatter;
import javax.xml.crypto.Data;
import box.*;/* 导入box包内的类 */
public class App {
    public static String compare(student s1[],int n)
    {   student f[]=new student[1];
        String r="";
        for(int o=0;o<n;o++)
        {     for(int i=0;i<o;i++)
        {
            if(s1[i].outgrade()<s1[i+1].outgrade())
            {f[0]=s1[i];
            s1[i]=s1[i+1];
            s1[i+1]=f[0];
            }
        }
        }
        for(int x=0;x<n;x++)
        {
            r=r+s1[x].outnumber()+' ';
        }
        return r;
    }
    public static boolean provekey(teacher t,String keyword)
    {   if(t.outkey()==keyword)
        return true;
        else
        return false;
    }
    public static int find(int number,student stu[],int sum)//学号,stu集合,学生总数
    { int n=0;
    for(n=0;n<=sum;n++)
    {
        if(stu[n].outnumber()==number)
        return n;
    }
    return -1;
    }
    public static boolean del(int no,student stu[],int sum)
    {
       int no1=find(no, stu, sum);
       if(no1!=-1)
       {
        for (int j = no1; j<stu.length-1; j++)
            {
            stu[j] = stu[j+1];
            }//后面元素补一下
            stu[stu.length-1]=null;
        return true;
       }
       else
       return false;
    }


    public static void main(String[] args) throws Exception 
    {
        Scanner input=new Scanner(System.in);
        teacher t1=new teacher();//不完善只能一个老师
        System.out.println("*********欢迎来到学生管理系统**********");
        System.out.println("请输入密码(初始密码8888)");
                        while(true)
                        {
                        String keyword=input.next();
                        if(provekey(t1, keyword))
                        break;
                        else
                        {
                            System.out.println("输入有误重新输入");
                            continue;
                        }
                        }//验证系统
        System.out.println("需要构建几个学生呢?");
        int sum=input.nextInt();
        student stu[]= new student[sum];/* 构造sum个同学的结构体 */
while(true)
{       int num=0;//循环了第n名学生了
        System.out.println("增加学生信息扣0");
        System.out.println("改学生成绩扣1");
        System.out.println("更改密码扣2");
        System.out.println("查询学生信息扣3");
        System.out.println("删除学生信息扣4");
        System.out.println("查询当前时间扣5");
        int op=input.nextInt();
        switch(op)
        {
    case(0):
{    int x=num+1;
     System.out.println("请输入学生姓名");
     stu[num].setname(input.next());
     System.out.println("请输入学生学号");
     stu[num].setnumber(input.nextInt());
     System.out.println("请输入学生性别");
     stu[num].setgender(input.next());
     System.out.println("请输入学生成绩");
     stu[num].setgrade(input.nextDouble());
     System.out.println("第"+x+"位学生信息录入成功");
     num++;
}
    case(1):
{ System.out.println("请输入所需更改学生的学号");
  int number=input.nextInt();
  int o=find(number, stu, sum);//找到位置
  if(o!=-1)
  {   System.out.println("请输入所需更改的成绩是:");
      int after=input.nextInt();
      stu[o].setgrade(after);
  }
}
break;
    case(2):
{ System.out.println("请输入原密码");
  String old=input.next();
  while(true)
  {if(provekey(t1, old))
    {   System.out.println("请输入密码");
        t1.setKey(input.next());
        break;
    }
   else
   {
       System.out.println("原密码输入错误,请重新输入");
       continue;
   }
  }
}
break;
    case(3):
{
    System.out.println("请输入所需更改学生的学号");
    int number=input.nextInt();
    int o=find(number, stu, sum);//找到位置
    if(o!=-1)
    {   System.out.println("所要查询的信息是");
        System.out.println(stu[0].all());
    }

}
break;
    case(4): 
{
    System.out.println("请输入所删除学生学号");//用名字更好点
    int x=input.nextInt();
    if(del(x,stu,sum))
    System.out.println("删除成功");
    else
    System.out.println("删除失败");
    
}
     case(5):
{
    LocalDateTime dateTime=LocalDateTime.now();/* 获取当前时间 */
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
    System.out.println(dateTime.format(formatter));  
}  


    default:System.err.println("选项输入有误");
        }
        
    }
    }
}

–请大家批评指正–2020.11.6

PE ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

喜欢 (0)