java基于命令行的学生成绩管理系统.docx
- 文档编号:5039846
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:13
- 大小:19.50KB
java基于命令行的学生成绩管理系统.docx
《java基于命令行的学生成绩管理系统.docx》由会员分享,可在线阅读,更多相关《java基于命令行的学生成绩管理系统.docx(13页珍藏版)》请在冰豆网上搜索。
java基于命令行的学生成绩管理系统
《面向对象程序设计与C++》实验报告
年级、专业、班级
2011级计科4班
2011级计科4班
2011级计科4班
XX
实验题目
基于命令行的学生成绩管理系统
实验时间
2013.10.16~2013.10.23
实验地点
A主414
实验成绩
实验性质
□验证性□设计性■综合性
教师评价:
□算法/实验过程正确;□源程序/实验容提交□程序结构/实验步骤合理;
□实验结果正确;□语法、语义正确;□报告规;
其他:
评价教师签名:
一、实验目的
运用面向对象程序设计思想,使用Java集合框架,实现对学生成绩的管理。
二、实验项目容
1、设计学生类接口;
2、使用集合框架,实现学生成绩的插入、通过名字查询、显示各科成绩排名列表、显示各科成绩通过的排名列表。
3、将存中的集合框架对象进行持久化,下一次运行系统时可直接调用。
三、实验过程或算法(源程序)
packagefilemanager;
importjava.io.*;
importjava.security.*;
importjava.util.*;
importjavax.crypto.*;
publicclassFileManager{
publicstaticvoidmain(String[]args)throwsException{
MainMenumainmenu=newMainMenu();
mainmenu.StartMenu();
}
}
classCreateFile{
CreateFile()throwsIOException{
Scanners=newScanner(System.in);
System.out.println("Wheretocreate?
(D:
/aaa/...)");
StringCurrentDirectory=s.next();
Filefile=newFile(CurrentDirectory);
if(file.exists()){
System.out.println("Enterthename:
");
StringName=s.next();
Filef=newFile(CurrentDirectory+File.separator+Name);//实例化File类的对象
f.mkdir();
System.out.println("successtocreate!
");
}elseSystem.out.println("thedirectoryisn'texist!
");
}
}
classDeleteFile{
Filepath;
publicDeleteFile(Filepath){
this.path=path;
}
publicvoidDelete(Filepath){
Filefilelist[]=path.listFiles();
intlistlen=filelist.length;
for(inti=0;i if(filelist[i].isDirectory()){ Delete(filelist[i]); } else{ filelist[i].delete(); } } path.delete();//删除当前目录 } voidSuccess(){ System.out.println("Successtodelete! ! : "); } } classEnterDirectory{ EnterDirectory(Stringpath)throwsIOException{ Runtime.getRuntime().exec("explorer.exe"+path); } } classListDirectory{ ListDirectory(Stringpath){ //Stringluj=null;//路径 //如果dir不以文件分隔符结尾,自动添加文件分隔符 if(! path.endsWith(File.separator)){ path=path+File.separator; } FiledirFile=newFile(path); //如果dir对应的文件不存在,或者不是一个文件夹则退出 if(! dirFile.exists()||(! dirFile.isDirectory())){ System.out.println("Listfailed! cannotfindthedirectory: "+path); } //list方法返回该目录下的所有文件(包括目录)的文件名,文件名不含路径信息 System.out.println(path+"containsbelowdirectoriseorfiles"); String[]files=dirFile.list(); for(inti=0;i System.out.println(files[i]); } } } classCopyFile{ CopyFile(Stringsource,Stringdest)throwsIOException{ Filein=newFile(source); Fileout=newFile(dest); FileInputStreaminFile=newFileInputStream(in); FileOutputStreamoutFile=newFileOutputStream(out); byte[]buffer=newbyte[1024]; inti=0; while((i=inFile.read(buffer))! =-1){ outFile.write(buffer,0,i); }//endwhile inFile.close(); outFile.close(); System.out.print("Successtocopy! "); } } classCopyDirectory{ publicvoidcopyFolder(StringoldPath,StringnewPath){ try{ (newFile(newPath)).mkdirs();//如果文件夹不存在则建立新文件夹 Filea=newFile(oldPath); String[]file=a.list(); Filetemp=null; for(inti=0;i if(oldPath.endsWith(File.separator)){ temp=newFile(oldPath+file[i]); } else{ temp=newFile(oldPath+File.separator+file[i]); } if(temp.isFile()){ FileInputStreaminput=newFileInputStream(temp); FileOutputStreamoutput=newFileOutputStream(newPath+"/"+ (temp.getName()).toString()); byte[]b=newbyte[1024*5]; intlen; while((len=input.read(b))! =-1){ output.write(b,0,len); } output.flush(); output.close(); input.close(); } if(temp.isDirectory()){//如果是子文件夹 copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]); } } } catch(Exceptione){ System.out.println("复制整个文件夹容操作出错"); e.printStackTrace(); } } publicvoidSuccess(){ System.out.println("Successtocopythedirectory! "); } } classTestDES{ Keykey; publicTestDES(){} publicTestDES(Stringstr){ getKey(str);//生成密匙 } /** *根据参数生成KEY */ publicvoidgetKey(StringstrKey){ try{ KeyGenerator_generator=KeyGenerator.getInstance("DES"); _generator.init(newSecureRandom(strKey.getBytes())); this.key=_generator.generateKey(); _generator=null; } catch(Exceptione){ thrownewRuntimeException("ErrorinitializingSqlMapclass.Cause: "+e); } } /* *文件file进行加密并保存目标文件destFile中 * *paramfile要加密的文件如c: /test/srcFile.txt *paramdestFile加密后存放的文件名如c: /加密后文件.txt */ publicvoidencrypt(Stringfile,StringdestFile)throwsException{//【具体用法见主函数】 Ciphercipher=Cipher.getInstance("DES"); //cipher.init(Cipher.ENCRYPT_MODE,getKey()); cipher.init(Cipher.ENCRYPT_MODE,this.key); InputStreamis=newFileInputStream(file); OutputStreamout=newFileOutputStream(destFile); CipherInputStreamcis=newCipherInputStream(is,cipher); byte[]buffer=newbyte[1024]; intr; while((r=cis.read(buffer))>0){ out.write(buffer,0,r); } cis.close(); is.close(); out.close(); } /* *文件采用DES算法解密文件 * *paramfile已加密的文件如c: /加密后文件.txt **paramdestFile *解密后存放的文件名如c: /test/解密后文件.txt */ publicvoiddecrypt(Stringfile,Stringdest)throwsException{ Ciphercipher=Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE,this.key); InputStreamis=newFileInputStream(file); OutputStreamout=newFileOutputStream(dest); CipherOutputStreamcos=newCipherOutputStream(out,cipher); byte[]buffer=newbyte[1024]; intr; while((r=is.read(buffer))>=0){ cos.write(buffer,0,r); } cos.close(); out.close(); is.close(); } voidDES()throwsException{ System.out.println("inuputencryptedpassword: "); Scannerscan=newScanner(System.in); Stringtd1=scan.nextLine();//以上两行用来实现字符串的输入。 TestDEStd=newTestDES(td1);//【对称加密的密码所在】 System.out.println("encrypt: inuputsourcefileandtargetfile: "); Stringsourcee=scan.next(); Stringtargete=scan.next(); td.encrypt(sourcee,targete);//加密 System.out.println("encryptionisplete! "); System.out.println("decrypt: inuputdecryptionedpassword: "); Scannerscanf=newScanner(System.in); Stringtd2=scanf.nextLine(); TestDEStdd=newTestDES(td2); System.out.println("decrypt: inuputsourcefileandtargetfile: "); Stringsourced=scan.next(); Stringtargetd=scan.next(); tdd.decrypt(sourced,targetd);//解密 System.out.println("decryptionisplete"); } } classMainMenu{ voidStartMenu()throwsException{ System.out.println("Choosewhattodo: "); System.out.println("'1': Createadirectory"); System.out.println("'2': Deleteadirectory"); System.out.println("'3': Enteradirectory"); System.out.println("'4': Listadirectory"); System.out.println("'5': Copyafile"); System.out.println("'6': Copyadirectory"); System.out.println("'7': Encryptafile"); System.out.println("'0': Exit"); Scanners=newScanner(System.in); inta=s.nextInt(); while(true){ switch(a){ case1: System.out.println("youchoose1"); newCreateFile(); break; case2: System.out.println("youchoose2"); System.out.println("inputthedirectorynamethatyouwanttodelete: "); Filepathtodele=newFile(s.next()); if(pathtodele.exists()){ DeleteFileDeleteDirectory=newDeleteFile(pathtodele); DeleteDirectory.Delete(DeleteDirectory.path); DeleteDirectory.Success(); }elseSystem.out.println("Cannotfindthedirectory: "+pathtodele); break; case3: System.out.println("youchoose3"); System.out.println("inputthedirectorythatyouwanttoenter: "); Stringpathtoenter=s.next(); newEnterDirectory(pathtoenter); break; case4: System.out.println("youchoose4"); System.out.println("inputthedirectorynamethatyouwanttolist: "); Stringpathtolist=s.next(); newListDirectory(pathtolist); break; case5: System.out.println("youchoose5"); System.out.println("inputthesourcefileandthetargetfile: "); Stringsourcef=s.next(); Stringdestf=s.next(); newCopyFile(sourcef,destf); break; case6: System.out.println("youchoose6"); CopyDirectorycopydirectory=newCopyDirectory(); System.out.println("inputthesourcedirectory: "); Stringsourcedir=s.next(); System.out.println("inputthetargetdirectory: "); Stringdestdir=s.next(); copydirectory.copyFolder(sourcedir,destdir); copydirectory.Success(); break; case7: System.out.println("youchoose7"); TestDEStestdes=newTestDES(); testdes.DES(); break; case0: System.out.println("youchoosetoexit"); System.exit(0); default: System.out.print("error"); } a=s.nextInt(); } } } 四、实验结果及分析和(或)源程序调试过程 备注: 1、教师在布置需撰写实验报告的实验前,应先将报告书上的“实验题目”、“实验性质”、“实验目的”、“实验项目容”等项目填写完成,然后再下发给学生。 2、教师在布置需撰写报告的实验项目时,应告知学生提交实验报告的最后期限。 3、学生应按照要求正确地撰写实验报告: 1)在实验报告上正确地填写“实验时间”、“实验地点”等栏目。 2)将实验所涉及的源程序文件容(实验操作步骤或者算法)填写在“实验过程或算法(源程序)”栏目中。 3)将实验所涉及源程序调试过程(输入数据和输出结果)或者实验的分析容填写在“实验结果及分析和(或)源程序调试过程”栏目中。 4)在实验报告页脚的“报告创建时间: ”处插入完成实验报告时的日期和时间。 5)学生将每个实验完成后,按实验要求的文件名通过网络提交(上载)到指定的服务器所规定的共享文件夹中。 每个实验一个电子文档,如果实验中有多个电子文档(如源程序或图形等),则用WinRAR压缩成一个压缩包文档提交,压缩包文件名同实验报告文件名(见下条)。 6)提交的实验报告电子文档命名为: “组号(2位数字)年级(两位数字不要“级”字)专业(缩写: 计算机科学与技术专业(计科)、网络工程专业(网络)、信息安全专业(信息)、物联网工程(物联网))项目组成员(学号(八位数字))实验序号(一位数字).doc。 如第1组完成第1个Project,专业为“计算机科学与技术”专业,项目组成员有: 三(学号20115676),四(学号20115676),王五(学号20115676),完成的课程设计报告命名为: 01_10计科_20115676三_20115676四_20115676王五1.doc,以后几次实验的报告名称以此类推。 4、教师(或助教)在评价学生实验时,应根据其提交的其他实验相关资料(例如源程序文件等)对实验报告进行仔细评价。 评价后应完成的项目有: 1)在“成绩”栏中填写实验成绩。 每个项目的实验成绩按照五级制(优、良、中、及格、不及格)方式评分,实验总成绩则通过计算每个项目得分的平均值获得(平均值计算时需将五级制转换为百分制优=95、良=85、中=75、及格=65、不及格=55)。 2)在“教师评价”栏中用符号标注评价项目结果(用√表示正确,用×表示错误,用≈表示半对半错)。 3)在“教师评价”栏中“评价教师签名”填写评价教师(或助教)。 将评价后的实验报告转换为PDF格式文件归档。 4)课程实验环节结束后,任课教师将自己教学班的实验报告文件夹进行清理。 在提交文件夹中,文件总数为实验次数×教学班学生人数(如,教学班人数为90人,实验项目为5,其文件数为: 90×5=450)。 任课教师一定要认真清理,总数相符,否则学生该实验项目不能得分。 最后将学生提交的实验报告刻光盘连同实验成绩一起放入试卷袋存档。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 基于 命令行 学生 成绩管理系统