• 暑假日报-17


    今天完成了简单的学生管理系统

     

    package 学生成绩管理系统;
    import java.util.*;
    @SuppressWarnings("unused")
    public class Student {
    private String StudentNumber;
    private String name;
    private int age;
    private boolean sex;
    private double score;
    Scanner in=new Scanner(System.in);
    public Student() {
    StudentNumber="00000000";
    name="***";
    age=0;
    sex=false;
    score=0;
    }
    public String GetStudentNumber() {
    return StudentNumber;
    }
    public String GetName() {
    return name;
    }
    public int GetAge() {
    return age;
    }
    public boolean GetSex() {
    return sex;
    }
    public double GetScore() {
    return score;
    }
    public void SetStudentNumber() {
    StudentNumber=in.next();
    }
    public void SetName() {
    name=in.next();
    }
    public void SetAge() {
    age=in.nextInt();
    }
    public void SetSex() {
    String temp;
    System.out.print("please input sex male or female:");
    temp=in.next();
    if(temp=="male")
    sex=false;
    else if(temp=="female")
    sex=true;
    //else {
    //System.out.println("input error i wanna goto but not have,please exit");
    //}
    }
    public void SetScore() {
    score=in.nextDouble();
    }

    }

    package 学生成绩管理系统;
    import java.util.*;
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public class StudentManager {
    int n=5;
    Student []A=new Student[n];
    Scanner in=new Scanner(System.in);
    void show() {
    System.out.println("****************************************************************");
    System.out.println("* 石家庄铁道大学信息科学与技术学院 *");
    System.out.println("* 学生信息管理系统 *");
    System.out.println("****************************************************************");
    System.out.println("* 1、 遍历输出学生信息 *");
    System.out.println("* 2、 新学生信息录入 *");
    System.out.println("* 3、 删除学生信息 *");
    System.out.println("* 4、 修改学生信息 *");
    System.out.println("* 5、 查询学生信息 *");
    System.out.println("****************************************************************");
    }
    void SelsctStudent() {
    int i;
    String num;
    System.out.print("plaese input StudentNumber:");
    num=in.next();
    for(i=0;i<n;i++)
    if(A[i].GetStudentNumber()==num)
    {
    System.out.print(" id:");
    System.out.print(A[i].GetStudentNumber());
    System.out.print(" name:");
    System.out.print(A[i].GetName());
    System.out.print(" age:");
    System.out.print(A[i].GetAge());
    System.out.print(" sex(false==male,true==famale):");
    System.out.print(A[i].GetSex());
    System.out.print(" score:");
    System.out.print(A[i].GetScore());
    break;
    }

    }
    void UpdateStudent() {
    int i;
    Student B;
    B=Set();
    for(i=0;i<n;i++)
    if(B.GetStudentNumber()==A[i].GetStudentNumber())
    break;
    List<Student> list=new ArrayList(Arrays.asList(A));
    list.set(i, B);
    Student[] ne=new Student[list.size()];
    list.toArray(ne);
    A=ne;
    }
    void DeleteStudent() {
    int i;
    String num;
    System.out.print("plaese input StudentNumber:");
    num=in.next();
    for(i=0;i<n;i++)
    if(A[i].GetStudentNumber()==num)
    break;
    List<Student> list=new ArrayList(Arrays.asList(A));
    list.remove(i);
    Student[] ne=new Student[list.size()];
    list.toArray(ne);
    A=ne;
    n--;

    }
    void AddStudent(){
    Student B;
    List<Student> list=new ArrayList(Arrays.asList(A));
    B=Set();
    for(int i=0;i<n;i++)
    if(B.GetStudentNumber()==A[i].GetStudentNumber())
    {
    System.out.print("重复,请重新输入");
    B=Set();
    break;
    }
    list.add(B);
    Student[] ne=new Student[list.size()];
    list.toArray(ne);
    A=ne;
    n++;
    }
    void ShowStudent() {
    for(Student element:A)
    System.out.println(element);
    }
    void SetStudent() {
    for(int i=0;i<n;i++)
    A[i]=Set();
    }
    Student Set() {
    Student temp = new Student();
    System.out.println("please enter in turn");
    System.out.println("StudentNumber Name Age Sex Score");
    temp.SetStudentNumber();
    temp.SetName();
    temp.SetAge();
    temp.SetSex();
    temp.SetScore();
    return temp;
    }

    }

    package 学生成绩管理系统;

    /*import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;*/
    import java.util.*;

    public class zhu {
    /* @SuppressWarnings("deprecation")
    public static void clear() throws AWTException {
    Robot r = new Robot();
    r.mousePress(InputEvent.BUTTON3_MASK); // 按下鼠标右键
    r.mouseRelease(InputEvent.BUTTON3_MASK); // 释放鼠标右键
    r.keyPress(KeyEvent.VK_CONTROL); // 按下Ctrl键
    r.keyPress(KeyEvent.VK_R); // 按下R键
    r.keyRelease(KeyEvent.VK_R); // 释放R键
    r.keyRelease(KeyEvent.VK_CONTROL); // 释放Ctrl键
    r.delay(100);

    }*/
    public static void main(String[] args) {
    StudentManager A = new StudentManager();
    int choice;
    @SuppressWarnings("resource")
    Scanner in=new Scanner(System.in);
    A.SetStudent();
    //clear();
    while(true)
    {
    A.show();
    choice=in.nextInt();
    if(choice==1)
    {
    A.ShowStudent();
    }
    else if(choice==2)
    {
    A.AddStudent();
    }
    else if(choice==3)
    {
    A.DeleteStudent();
    }
    else if(choice==4)
    {
    A.UpdateStudent();
    }
    else if(choice==5)
    {
    A.SelsctStudent();
    }
    else
    {
    char cho=0;
    System.out.print("exit? Y/N");
    choice=in.nextInt();
    if(cho=='Y')
    break;

    }
    //clear();
    }
    }
    }

    遇到的问题就还保留有许多c++的习惯一些不常用的会习惯性的写成c++。

    明天打算学习list。

  • 相关阅读:
    FirstAFNetWorking
    JSONModel 简单例子
    KVO
    KVC
    关于UITableView的性能优化(历上最全面的优化分析)
    浅拷贝和深拷贝
    UI2_异步下载
    UI2_同步下载
    算法图解学习笔记02:递归和栈
    算法图解学习笔记01:二分查找&大O表示法
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/13368155.html
Copyright © 2020-2023  润新知