java student数组_java用数组实现简单的学生管理系统

标签:

用数组存放对象,然后遍历数组,加上一些数组的操作,很简单,纯属记录

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?  ");

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;

}

}

标签:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值