天天看点

java小学期实验报告_大一java小学期作业学生管理信息系统

package summerPractice;

import java.util.NoSuchElementException;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Arrays;

import java.util.Iterator;

import java.util.Scanner;

public class Home {

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Scanner input=new Scanner(System.in);

//实验文档数据转换

//确定学生人数

//out1和out2为操作是的试验文本

System.out.println("先将信息按:学号+名字+性别+高数+马列+C语言+计技基础的格式输入到data/output.txt文档中;输入out 退出,输入任意字符进入系统。");String enter=input.next();

//判断是否进入系统

while(!enter.equals("out")){

CopyRight.CopyRight(1);//版权书写

int studentNum=0;Scanner outS=new Scanner(new File("data/output.txt"));

PrintWriter out1=new PrintWriter(new File("data/out1.txt"));PrintWriter out2=new PrintWriter(new File("data/out2.txt"));

while(outS.hasNext()){

for(int i=0;i<3;i++){if(i!=2)out1.print(outS.next()+"  "); else out1.println(outS.next());}

for(int i=0;i<5;i++){if(i!=4)out2.print(outS.nextInt()+"  "); else out2.println(outS.nextInt());}

studentNum++;

}outS.close();out1.close();out2.close();

//System.out.println(studentNum);//检验学生人数

//将原始数据信息和分数分别复制到student.txt和scores.txt文档中

PrintWriter studentData=new PrintWriter(new File("data/student.txt"));

PrintWriter scoresData=new PrintWriter(new File("data/student1.txt"));

Scanner dataSource=new Scanner (new File("data/output.txt"));

while(dataSource.hasNext()){

for(int n=0;n<3;n++){if(n!=2)studentData.print(dataSource.next()+"    ");else studentData.println(dataSource.next());}

for(int n=0;n<5;n++){if(n!=4)scoresData.print(dataSource.nextInt()+"    ");else scoresData.println(dataSource.next());}

}studentData.close();scoresData.close();scoresData.close();

String[][] student=new String[studentNum][3];String[][] student1=new String[studentNum][3];

int[][] scores=new int[studentNum][5];

Scanner source=new Scanner(new File("data/student.txt"));

Scanner source1=new Scanner(new File("data/student1.txt"));

//基本信息二维数组student;

for(int i=0;i

int n=0;while(source.hasNext()&&n<=2){

student [i][n]=source.next();String s=student[i][n];student1[i][n]=s;//student1为原始基本信息数组

n++;

}

}source.close();

//成绩二维数组scores;一行为个人高数。英语。马列,C语言,计技基础的成绩

for(int i=0;i

int n=0;while(source1.hasNext()&&n<=4){

scores [i][n]=source1.nextInt();n++;

}

}source1.close();

//个人各科分数求和,输入列,存入Sum数组中

double[] Sum=new double[studentNum];

for(int i=0;i

double sum=0;for(int n=0;n<5;n++){

sum=sum+scores [i][n];

}Sum[i]=sum;

}

//实现总分排名输出和排名检索: 将数组按总分排名写出

for(int i=0;i

String[] turn1=new String[3];int[] turn2=new int[5];

double max=Sum[i];for(int n=i+1;n

if(Sum[n]>max){

max=Sum[n];Sum[n]=Sum[i];Sum[i]=max;//总分替换

turn1=student[i];student[i]=student[n];student[n]=turn1;//替换基本信息

turn2=scores[i];scores[i]=scores[n];scores[n]=turn2;//替换各科分数数组

}

}

}//for(int i=0;i<10;i++){System.out.println(Sum[i]+student[i][1]);}总分打印检验,数组已经是按总分排名

System.out.println("共:"+studentNum+"名学生"+"输入操作类型case:(0:基本信息;1:修改信息;2:总分排名打印;3:单科数据;4:总分排名查询;5:基本信息查询;6:打印成绩报表)");

int type=input.nextInt();

switch(type){

//显示学生基本信息

case 0:

for(int i=0;i

System.out.println(Arrays.toString(student1[i]));

}break;

case 1:

//修改信息

System.out.println("信息修改,输入1增加个人数据,输入2删除个人数据,输入3更改已有人员信息:");

int update=input.nextInt();PrintWriter output = new PrintWriter(new FileWriter("data/output.txt", true));

PrintWriter outputData = new PrintWriter(new FileWriter("data/testData.txt", true));

//增加档案

if(update==1){

System.out.println("请输入增加人:");

int i=input.nextInt();System.out.println("输入学号+姓名+性别+高数+英语+马列+c语言+计技基础:");

for(int t=0;t

for(int n=0;n<3;n++){String s=input.next();output.print(s+"  ");}

for(int n=0;n<5;n++){int num=input.nextInt();if(n!=4)output.print(num+ "  ");else output.println(num);}

}

output.close();outputData.close();System.out.println("操作成功,数据保存在data/output.txt文档中");

}

//删除档案

else if(update==2){

System.out.println("输入个人信息:学号或姓名:");java.io.File file=new java.io.File("data/output.txt");

String s=input.next();int count=-1;

for(int i=0;i

if(s.equals(student[i][0])||s.equals(student[i][1])){

count=i;

}

}

if(count>=0){System.out.println("即将删除的信息为:"+Arrays.toString(student[count])+" "+Arrays.toString(scores[count])+"输入yes删除,输入其他则取消:");

String yes=input.next();

if(yes.equals("yes")){DelectAims.delectAims(file, s);

Scanner delSource=new Scanner (new File("data/delMid.txt"));PrintWriter delRusult=new PrintWriter(new File("data/output.txt"));

while(delSource.hasNextLine()){

delRusult.println(delSource.nextLine());

}delSource.close();delRusult.close();System.out.println("操作成功,数据保存在原文档data/output.txt中");

}

else System.out.println("取消删除成功!");

}

else System.out.println("没有该学生信息,请重新操作。");

}

//修改个人信息

else {

System.out.println("输入名字和修改科目(1-5):高数1;英语2;马列3;c语言;计技基础5和新的分数");String name=input.next();int subject=input.nextInt();int num=input.nextInt();

for(int i=0;i

if(student[i][1].equals(name)||student[i][0].equals(name)){

System.out.println();scores[i][subject-1]=num;System.out.println(scores[i][subject-1]);

}

}

PrintWriter editMid=new PrintWriter(new File("data/editMid.txt"));

for(int i=0;i

for(int n=0;n<3;n++){editMid.print(student[i][n]+" ");}//打印到文档

for(int n=0;n<5;n++){if(n!=4)editMid.print(scores[i][n]+" ");else editMid.println(scores[i][n]);}

}editMid.close();//需要确定文档名

Scanner editSource=new Scanner(new File("data/editMid.txt"));PrintWriter editResult=new PrintWriter(new File("data/output.txt"));

while(editSource.hasNextLine()){

editResult.println(editSource.nextLine());

}editSource.close();editResult.close();

System.out.println("操作成功,数据保存在data/output.txt文档中");

System.out.println(Arrays.toString(student[1])+" "+Arrays.toString(scores[1]));

}

break;

case 2:

//总分统计

java.io.PrintWriter sumData=new java.io.PrintWriter("data/总分统计.txt");

for(int i=0;i

sumData.print(Arrays.toString(student[i]));sumData.println(Sum[i]);

}sumData.close();System.out.println("数据保存于data/总分统计.txt文档中");

break;

case 3:

//单科最高分和最低分:保存到SumSingle数组中。平均分保存到SingleAverage数组中

double[] maxSingle=new double[5];double[] SingleAverage=new double[5];double[] minSingle=new double[5];

double sum1=0;double sum2=0;double sum3=0;double sum4=0;double sum5=0;double max=0;double min=0;

//单科平均分

for(int i=0;i

sum1+=scores[i][0];sum2+=scores[i][1];sum3+=scores[i][2];sum4+=scores[i][3];sum5+=scores[i][4];

}

SingleAverage[0]=(sum1*1.0)/studentNum;SingleAverage[1]=((sum2)*1.0)/studentNum;SingleAverage[2]=(sum3*1.0)/studentNum;

SingleAverage[3]=(sum4*1.0)/studentNum;SingleAverage[4]=(sum5*1.0)/studentNum;

//单科最高分和最低分

for(int n=0;n<5;n++){

max=scores[0][n];min=scores[0][n];

for(int i=1;i

if(scores[i][n]>max) max=scores[i][n];

else if(scores[i][n]

}

maxSingle[n]=max;minSingle[n]=min;

}

PrintWriter singleData=new PrintWriter("data/各科目数据.txt");//输出到文档

singleData.println("data    高数    英语      马列    c语言  计技基础");

singleData.print("最高分:  ");for(int i=0;i<5;i++){if(i!=4)singleData.print(maxSingle[i]+"    ");else singleData.println(maxSingle[i]);}

singleData.print("最低分:  ");for(int i=0;i<5;i++){if(i!=4)singleData.print(minSingle[i]+"    ");else singleData.println(minSingle[i]);}

singleData.print("平均分:  ");for(int i=0;i<5;i++){if(i!=4)singleData.print(SingleAverage[i]+"    ");else singleData.println(SingleAverage[i]);}

singleData.close();

System.out.println("操作成功:显示为单科最高分,最低分和平均分(数据保存在data/各科目数据.txt中)");

System.out.println("最高分:"+Arrays.toString(maxSingle)+"最低分:"+Arrays.toString(minSingle)+"平局分:"+Arrays.toString(SingleAverage));//打印检验

break;

case 4:

//按总分排名查询

System.out.println("输入总分名次:");int degree=input.nextInt();

System.out.println("第"+(degree)+"名:"+Arrays.toString(student[degree-1])+Sum[degree-1]);//排名检索实现

break;

case 5:

//按信息查询结果

System.out.println("请输入要查询的基本信息:名字,学号,性别");String s=input.next();

for(int i=0;i

for(int n=0;n<3;n++){

if(s.equals(student[i][n])){

System.out.println("该人信息为:"+Arrays.toString(student[i])+" 高数:"+scores[i][0]+" 英语:"+scores[i][1]+" 马列:"+scores[i][2]

+" c语言:"+scores[i][3]+" 计技基础:"+scores[i][4]+"总分:"+Sum[i]+"总分第"+(i+1)+"名");

}

}

}break;

case 6:

//打印成绩报表

PrintWriter form=new PrintWriter("data/成绩报表.txt");form.println("                班级成绩报表                         ");

form.println("学号        姓名    高数    英语   马列  c语言 计技基础  总分  ");

for(int i=0;i

for(int n=0;n<2;n++){form.print(student[i][n]+"     ");}

for(int n=0;n<5;n++){form.print(scores[i][n]+"     ");}

form.println(" "+Sum[i]);

}form.close();

System.out.println("操作成功,数据保存在data/成绩报表.txt中");

break;

default://输入无效是报错。

System.out.println("输入无效!\n系统自动退出");

break;

}

System.out.println("继续输入任意数字,退出输入out");

enter=input.next();

}

System.out.println("已经安全退出系统!");

}

}