score.java
package score;
public class score {
String name;
String num;
int age;
boolean sex;
double score;
String one;
public score() {
}
public void setnum(String num)
{
this.num=num;
}
public void setname(String name) {
this.name=name;
}
public void setscore(double score) {
this.score=score;
}
public void setage(int age)
{
this.age=age;
}
public void setsex(String one) {
this.one=one;
if(one.equals("男")==true) {
sex=true;
}
if(one.equals("女")==true) {
sex=false;
}
}
}
Scorein.java
package score;
import java.util.Scanner;
public class Scorein {
int maxlength=100;
int length=0;
score[] data=new score[maxlength];
Scanner input=new Scanner(System.in);
public Scorein(){
}
//添加
public void add()
{
if(length<maxlength) {
data[length]=new score();
System.out.println("请输入学生学号:");
data[length].setnum(input.next());
System.out.println("请输入学生姓名:");
data[length].setname(input.next());
System.out.println("请输入学生性别:");
data[length].setsex(input.next());
System.out.println("请输入学生年龄:");
data[length].setage(input.nextInt());
System.out.println("请输入学生成绩:");
data[length].setscore(input.nextDouble());
length++;
System.out.println("添加成功!");
}
else {
System.out.println("添加失败!超过人数!");
}
}
public void display() {
System.out.println("************************************************");
System.out.println("学号"+"\t\t"+"姓名"+"\t"+"性别"+"\t"+"年龄"+"\t"+"成绩");
for(int i=0;i<length;i++) {
System.out.print(data[i].num+"\t"+data[i].name+"\t");
if(data[i].sex) {
System.out.print("男"+"\t");
}
else {
System.out.print("女"+"\t");
}
System.out.println(data[i].age+"\t"+data[i].score);
}
System.out.println("************************************************");
}
//删除
public void delete() {
System.out.println("请输入要删除的学生的学号:");
String num1=input .next();
int i,thought_1=length;
for(i=0;i<thought_1;i++) {
if(num1.equals(data[i].num)) {
thought_1=i;
break;
}
}
if(i==thought_1) {
System.out.println("此人不存在!");
delete();
}
else {
for(int j=i;j<length;j++) {
data[j]=data[j+1];
}
System.out.println("删除成功!");
length-=1;
}
}
//查询
public void search() {
System.out.println("请输入您要查询的学生学号:");
String num2=input.next();
int i;
for(i=0;i<length;i++) {
if(num2.equals(data[i].num)) {
System.out.println("************************************************");
System.out.println("学号"+"\t\t"+"姓名"+"\t"+"性别"+"\t"+"年龄"+"\t"+"成绩");
System.out.print(data[i].num+"\t"+data[i].name+"\t");
if(data[i].sex) {
System.out.print("男"+"\t");
}
else {
System.out.print("女"+"\t");
}
System.out.println(data[i].age+"\t"+data[i].score);
System.out.println("************************************************");
break;
}
}
if(i==length) {
System.out.println("此人不存在!请重新输入:");
search();
}
}
//修改
public void change() {
System.out.println("请输入您要修改学生的学号");
String num3=input.next();
int i;
for(i=0;i<length;i++) {
if(num3.equals(data[i].num)) {
break;
}
}
if(i==length) {
System.out.println("此人不存在!请重新输入:");
change();
}
System.out.println("请输入修改的学号:");
data[i].setnum(input.next());
System.out.println("请输入修改的姓名:");
data[i].setname(input.next());
System.out.println("请输入修改的性别:");
data[i].setsex(input.next());
System.out.println("请输入修改的年龄:");
data[i].setage(input.nextInt());
System.out.println("请输入修改的成绩:");
data[i].setscore(input.nextDouble());
System.out.println("修改完成!");
}
}
Main.java
package score;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String choice="1";
Scorein aScorein=new Scorein();
Scanner input=new Scanner(System.in);
System.out.println("*********************************************");
System.out.println("\t石家庄铁道大学信息科学与技术学院");
System.out.println(" 学生信息管理系统V2.0");
System.out.println("*********************************************");
while(choice.equals("0")==false) {
System.out.println("\t\t1.添加学生信息");
System.out.println("\t\t2.显示学生信息");
System.out.println("\t\t3.查询学生信息");
System.out.println("\t\t4.修改学生信息");
System.out.println("\t\t5.删除学生信息");
System.out.println("\t\t0.退出系统");
System.out.println("\t\t请输入您的操作:");
choice=input.next();
switch(choice) {
case "0":
System.out.println("谢谢您的使用!程序即将退出。");
break;
case "1":
aScorein.add();
break;
case "2":
aScorein.display();
break;
case "3":
aScorein.search();
break;
case "4":
aScorein.change();
break;
case "5":
aScorein.delete();
break;
default:
System.out.println("您的输入有误!请重新输入:");
break;
}
}
}
}