1.我对考试进行了复盘这个是复盘后的代码
public class Student {
//学号
private String stunumber;
//名字
private String name;
//年龄
private int age;
//性别
private boolean sex;
//得分
private double score;
public Student() {
}
public Student(String stunumber, String name, int age, boolean sex, double score) {
this.stunumber = stunumber;
this.name = name;
this.age = age;
this.sex = sex;
this.score = score;
}
/**
* 获取
* @return stunumber
*/
public String getStunumber() {
return stunumber;
}
/**
* 设置
* @param stunumber
*/
public void setStunumber(String stunumber) {
this.stunumber = stunumber;
}
/**
* 获取
* @return name
*/
public String getName() {
return name;
}
/**
* 设置
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取
* @return age
*/
public int getAge() {
return age;
}
/**
* 设置
* @param age
*/
public void setAge(int age) {
this.age = age;
}
/**
* 获取
* @return sex
*/
public boolean isSex() {
return sex;
}
/**
* 设置
* @param sex
*/
public void setSex(boolean sex) {
this.sex = sex;
}
/**
* 获取
* @return score
*/
public double getScore() {
return score;
}
/**
* 设置
* @param score
*/
public void setScore(double score) {
this.score = score;
}
public String toString() {
String s1=sex==true?"女生":"男生";
return "Student{stunumber = " + stunumber + ", name = " + name + ", age = " + age + ", sex = " + s1 + ", score = " + score + "}";
}
}
import java.util.Scanner;
public class StudentManger {
private int index;
Scanner sc=new Scanner(System.in);
private Student []student=new Student[1000];
public StudentManger(){
index=0;
while(true){
ui();
int choese=sc.nextInt();
switch (choese){
case 1:
showStudent();
break;
case 2:
addStudents();
break;
case 3:
deleteStudents();
break;
case 4:
updateStudents();
break;
case 5:
selectStudents();
break;
default:
System.out.println("输入数字异常重新输入" +
"");
break;
}
}
}
//输出
public void showStudent(){
for(int i=0;i<index;i++){
System.out.println(student[i]);
}
}
//查找
public int find(String stunumber){
for (int i = 0; i < index; i++) {
if(stunumber.equals(student[i].getStunumber()))
return i;
}
return -1;
}
//添加
public void addStudent(String stunumber,String name,int age,boolean sex,double score){
int t=find(stunumber);
if(t-1){
student[index++]=new Student(stunumber,name,age,sex,score);
System.out.println("添加成功");
}
else{
System.out.println("添加失败");
}
}
//删除
public void deleteStudent(String stunumber){
int t=find(stunumber);
if(t-1){
System.out.println("这个信息不存在");
}
else{
Student te=student[t];
student[t]=student[index-1];
student[index - 1] = te;
index--;
System.out.println("删除成功");
}
}
//修改
public void updateStudent(String stunumber,String name,int age,boolean sex,double score){
Student s=new Student(stunumber,name,age,sex,score);
int t=find(stunumber);
if(t==-1){
System.out.println("这个学生不存在");
}
else{
student[t]=s;
System.out.println("修改成功");
}
}
//查询输出信息
public void selectStudent(String stunumber){
int t=find(stunumber);
if(t==-1) System.out.println("学生信息不存在");
else {
System.out.println(student[t]);
}
}
public void ui(){
System.out.println("\n" +
" 石家庄铁道大学软件工程系学生信息管理系统\n" +
"\n" +
" 1、遍历输出学生信息;\n" +
" 2、新学生信息录入;\n" +
" 3、删除学生信息;\n" +
" 4、修改学生信息;\n" +
" 5、查询学生信息;\n" +
"***************************************************************");
}
public Student in(){
System.out.println("请输入学生信息(学号,姓名,年龄,性别(男false/女true),得分)");
String stunumber=sc.next();
String name=sc.next();
int age=sc.nextInt();
boolean sex=sc.nextBoolean();
double score=sc.nextDouble();
return new Student(stunumber,name,age,sex,score);
}
public void addStudents(){
Student s=in();
addStudent(s.getStunumber(),s.getName(),s.getAge(),s.isSex(),s.getScore());
}
public void deleteStudents(){
String s=sc.next();
deleteStudent(s);
}
public void updateStudents(){
Student s=in();
updateStudent(s.getStunumber(),s.getName(),s.getAge(),s.isSex(),s.getScore());
}
public void selectStudents(){
String s=sc.next();
selectStudent(s);
}
}
public class test {
public static void main(String[] args) {
StudentManger studentManger=new StudentManger();
}
}
标签:01,java,String,sex,score,stunumber,public,考试,name From: https://www.cnblogs.com/yuanshitianzun123/p/18423338