java用數組實現簡單的學生管理系統

來源:互聯網
上載者:User

標籤:

用數組存放對象,然後遍曆數組,加上一些數組的操作,很簡單,純屬記錄

import java.util.Scanner;


public class StudentManagerTwice {
    public static void main(String[] args) {
        Student1 stu = new Student1("aaa",12,1201);
        Student1 stu2 = new Student1("bbb",34,1202);
        Student1 stu3 = new Student1("ccc",14,1203);
        Student1 stu4 = new Student1("ddd",16,1204);
        Student1 stu5 = new Student1("eee",11,1204);
        
        Student1[] stus = new Student1[5];
        
        stus[0] = stu;
        stus[1] = stu2;
        stus[2] = stu3;
        stus[3] = stu4;
        stus[4] = stu5;
        
        String answer = "";
        Scanner input = new Scanner(System.in);
        System.out.println("-----welcomecome to the students manager system-----");
        do {
            
            System.out.println("     1.look all         2.query stuNum    ");
            System.out.println("     3.exit             4.without    ");
            int choice = input.nextInt();
            switch (choice) {
            case 1:
                for (int i = 0; i < stus.length; i++) {
                    System.out.println(stus[i]);
                }
                break;
            case 2:
                System.out.println("please input a stuNum: ");
                int num = input.nextInt();
                for (int i = 0; i < stus.length; i++) {
                    Student1 s = stus[i];
                    if(num == s.getStuNum()){
                        System.out.println(s);
                        break;  //這裡用break提前結束了迴圈,提高了效率,但是
                    }
                }
                break;
            case 3:
                System.exit(0);
                break;
            default:
                break;
            }
            System.out.println("continue?  <y/n>");
            answer = input.next();
        } while (answer.equals("y"));
            
    
    }
    
}



class Student1{
    private String name;
    private int age;
    private int stuNum;
    public Student1() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Student1(String name, int age, int stuNum) {
        super();
        this.name = name;
        this.age = age;
        this.stuNum = stuNum;
    }
    @Override
    public String toString() {
        return "Studetn [name=" + name + ", age=" + age + ", stuNum=" + stuNum
                + "]";
    }
    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 int getStuNum() {
        return stuNum;
    }
    public void setStuNum(int stuNum) {
        this.stuNum = stuNum;
    }
    
    
}

java用數組實現簡單的學生管理系統

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.