本篇文章记录的是作者在编写大学生创新课题项目管理系统的一些感受以及具体的代码实现,希望能够通过本篇文章给大家的编程学习带来一些帮助!
项目简介:
随着教育部对培养大学生创新创业能力的要求进一步提高,信息化时代的到来,互联网+等大学生创新创业实训项目在最近几年进一步的兴起,能够快速,准确的找到与大学生创新创业项目相关的课题,查找本学校对大学生创新创业项目相关授课指导教师,成为当代致力参加大学生创新创业实践项目的学生迫切需求。该系统致力于解决该问题,为大学生创新实践提供便利。
开发背景:
随着互联网时代的到来,IT行业的兴起,实现信息间的交互性显得更加重要,通过技术手段解决用户在查找、登记信息遇到的困难,减少人力、物力的消耗成为各企业发展的刚需。目前已经有部分高校为了提高大学生创新创业能力,将本校大学生创业相关的信息录入大学生创新创业系统,以解决学生寻找指导教师,借鉴前辈经验的困难。
借助该平台,准备参与大学生创新创业实训的学生还能够查找学校提供的大学生创业工作室信息,可以满足团队讨论的需求。
鉴于部分大学生有思维、勇于挑战但是时间观念不强,不注意创新创业项目申报时间的问题,该系统设计了大创比赛信息模块,对即将举办的比赛做到实时更新,满足同学实时掌握大赛具体信息的需求
为了便于广大师生借鉴前辈经验,设计大创作品信息模块,将比赛级别分为国家级、省级、市级三个级别,用户可以根据自身需求,查找不同级别的作品信息。
由此,通过大学生创新课题项目管理系统可以有效实现网络化办公,形成一个指导教师与参赛学生动态交流的网络环境,有效促进师生对创新创业能力培养的热情,全面、准确的为师生提供有关创新比赛的各项信息。有鉴于此,该系统能够有效的为创新教育研究机构,高校创新创业学院等单位使用,提供高效信息管理与信息交互,同时还能够为参赛人员提供真实、有效的依据。
开发环境:
使用eclipse,JDK1.7版本
模块分为四个部分:
指导教师模块
大创作品信息模块
大创比赛信息模块
大创工作室模块
存储数据使用的是txt文件。
具体四个txt文件如下:
**
public class Adviser {
private String wnumber; //工号
private String wname; //姓名
private String wsex; //性别
private String wrank; //职称
private String wacedemy;//所属学院
public String getWnumber() {
return wnumber;
}
public void setWnumber(String wnumber) {
this.wnumber = wnumber;
}
public String getWname() {
return wname;
}
public void setWname(String wname) {
this.wname = wname;
}
public String getWsex() {
return wsex;
}
public void setWsex(String wsex) {
this.wsex = wsex;
}
public String getWrank() {
return wrank;
}
public void setWrank(String wrank) {
this.wrank = wrank;
}
public String getWacedemy() {
return wacedemy;
}
public void setWacedemy(String wacedemy) {
this.wacedemy = wacedemy;
}
}
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class TeacherDemo {
//文件存放路径
private String path = "d:\\指导教师.txt";
//判断是否退出系统
private static boolean pd=true;
public static void main(String[] args)throws IOException {
while (pd) {
TeacherDemo teacherDemo = new TeacherDemo();
//功能提示信息
teacherDemo.Tips();
//功能选择
teacherDemo.function(teacherDemo);
//循环间隔
System.out.println(" ");
}
}
//功能提示
public void Tips() {
System.out.println("******欢迎使用大学生创新课题项目管理系统******");
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("@请选择你要使用的功能@");
}
//功能选择
public void function(TeacherDemo teacherDemo) throws IOException {
switch (teacherDemo.ScannerInt()) {
//查询所有指导教师信息
case 1:
teacherDemo.showteacher(teacherDemo.path);
break;
//添加指导教师信息
case 2:
teacherDemo.addTeacher(teacherDemo.path);
break;
//更改指导教师信息
case 3:
teacherDemo.updateteacher(teacherDemo.path);
break;
//删除指导教师信息
case 4:
teacherDemo.deleteteacher(teacherDemo.path);
break;
//退出
case 5:
pd=false;
break;
//输入无效
default: {
System.out.println("请重新输入");
//再次输入
function(teacherDemo);
break;
}
}
}
//输入功能
public int ScannerInt() {
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
return y;
}
//输入指导教师信息
public String scannerString() {
Scanner scanner = new Scanner(System.in);
String x = scanner.next().toString();
return x;
}
/*
读数据 利用ArrayList动态数组
*/
//显示所有指导教师信息
void showteacher(String path) throws IOException {
//读数据到集合中
ArrayList<Adviser> teacherArrList = new ArrayList<Adviser>();
//0是判断
readData("0", path, teacherArrList);
if (teacherArrList.size() == 0) {
System.out.println("无可查询信息");
return;
}
print(teacherArrList);
}
//输出信息
static void print(ArrayList<Adviser> teacherArrList) {
for (int i = 0; i < teacherArrList.size(); i++) {
Adviser adviser = teacherArrList.get(i);
System.out.println(adviser.getWnumber()+" "+adviser.getWname()+" "+adviser.getWsex()+" "+adviser.getWrank()+" "+adviser.getWacedemy());
}
}
//保存对象信息
public static Adviser teacher(String[] str){
Adviser teacher = new Adviser();
teacher.setWnumber(str[0]);
teacher.setWname(str[1]);
teacher.setWsex(str[2]);
teacher.setWrank(str[3]);
teacher.setWacedemy(str[4]);
return teacher;
}
//将文件读入集合
static void readData(String onlyteacher, String path, ArrayList< Adviser> teacherArrList) throws IOException {
//利用处理流提高性能
Scanner scanner = new Scanner(new FileInputStream(path), "GBK").useDelimiter("\\A");
String fileContent = scanner.hasNext() ? scanner.next() : "";
String[] lines = fileContent.split("\\r\\n");
for (String line : lines) {
String[] str = line.split("\\s+");
if (str.length < 5) {
continue;
}
Adviser tea = new Adviser();
tea.setWnumber(str[0]);
tea.setWname(str[1]);
tea.setWsex(str[2]);
tea.setWrank(str[3]);
tea.setWacedemy(str[4]);
teacherArrList.add(tea);
}
}
//将集合写入文件
public void writeData(String path, ArrayList< Adviser> teacherArrList) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path));
for (int i = 0; i < teacherArrList.size(); i++) {
//获取对象
Adviser teacher = teacherArrList.get(i);
//使用StringBuilder提高效率
StringBuilder stringBuilder = new StringBuilder();
//获取并保存数据
stringBuilder.append(teacher.getWnumber()).append(" ").append(teacher.getWname()).append(" ").append(teacher.getWsex()).append(" ").append(teacher.getWrank()).append(" ").append(teacher.getWacedemy());
//写入
bufferedWriter.write(stringBuilder.toString());
//换行
bufferedWriter.newLine();
//强制刷新
bufferedWriter.flush();
}
}
//增添指导教师信息
public void addTeacher(String path) throws IOException {
ArrayList< Adviser> teacherArrList = new ArrayList< Adviser>();
readData("0", path, teacherArrList);
boolean flag = false;
String wnumber;
while (true) {
System.out.println("请输入需要添加的工号");
wnumber = scannerString();
//判断指导教师是否已经存在
for (int i = 0; i < teacherArrList.size(); i++) {
Adviser t = teacherArrList.get(i);
if (t.getWnumber().equals(wnumber)) {
flag = true;
break;
}
}
if (flag) {
System.out.println("指导教师信息已存在,请重新操作");
break;
} else
break;
}
System.out.println("请输入需要添加的工号");
wnumber = scannerString();
System.out.println("请输入需要添加的指导教师姓名");
String wname = scannerString();
System.out.println("请输入需要添加的指导教师性别");
String wsex = scannerString();
System.out.println("请输入需要添加的指导教师职称");
String wrank= scannerString();
System.out.println("请输入需要添加的指导教师所属学院");
String wacedemy= scannerString();
Adviser teacher = new Adviser();
teacher.setWnumber(wnumber);
teacher.setWname(wname);
teacher.setWsex(wsex);
teacher.setWrank(wrank);
teacher.setWacedemy(wacedemy);
teacherArrList.add(teacher);
writeData(path, teacherArrList);
System.out.println("添加成功");
}
//删除教师信息
private void deleteteacher(String path) throws IOException {
ArrayList< Adviser> teacherArrList = new ArrayList< Adviser>();
readData("0", path, teacherArrList);
System.out.println("请输入要删除的指导教师信息(工号/姓名)");
String wnumber_name = scannerString();
Boolean flag = false;
int x = 0;
for (int i = 1; i < teacherArrList.size(); i++) {
if (wnumber_name.equals(teacherArrList.get(i).getWnumber()) || wnumber_name.equals(teacherArrList.get(i).getWname())) {
flag = true;
x = i;
break;
}
}
if (flag) {
teacherArrList.remove(x);
//别忘记写入覆盖
writeData(path, teacherArrList);
System.out.println("删除完毕");
} else
System.out.println("查无此人,请重新输入");
}
//修改教师信息
private void updateteacher(String path) throws IOException {
System.out.println("请输入需要修改的指导教师工号");
String s = scannerString();
ArrayList< Adviser> teacherArrList = new ArrayList< Adviser>();
readData("0", path, teacherArrList);
for (int i = 0; i < teacherArrList.size(); i++) {
if (s.equals(teacherArrList.get(i).getWnumber())) {
System.out.println("请输入需要修改后的指导教师姓名");
String wname = scannerString();
System.out.println("请输入需要修改后的指导教师性别");
String wsex = scannerString();
System.out.println("请输入需要修改后的指导教师职称");
String wrank = scannerString();
System.out.println("请输入需要修改后的指导教师所在学院");
String wacedemy = scannerString();
teacherArrList.get(i).setWnumber(s);
teacherArrList.get(i).setWname(wname);
teacherArrList.get(i).setWsex(wsex);
teacherArrList.get(i).setWrank(wrank);
teacherArrList.get(i).setWacedemy(wacedemy);
}
else if(teacherArrList.size()==i) {
System.out.println("查无此人");
return;
}
}
writeData(path, teacherArrList);
System.out.println("修改完成");
}
}
public class Production {
private String proname; //作品名称
private String propeo; //团队成员
private String protime; //起止时间
private String protype; //作品类型
private String propri; //获得奖项
private String proteacher; //指导教师
public String getProname() {
return proname;
}
public void setProname(String proname) {
this.proname = proname;
}
public String getPropeo() {
return propeo;
}
public void setPropeo(String propeo) {
this.propeo = propeo;
}
public String getProtime() {
return protime;
}
public void setProtime(String protime) {
this.protime = protime;
}
public String getProtype() {
return protype;
}
public void setProtype(String protype) {
this.protype = protype;
}
public String getPropri() {
return propri;
}
public void setPropri(String propri) {
this.propri = propri;
}
public String getProteacher() {
return proteacher;
}
public void setProteacher(String proteacher) {
this.proteacher = proteacher;
}
}
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class ProductionDemo {
//文件存放路径
private String path = "d:\\大创作品信息.txt";
//判断是否退出系统
private static boolean pd=true;
public static void main(String[] args)throws IOException {
while (pd) {
ProductionDemo productionDemo = new ProductionDemo();
//功能提示信息
productionDemo.Tips();
//功能选择
productionDemo.function(productionDemo);
//循环间隔
System.out.println(" ");
}
}
//功能提示
public void Tips() {
System.out.println("******欢迎使用大学生创新课题项目管理系统******");
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("@请选择你要使用的功能@");
}
//功能选择
public void function(ProductionDemo productionDemo) throws IOException {
switch (productionDemo.ScannerInt()) {
//查询所有大创作品信息
case 1:
productionDemo.showproduction(productionDemo.path);
break;
//添加大创作品信息
case 2:
productionDemo.addproduction(productionDemo.path);
break;
//更改大创作品信息
case 3:
productionDemo.updateproduction(productionDemo.path);
break;
//删除大创作品信息
case 4:
productionDemo.deleteproduction(productionDemo.path);
break;
//退出
case 5:
pd=false;
break;
//输入无效
default: {
System.out.println("请重新输入");
//再次输入
function(productionDemo);
break;
}
}
}
//输入功能
public int ScannerInt() {
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
return y;
}
//输入大创作品信息
public String scannerString() {
Scanner scanner = new Scanner(System.in);
String x = scanner.next().toString();
return x;
}
/*
读数据 利用ArrayList动态数组
*/
//显示所有大创作品信息
void showproduction(String path) throws IOException {
//读数据到集合中
ArrayList<Production> productionArrlist = new ArrayList<Production>();
//0是判断
readData("0", path, productionArrlist);
if (productionArrlist.size() == 0) {
System.out.println("无可查询信息");
return;
}
print(productionArrlist);
}
//输出信息
static void print(ArrayList<Production> productionArrlist) {
for (int i = 0; i < productionArrlist.size(); i++) {
Production production = productionArrlist.get(i);
System.out.println(production.getProname()+" "+production.getPropeo()+" "+production.getProtime()+
" "+production.getProtype()+" "+production.getPropri()+" "+production.getProteacher());
}
}
//保存对象信息
public static Production production(String[] str){
Production production = new Production();
production.setProname(str[0]);
production.setPropeo(str[1]);
production.setProtime(str[2]);
production.setProtype(str[3]);
production.setPropri(str[4]);
production.setProteacher(str[5]);
return production;
}
//将文件读入集合
static void readData(String onlyproduction, String path, ArrayList<Production> productionArrlist) throws IOException {
//利用处理流提高性能
Scanner scanner = new Scanner(new FileInputStream(path), "GBK").useDelimiter("\\A");
String fileContent = scanner.hasNext() ? scanner.next() : "";
String[] lines = fileContent.split("\\r\\n");
for (String line : lines) {
String[] str = line.split("\\s+");
if (str.length < 6) {
continue;
}
Production production = new Production ();
production.setProname(str[0]);
production.setPropeo(str[1]);
production.setProtime(str[2]);
production.setProtype(str[3]);
production.setPropri(str[4]);
production.setProteacher(str[5]);
productionArrlist.add(production);
}
}
//将集合写入文件
public void writeData(String path, ArrayList<Production> productionArrlist) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path));
for (int i = 0; i < productionArrlist.size(); i++) {
//获取对象
Production production = productionArrlist.get(i);
//使用StringBuilder提高效率
StringBuilder stringBuilder = new StringBuilder();
//获取并保存数据
stringBuilder.append(production.getProname()).append(" ").append(production.getPropeo()).append(" ").append(production.getProtime()).append(" ")
.append(production.getProtype()).append(" ").append(production.getPropri()).append(" ").append(production.getProteacher());
//写入
bufferedWriter.write(stringBuilder.toString());
//换行
bufferedWriter.newLine();
//强制刷新
bufferedWriter.flush();
}
}
//增添大创作品信息
public void addproduction(String path) throws IOException {
ArrayList<Production> productionArrlist = new ArrayList<Production>();
readData("0", path,productionArrlist);
boolean flag = false;
String proname;
while (true) {
System.out.println("请输入需要添加的作品名称");
proname = scannerString();
//判断作品是否已经存在
for (int i = 0; i < productionArrlist.size(); i++) {
Production p = productionArrlist.get(i);
if (p.getProname().equals(proname)) {
flag = true;
break;
}
}
if (flag) {
System.out.println("已有作品信息,请重新操作");
} else
break;
}
System.out.println("请输入需要添加的团队成员");
String propeo = scannerString();
System.out.println("请输入需要添加的起止时间");
String protime= scannerString();
System.out.println("请输入需要添加的作品类型");
String protype= scannerString();
System.out.println("请输入需要添加的获得奖项");
String propri= scannerString();
System.out.println("请输入需要添加的指导教师");
String proteacher = scannerString();
Production production = new Production();
production.setProname(proname);
production.setPropeo(propeo);
production.setProtime(protime);
production.setProtype(protype);
production.setPropri(propri);
production.setProteacher(proteacher);
productionArrlist.add(production);
writeData(path, productionArrlist);
System.out.println("添加成功");
}
//删除大创作品信息
private void deleteproduction(String path) throws IOException {
ArrayList<Production> productionArrlist = new ArrayList<Production>();
readData("0", path,productionArrlist);
System.out.println("请输入要删除的大创作品信息(作品名称)");
String proname_name = scannerString();
Boolean flag = false;
int x = 0;
for (int i = 1; i < productionArrlist.size(); i++) {
if (proname_name.equals( productionArrlist.get(i).getProname())) {
flag = true;
x = i;
break;
}
}
if (flag) {
productionArrlist.remove(x);
//千万别忘记在写入覆盖
writeData(path, productionArrlist);
System.out.println("删除完毕");
} else
System.out.println("查无此信息,请重新输入");
}
//修改大创作品信息
private void updateproduction(String path) throws IOException {
System.out.println("请输入需要修改的大创作品名字");
String s = scannerString();
ArrayList<Production> productionArrlist = new ArrayList<Production>();
readData("0", path,productionArrlist);
for (int i = 1; i < productionArrlist.size(); i++) {
if (s.equals(productionArrlist.get(i).getProname())) {
System.out.println("请输入需要修改后的团队成员");
String propeo = scannerString();
System.out.println("请输入需要修改后的起止时间");
String protime = scannerString();
System.out.println("请输入需要修改后的作品类型");
String protype = scannerString();
System.out.println("请输入需要修改后的获得奖项");
String propri = scannerString();
System.out.println("请输入需要修改后的指导教师");
String proteacher = scannerString();
productionArrlist.get(i).setProname(s);
productionArrlist.get(i).setPropeo(propeo);
productionArrlist.get(i).setProtime(protime);
productionArrlist.get(i).setProtype(protype);
productionArrlist.get(i).setPropri(propri);
productionArrlist.get(i).setProteacher(proteacher);
}
else if(productionArrlist.size()==i) {
System.out.println("查无此信息");
return;
}
}
writeData(path, productionArrlist);
System.out.println("修改完成");
}
}
public class Workplace {
private String roomname; //工作室名称
private String roomtime; //工作室开放时间
private String roomsite; //工作室地点
private String roomprincipal; //工作室负责人
public String getRoomname() {
return roomname;
}
public void setRoomname(String roomname) {
this.roomname = roomname;
}
public String getRoomtime() {
return roomtime;
}
public void setRoomtime(String roomtime) {
this.roomtime = roomtime;
}
public String getRoomsite() {
return roomsite;
}
public void setRoomsite(String roomsite) {
this.roomsite= roomsite;
}
public String getRoomprincipal() {
return roomprincipal;
}
public void setRoomprincipal(String roomprincipal) {
this.roomprincipal = roomprincipal;
}
}
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class WorkplaceDemo {
//文件存放路径
private String path = "d:\\大创工作室信息.txt";
//判断是否退出系统
private static boolean pd=true;
public static void main(String[] args)throws IOException {
while (pd) {
WorkplaceDemo workplaceDemo = new WorkplaceDemo();
//功能提示信息
workplaceDemo.Tips();
//功能选择
workplaceDemo.function(workplaceDemo);
//循环间隔
System.out.println("");
}
}
//功能提示
public void Tips() {
System.out.println("******欢迎使用大学生创新课题项目管理系统******");
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("@请选择你要使用的功能@");
}
//功能选择
public void function(WorkplaceDemo workplaceDemo) throws IOException {
switch (workplaceDemo.ScannerInt()) {
//查询所有大创工作室信息
case 1:
workplaceDemo.showworkplace(workplaceDemo.path);
break;
//添加大创工作室信息
case 2:
workplaceDemo.addworkplace(workplaceDemo.path);
break;
//更改大创工作室信息
case 3:
workplaceDemo. updateworkplace(workplaceDemo.path);
break;
//删除大创工作室信息
case 4:
workplaceDemo.deleteworkplace(workplaceDemo.path);
break;
//退出
case 5:
pd=false;
break;
//输入无效
default: {
System.out.println("请重新输入");
//再次输入
function(workplaceDemo);
break;
}
}
}
//输入功能
public int ScannerInt() {
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
return y;
}
//输入大创工作室信息
public String scannerString() {
Scanner scanner = new Scanner(System.in);
String x = scanner.next().toString();
return x;
}
/*
读数据 利用ArrayList动态数组
*/
//显示所有大创工作室信息
void showworkplace(String path) throws IOException {
//读数据到集合中
ArrayList<Workplace> workplaceArrList = new ArrayList<Workplace>();
//0是判断
readData("0", path, workplaceArrList);
if (workplaceArrList.size() == 0) {
System.out.println("无可查询信息");
return;
}
print(workplaceArrList);
}
//输出信息
static void print( ArrayList<Workplace> workplaceArrList) {
for (int i = 0; i < workplaceArrList.size(); i++) {
Workplace workplace = workplaceArrList.get(i);
System.out.println(workplace.getRoomname()+" "+workplace.getRoomtime()+" "+workplace.getRoomsite()+" "+workplace.getRoomprincipal());
}
}
//保存对象信息
public static Workplace workplace(String[] str){
Workplace workplace = new Workplace();
workplace.setRoomname(str[0]);
workplace.setRoomtime(str[1]);
workplace.setRoomsite(str[2]);
workplace.setRoomprincipal(str[3]);
return workplace;
}
//将文件读入集合
static void readData(String onlyworkplace, String path, ArrayList<Workplace> workplaceArrList) throws IOException {
//利用处理流提高性能
Scanner scanner = new Scanner(new FileInputStream(path), "GBK").useDelimiter("\\A");
String fileContent = scanner.hasNext() ? scanner.next() : "";
String[] lines = fileContent.split("\\r\\n");
for (String line : lines) {
String[] str = line.split("\\s+");
if (str.length < 4) {
continue;
}
Workplace workplace = new Workplace();
workplace.setRoomname(str[0]);
workplace.setRoomtime(str[1]);
workplace.setRoomsite(str[2]);
workplace.setRoomprincipal(str[3]);
workplaceArrList.add( workplace);
}
}
//将集合写入文件
public void writeData(String path, ArrayList<Workplace> workplaceArrList) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path));
for (int i = 0; i < workplaceArrList.size(); i++) {
//获取对象
Workplace workplace = workplaceArrList.get(i);
//使用StringBuilder提高效率
StringBuilder stringBuilder = new StringBuilder();
//获取并保存数据
stringBuilder.append(workplace.getRoomname()).append(" ").append(workplace.getRoomtime()).append(" ").append(workplace.getRoomsite()).append(" ").append(workplace.getRoomprincipal());
//写入
bufferedWriter.write(stringBuilder.toString());
//换行
bufferedWriter.newLine();
//强制刷新
bufferedWriter.flush();
}
}
//增添大创工作室信息
public void addworkplace(String path) throws IOException {
ArrayList<Workplace> workplaceArrList = new ArrayList<Workplace>();
readData("0", path, workplaceArrList);
boolean flag = false;
String roomname;
while (true) {
System.out.println("请输入需要添加的工作室名称");
roomname = scannerString();
//判断工作室是否已经存在
for (int i = 0; i < workplaceArrList.size(); i++) {
Workplace t =workplaceArrList.get(i);
if (t.getRoomname().equals(roomname)) {
flag = true;
break;
}
}
if (flag) {
System.out.println("该工作室信息已存在,请重新操作");
} else
break;
}
System.out.println("请输入需要添加的工作室开放时间");
String roomtime = scannerString();
System.out.println("请输入需要添加的工作室地点");
String roomsite = scannerString();
System.out.println("请输入需要添加的工作室负责人");
String roomprincipal= scannerString();
Workplace workplace = new Workplace();
workplace.setRoomname(roomname);
workplace.setRoomtime(roomtime);
workplace.setRoomsite(roomsite);
workplace.setRoomprincipal(roomprincipal);
workplaceArrList.add(workplace);
writeData(path, workplaceArrList);
System.out.println("添加成功");
}
//删除大创工作室信息
private void deleteworkplace(String path) throws IOException {
ArrayList<Workplace> workplaceArrList = new ArrayList<Workplace>();
readData("0", path, workplaceArrList);
System.out.println("请输入要删除的大创工作室");
String roomname_name = scannerString();
Boolean flag = false;
int x = 0;
for (int i = 0; i < workplaceArrList.size(); i++) {
if (roomname_name .equals( workplaceArrList.get(i).getRoomname())) {
flag = true;
x = i;
break;
}
}
if (flag) {
workplaceArrList.remove(x);
//千万别忘记在写入覆盖
writeData(path, workplaceArrList);
System.out.println("删除完毕");
} else
System.out.println("查无此工作室,请重新输入");
}
//修改工作室信息
private void updateworkplace(String path) throws IOException {
System.out.println("请输入需要修改的大创工作室名称");
String s = scannerString();
ArrayList<Workplace> workplaceArrList = new ArrayList<Workplace>();
readData("0", path, workplaceArrList);
for (int i = 0; i < workplaceArrList.size(); i++) {
if (s.equals(workplaceArrList.get(i).getRoomname())) {
System.out.println("请输入需要修改的工作室开放时间");
String roomtime = scannerString();
System.out.println("请输入需要修改的工作室地点");
String roomsite = scannerString();
System.out.println("请输入需要修改的工作室负责人");
String roomprincipal= scannerString();
workplaceArrList.get(i).setRoomname(s);
workplaceArrList.get(i).setRoomtime(roomtime);
workplaceArrList.get(i).setRoomsite(roomsite);
workplaceArrList.get(i).setRoomprincipal(roomprincipal);
}
else if(workplaceArrList.size()==i) {
System.out.println("没有这个工作室");
return;
}
}
writeData(path, workplaceArrList);
System.out.println("修改完成");
}
}
public class Competition {
private String gamename; //比赛名称
private String gamelevel; //比赛级别
private String gametime; //比赛时间
private String gamesite; //比赛地点
public String getGamename() {
return gamename;
}
public void setGamename(String gamename) {
this.gamename = gamename;
}
public String getGamelevel() {
return gamelevel;
}
public void setGamelevel(String gamelevel) {
this.gamelevel = gamelevel;
}
public String getGametime() {
return gametime;
}
public void setGametime(String gametime) {
this.gametime= gametime;
}
public String getGamesite() {
return gamesite;
}
public void setGamesite(String gamesite) {
this.gamesite = gamesite;
}
}
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class CompetitionDemo {
//文件存放路径
private String path = "d:\\大创比赛信息.txt";
//判断是否退出系统
private static boolean pd=true;
public static void main(String[] args)throws IOException {
while (pd) {
CompetitionDemo competitionDemo = new CompetitionDemo ();
//功能提示信息
competitionDemo.Tips();
//功能选择
competitionDemo.function(competitionDemo);
//循环间隔
System.out.println(" ");
}
}
//功能提示
public void Tips() {
System.out.println("******欢迎使用大学生创新课题项目管理系统******");
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("@请选择你要使用的功能@");
}
//功能选择
public void function(CompetitionDemo competitionDemo ) throws IOException {
switch (competitionDemo.ScannerInt()) {
//查询所有大创比赛信息
case 1:
competitionDemo.showcompetition(competitionDemo.path);
break;
//添加大创比赛信息
case 2:
competitionDemo.addcompetition(competitionDemo.path);
break;
//更改大创比赛信息
case 3:
competitionDemo. updatecompetition(competitionDemo.path);
break;
//删除大创比赛信息
case 4:
competitionDemo.deletecompetition(competitionDemo.path);
break;
//退出
case 5:
pd=false;
break;
//输入无效
default: {
System.out.println("请重新输入");
//再次输入
function(competitionDemo);
break;
}
}
}
//输入功能
public int ScannerInt() {
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
return y;
}
//输入比赛信息
public String scannerString() {
Scanner scanner = new Scanner(System.in);
String x = scanner.next().toString();
return x;
}
/*
读数据 利用ArrayList动态数组
*/
//显示所有大创比赛信息
void showcompetition(String path) throws IOException {
//读数据到集合中
ArrayList<Competition>competitionArrList = new ArrayList<Competition>();
//0是判断
readData("0", path,competitionArrList);
if (competitionArrList.size() == 0) {
System.out.println("无可查询信息");
return;
}
print(competitionArrList);
}
//输出信息
static void print( ArrayList<Competition>competitionArrList) {
for (int i = 0; i < competitionArrList.size(); i++) {
Competition competition = competitionArrList.get(i);
System.out.println(competition.getGamename()+" "+competition.getGamelevel()+" "+competition.getGametime()+" "+competition.getGamesite());
}
}
//保存对象信息
public static Competition competition(String[] str){
Competition competition = new Competition();
competition.setGamename(str[0]);
competition.setGamelevel(str[1]);
competition.setGametime(str[2]);
competition.setGamesite(str[3]);
return competition;
}
//将文件读入集合
static void readData(String onlycompetition, String path, ArrayList<Competition>competitionArrList) throws IOException {
//利用处理流提高性能
Scanner scanner = new Scanner(new FileInputStream(path), "GBK").useDelimiter("\\A");
String fileContent = scanner.hasNext() ? scanner.next() : "";
String[] lines = fileContent.split("\\r\\n");
for (String line : lines) {
String[] str = line.split("\\s+");
if (str.length < 4) {
continue;
}
Competition competition = new Competition();
competition.setGamename(str[0]);
competition.setGamelevel(str[1]);
competition.setGametime(str[2]);
competition.setGamesite(str[3]);
competitionArrList.add(competition);
}
}
//将集合写入文件
public void writeData(String path, ArrayList<Competition>competitionArrList) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path));
for (int i = 0; i < competitionArrList.size(); i++) {
//获取对象
Competition competition = competitionArrList.get(i);
//使用StringBuilder提高效率
StringBuilder stringBuilder = new StringBuilder();
//获取并保存数据
stringBuilder.append( competition.getGamename()).append(" ").append( competition.getGamelevel()).append(" ").append( competition.getGametime()).append(" ").append( competition.getGamesite());
//写入
bufferedWriter.write(stringBuilder.toString());
//换行
bufferedWriter.newLine();
//强制刷新
bufferedWriter.flush();
}
}
//增添大创比赛信息
public void addcompetition(String path) throws IOException {
ArrayList<Competition>competitionArrList = new ArrayList<Competition>();
readData("0", path, competitionArrList);
boolean flag = false;
String gamename;
while (true) {
System.out.println("请输入需要添加的比赛名称");
gamename = scannerString();
//判断用户是否已经存在
for (int i = 0; i < competitionArrList.size(); i++) {
Competition t =competitionArrList.get(i);
if (t.getGamename().equals(gamename)) {
flag = true;
break;
}
}
if (flag) {
System.out.println("该比赛信息已存在,请重新操作");
} else
break;
}
System.out.println("请输入需要添加的比赛级别");
String gamelevel = scannerString();
System.out.println("请输入需要添加的比赛时间");
String gametime = scannerString();
System.out.println("请输入需要添加的比赛地点");
String gamesite= scannerString();
Competition competition = new Competition();
competition.setGamename(gamename);
competition.setGamelevel(gamelevel);
competition.setGametime(gametime);
competition.setGamesite(gamesite);
competitionArrList.add(competition);
writeData(path,competitionArrList);
System.out.println("添加成功");
}
//删除比赛信息
private void deletecompetition(String path) throws IOException {
ArrayList<Competition>competitionArrList = new ArrayList<Competition>();
readData("0", path, competitionArrList);
System.out.println("请输入要删除的大创比赛");
String gamename_name = scannerString();
Boolean flag = false;
int x = 0;
for (int i = 0; i < competitionArrList.size(); i++) {
if (gamename_name .equals( competitionArrList.get(i).getGamename())) {
flag = true;
x = i;
break;
}
}
if (flag) {
competitionArrList.remove(x);
//千万别忘记在写入覆盖
writeData(path, competitionArrList);
System.out.println("删除完毕");
} else
System.out.println("查无此内容,请重新输入");
}
//修改比赛信息
private void updatecompetition(String path) throws IOException {
System.out.println("请输入需要修改的大创比赛名称");
String s = scannerString();
ArrayList<Competition>competitionArrList = new ArrayList<Competition>();
readData("0", path, competitionArrList);
for (int i = 0; i < competitionArrList.size(); i++) {
if (s.equals(competitionArrList.get(i).getGamename())) {
System.out.println("请输入需要修改的比赛级别");
String gamelevel = scannerString();
System.out.println("请输入需要修改的比赛时间");
String gametime = scannerString();
System.out.println("请输入需要修改的比赛地点");
String gamesite= scannerString();
competitionArrList.get(i).setGamename(s);
competitionArrList.get(i).setGamelevel(gamelevel);
competitionArrList.get(i).setGametime(gametime);
competitionArrList.get(i).setGamesite(gamesite);
}
else if(competitionArrList.size()==i) {
System.out.println("没有这个比赛");
return;
}
}
writeData(path, competitionArrList);
System.out.println("修改完成");
}
}
利用线程交互读取多个文件
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class All extends Thread {
private File file;
public All(File file)
{
super();
this.file = file;
}
public void run()
{
InputStream in=null;
OutputStream out=null;
try
{
System.out.println(Thread.currentThread().getName());
in=new FileInputStream(file);
byte[] b=new byte[in.available()];
in.read(b);
out=new FileOutputStream("D:\\大作业\\A.txt",true);
out.write(b);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try
{
in.close();
out.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) throws InterruptedException
{
File dir=new File("D:\\大作业");
File[] listFiles = dir.listFiles();
for(int i=0;i<listFiles.length;i++)
{
All a1=new All(listFiles[i]);
a1.start();
a1.join();
}
}
}
import java.io.*;
import java.util.*;
public class CopyFile {
public static void main(String[] args) {
String source = "d:\\指导教师.txt";
String target = "d:\\指导教师1.0.txt";
try {
Scanner input = new Scanner(new File(source));
PrintWriter output = new PrintWriter(new File(target));
while (input.hasNext()) {
String s1 = input.nextLine();
String s2 = s1.replaceAll("男", "女");
output.println(s2);
System.out.println(s2);
}
System.out.println("恭喜文件复制成功,完成了字符串的替换");
input.close();
output.close();
} catch (FileNotFoundException e) {
System.out.println("抱歉,文件备份失败,请查看是否出现文件名错误、代码错误等问题");
}
System.out.println("备份大创工作室信息文件");
String workplace = "d:\\大创工作室信息.txt";
String newplace = "d:\\大创工作室信息1.0.txt";
try {
Scanner input = new Scanner(new File(workplace));
PrintWriter output = new PrintWriter(new File(newplace));
while (input.hasNext()) {
String s1 = input.nextLine();
System.out.println(s1);
}
System.out.println("恭喜文件复制成功");
input.close();
output.close();
} catch (FileNotFoundException e) {
System.out.println("file doesn't exists");
}
System.out.println("备份大创作品信息文件");
String production = "d:\\大创作品信息.txt";
String newproduction = "d:\\大创作品信息1.0.txt";
try {
Scanner input = new Scanner(new File(production));
PrintWriter output = new PrintWriter(new File(newproduction));
while (input.hasNext()) {
String s1 = input.nextLine();
System.out.println(s1);
}
System.out.println("恭喜文件复制成功");
input.close();
output.close();
} catch (FileNotFoundException e) {
System.out.println("抱歉,文件备份失败,请查看是否出现文件名错误、代码错误等问题");
}
System.out.println("备份大创比赛信息文件");
String competition = "d:\\大创比赛信息.txt";
String newcompetition = "d:\\大创比赛信息1.0.txt";
try {
Scanner input = new Scanner(new File(competition));
PrintWriter output = new PrintWriter(new File(newcompetition));
while (input.hasNext()) {
String s1 = input.nextLine();
System.out.println(s1);
}
System.out.println("恭喜文件复制成功");
input.close();
output.close();
} catch (FileNotFoundException e) {
System.out.println("抱歉,文件备份失败,请查看是否出现文件名错误、代码错误等问题");
}
}
}
这是我们一门课程的做作业,基本实现了老师要求得各项要求,不足之处在于:查找时不能够按照条件进行查找,只能够查找全部,另外就是用txt读取文件内容在控制台显示的时候出现文字不对齐的现象,影响美感。另外,在文件备份过程中进行字符串替换时,一定要结合现实意义,来判断是否需要进行字符串替换。
经历了大作业的磨练使得自己对独立编写代码的能力感到更加的自信,虽然有很多的不足之处,但是砥砺前行,奋斗,我在进行时!各位读者也加油呀!