小型学生管理系统的架构设计
程序员文章站
2022-06-01 23:20:06
...
package Studentdemain;
public class Student {
private String name;
private int age ;
private int score;
private int sid;
//构造方法
public Student(String name, int age, int score, int sid) {
super();
this.name = name;
this.age = age;
this.score = score;
this.sid = sid;
}
//shou方法
public void show(){
System.out.println("学生姓名:"+name+"学生年龄:"+age+"学生分数:"+score+"学生学号:"+sid);
}
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 getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
}
//测试类
package StudentTest;
import java.util.Scanner;
import Studentdemain.Student;
public class StudentTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean flag = true;
Student[] student = new Student[3];
Scanner input = new Scanner(System.in);
Scanner input1 = new Scanner(System.in);
while (true) {
System.out.println("------------小商品管理系统-----------");
System.out.println("1:录入学生信息");
System.out.println("2:查看学生信息");
System.out.println("0:退出系统");
System.out.print("请选择:");
int num = input1.nextInt(); // 从键盘获得的第一个值
String name;
int age;
int score;
int sid;
switch (num) {
case 1: {
for (int i = 0; i < 3; i++) {
System.out.print("请输入第"+(i+1)+"个学生姓名:");
name = input.nextLine();
System.out.print("请输入第"+(i+1)+"个学生年龄");
age = input1.nextInt();
System.out.print("请输入第"+(i+1)+"个学生分数");
score = input1.nextInt();
System.out.print("请输入第"+(i+1)+"个学生学号");
sid = input1.nextInt();
do{
if(score<=100 && score>0){
flag=false;
}else{
System.out.println("分数输入不正确");
System.out.println("请重新输入分数");
score=input1.nextInt();
break;
}
}while(flag);
student[i] = new Student(name, age, score, sid);
}
}break;
case 2:{
for(Student st:student){
st.show();
}
}break;
case 0:{
System.out.println("退出系统成功");
}
}
}
}
}
下一篇: PHP实现简单高精度的求PI方法