日期:2018.9.7
博客期:009
星期五
今天按要求来提交代码啦!本来处于小学期要写很多C++的程序代码的,Java程序的话,抽空写的。应该说写链表已经写吐了我了,想换个口味!!!嗯,下面即为源码:
package testforthis;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStreamReader;
//班级:*-****-* *
//学号:********
//姓名:**
public class StudentManager {
//---------------------------<数据区>------------------------------//
//学生数据存储区
protected student date[];
//存储数量
protected int number;
//位置存储
protected boolean save[];
//---------------------------<功能函数区>------------------------------//
//打印输出所有的学生信息
public void showStudent(){
boolean have = false;
for(int i=0;i<number;i++)
if(save[i])
{
have = true;
break;
}
if(have)
{
System.out.println("姓名 学号 性别 年龄 分数 ");
for(int i=0;i<number;i++)
if(save[i])
System.out.println(date[i].get_name()+" "+date[i].get_stunumber()+" "+date[i].get_sex()+" "+date[i].get_age()+" "+date[i].get_score());
}
else
System.out.println(" 没有存储任何数据!");
}
//增加一名新学生的信息
public void addStudent(String stunumber_s,String name_s,int age_s,boolean sex_s,double score_s){
boolean have = false;
boolean these = false;
for(int i=0;i<number;i++)
{
if(!save[i])
{
have = true;
break;
}
if(save[i]&&!these&&date[i].get_stunumber()==stunumber_s)
these = true;
}
if(these)
{
System.out.println("该学号已经录入,增添信息失败!");
return;
}
if(!have)
System.out.println("学生信息已满!");
else
{
for(int i=0;i<number;i++)
if(!save[i])
{
date[i].set(stunumber_s, name_s, sex_s, age_s, score_s);
save[i] = true;
break;
}
}
}
//删除一名学生信息
public void deleteStudent(String stunumber_s){
boolean have = false;
for(int i=0;i<number;i++)
if(save[i])
{
have = true;
break;
}
if(have)
System.out.println("还未存入任何学生信息!");
else
{
for(int i=0;i<number;i++)
if(!save[i]&&stunumber_s==date[i].get_stunumber())
{
date[i] = new student();
save[i] = false;
break;
}
}
}
//修改学生信息
public void updateStudent(int s)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入学生的信息:");
System.out.print("学号:");
date[s].stunumber = br.readLine();
System.out.print("姓名:");
date[s].name = br.readLine();
System.out.print("年龄:");
date[s].age = br.read();
System.out.print("性别:(0:男 ,1:女)");
date[s].sex = br.read()==0?false:true;
System.out.print("分数:");
date[s].score = (double) br.read();
}
//查询并且输出该名学生的全部信息
public void selectStudent(String stunumber_s){
for(int i=0;i<number;i++)
if(save[i]&&date[i].get_stunumber()==stunumber_s)
{
date[i].display();
break;
}
}
//---------------------------<窗口函数区>------------------------------//
//主菜单
public void main_win()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 石家庄铁道大学信息科学与技术学院 ");
System.out.println(" 学生信息管理系统 v2.0 ");
System.out.println("***************************************************************");
System.out.println(" 1、 遍历输出学生信息; ");
System.out.println(" 2、 新学生信息录入; ");
System.out.println(" 3、 删除学生信息; ");
System.out.println(" 4、 修改学生信息; ");
System.out.println(" 5、 查询学生信息; ");
System.out.println("***************************************************************");
System.out.println(" 请输入:");
int sea = br.read();
if(sea==0)
return;
else if(sea==1)
fun1();
else if(sea==2)
fun2();
else if(sea==3)
fun3();
else if(sea==4)
fun4();
else if(sea==5)
fun5();
else
main_win();
}
//遍历输出学生信息
public void fun1() throws IOException{
System.out.println("***************************************************************");
System.out.println(" 遍历输出学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("信息如下:");
showStudent();
main_win();
}
//新学生信息录入
public void fun2()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 新学生信息录入");
System.out.println("***************************************************************");
System.out.println("");
System.out.println(" 请输入信息以添加:");
System.out.println(" 格式:(姓名 学号 年龄 性别 分数)");
boolean t1;
int t2;
double t3;
String t4,t5;
t4 = br.readLine();
t5 = br.readLine();
t2 = br.read();
t1 = br.read()==0?false:true;
t3 = br.read();
addStudent(t5,t4,t2,t1,t3);
main_win();
}
// 删除学生信息
public void fun3()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 删除学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学号:");
String faster = br.readLine();
deleteStudent(faster);
main_win();
}
//修改学生信息
public void fun4()throws IOException{
System.out.println("***************************************************************");
System.out.println(" 修改学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学生的位置:(1~5)");
int m;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
m = br.read();
updateStudent(m);
main_win();
}
//查询学生信息
public void fun5()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 查询学生信息; ");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学号:");
String forest = br.readLine();
selectStudent(forest);
main_win();
}
//---------------------------<构造函数区>------------------------------//
//无参构造函数
public StudentManager( ){
number = 5;
student date[] = new student [5];
boolean save[] = new boolean [5];
for(int i=0;i<5;i++)
{
save[i] = false;
date[i] = new student();
}
}
//拷贝构造函数
public StudentManager(StudentManager x){
number = x.number;
boolean save [] = new boolean [number];
student date[] = new student [number];
for(int i=0;i<number;i++)
{
save[i] = x.save[i];
date[i] = x.date[i];
}
}
//主函数
public static void main(String args[])throws IOException{
StudentManager tube = new StudentManager();
tube.main_win();
}
}
//学号:********
//姓名:**
public class StudentManager {
//---------------------------<数据区>------------------------------//
//学生数据存储区
protected student date[];
//存储数量
protected int number;
//位置存储
protected boolean save[];
//---------------------------<功能函数区>------------------------------//
//打印输出所有的学生信息
public void showStudent(){
boolean have = false;
for(int i=0;i<number;i++)
if(save[i])
{
have = true;
break;
}
if(have)
{
System.out.println("姓名 学号 性别 年龄 分数 ");
for(int i=0;i<number;i++)
if(save[i])
System.out.println(date[i].get_name()+" "+date[i].get_stunumber()+" "+date[i].get_sex()+" "+date[i].get_age()+" "+date[i].get_score());
}
else
System.out.println(" 没有存储任何数据!");
}
//增加一名新学生的信息
public void addStudent(String stunumber_s,String name_s,int age_s,boolean sex_s,double score_s){
boolean have = false;
boolean these = false;
for(int i=0;i<number;i++)
{
if(!save[i])
{
have = true;
break;
}
if(save[i]&&!these&&date[i].get_stunumber()==stunumber_s)
these = true;
}
if(these)
{
System.out.println("该学号已经录入,增添信息失败!");
return;
}
if(!have)
System.out.println("学生信息已满!");
else
{
for(int i=0;i<number;i++)
if(!save[i])
{
date[i].set(stunumber_s, name_s, sex_s, age_s, score_s);
save[i] = true;
break;
}
}
}
//删除一名学生信息
public void deleteStudent(String stunumber_s){
boolean have = false;
for(int i=0;i<number;i++)
if(save[i])
{
have = true;
break;
}
if(have)
System.out.println("还未存入任何学生信息!");
else
{
for(int i=0;i<number;i++)
if(!save[i]&&stunumber_s==date[i].get_stunumber())
{
date[i] = new student();
save[i] = false;
break;
}
}
}
//修改学生信息
public void updateStudent(int s)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入学生的信息:");
System.out.print("学号:");
date[s].stunumber = br.readLine();
System.out.print("姓名:");
date[s].name = br.readLine();
System.out.print("年龄:");
date[s].age = br.read();
System.out.print("性别:(0:男 ,1:女)");
date[s].sex = br.read()==0?false:true;
System.out.print("分数:");
date[s].score = (double) br.read();
}
//查询并且输出该名学生的全部信息
public void selectStudent(String stunumber_s){
for(int i=0;i<number;i++)
if(save[i]&&date[i].get_stunumber()==stunumber_s)
{
date[i].display();
break;
}
}
//---------------------------<窗口函数区>------------------------------//
//主菜单
public void main_win()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 石家庄铁道大学信息科学与技术学院 ");
System.out.println(" 学生信息管理系统 v2.0 ");
System.out.println("***************************************************************");
System.out.println(" 1、 遍历输出学生信息; ");
System.out.println(" 2、 新学生信息录入; ");
System.out.println(" 3、 删除学生信息; ");
System.out.println(" 4、 修改学生信息; ");
System.out.println(" 5、 查询学生信息; ");
System.out.println("***************************************************************");
System.out.println(" 请输入:");
int sea = br.read();
if(sea==0)
return;
else if(sea==1)
fun1();
else if(sea==2)
fun2();
else if(sea==3)
fun3();
else if(sea==4)
fun4();
else if(sea==5)
fun5();
else
main_win();
}
//遍历输出学生信息
public void fun1() throws IOException{
System.out.println("***************************************************************");
System.out.println(" 遍历输出学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("信息如下:");
showStudent();
main_win();
}
//新学生信息录入
public void fun2()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 新学生信息录入");
System.out.println("***************************************************************");
System.out.println("");
System.out.println(" 请输入信息以添加:");
System.out.println(" 格式:(姓名 学号 年龄 性别 分数)");
boolean t1;
int t2;
double t3;
String t4,t5;
t4 = br.readLine();
t5 = br.readLine();
t2 = br.read();
t1 = br.read()==0?false:true;
t3 = br.read();
addStudent(t5,t4,t2,t1,t3);
main_win();
}
// 删除学生信息
public void fun3()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 删除学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学号:");
String faster = br.readLine();
deleteStudent(faster);
main_win();
}
//修改学生信息
public void fun4()throws IOException{
System.out.println("***************************************************************");
System.out.println(" 修改学生信息");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学生的位置:(1~5)");
int m;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
m = br.read();
updateStudent(m);
main_win();
}
//查询学生信息
public void fun5()throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("***************************************************************");
System.out.println(" 查询学生信息; ");
System.out.println("***************************************************************");
System.out.println("");
System.out.println("请输入学号:");
String forest = br.readLine();
selectStudent(forest);
main_win();
}
//---------------------------<构造函数区>------------------------------//
//无参构造函数
public StudentManager( ){
number = 5;
student date[] = new student [5];
boolean save[] = new boolean [5];
for(int i=0;i<5;i++)
{
save[i] = false;
date[i] = new student();
}
}
//拷贝构造函数
public StudentManager(StudentManager x){
number = x.number;
boolean save [] = new boolean [number];
student date[] = new student [number];
for(int i=0;i<number;i++)
{
save[i] = x.save[i];
date[i] = x.date[i];
}
}
//主函数
public static void main(String args[])throws IOException{
StudentManager tube = new StudentManager();
tube.main_win();
}
}