您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 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;ilistlen;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;ifiles.length;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);}//endwhileinFile.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;ifile.length;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(encryptioniscomplete!);System.out.println(decrypt:inuputdecr
三七文档所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
本文标题:java基于命令行的学生成绩管理系统
链接地址:https://www.777doc.com/doc-4567562 .html