学生管理系统·
来源:互联网 发布:中国古代名将 知乎 编辑:程序博客网 时间:2024/05/21 09:28
package com.softeem.project4;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.nio.BufferOverflowException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class Test extends Student implements Manager {
int i;
ArrayList<Student> stu = new ArrayList<>();
File file = new File(
"C:\\Documents and Settings\\Administrator\\桌面\\新建 文本文档.txt");
ObjectInputStream ois;
ObjectOutputStream oos;
public void start() {
t.tools("*********");
t.tools("1.添加学生");
t.tools("2.修改学生");
t.tools("3.查询全体学生");
t.tools("4.删除学生");
t.tools("5.退出");
t.tools("请输入:");
manage();
}
public void manage() {
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
switch (i) {
case 1:
add();
break;
case 2:
change();
break;
case 3:
select();
break;
case 4:
delete();
break;
case 5:
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void add() {
FileInputStream fis;
if (file.length() != 0) {
try {
fis = new FileInputStream(file);
ois = new ObjectInputStream(fis);
stu = (ArrayList<Student>) ois.readObject();
} catch (ClassNotFoundException | IOException e1) {
e1.printStackTrace();
}
}
Scanner sc = new Scanner(System.in);
t.tools("请输入学生学号:");
id = sc.nextInt();
t.tools("请输入学生姓名:");
name = sc.next();
t.tools("请输入学生性别:");
sex = sc.next();
t.tools("请输入学生年龄:");
age = sc.nextInt();
Student s = new Student(id, name, sex, age);
stu.add(s);
t.tools("是否继续添加:");
if (sc.next().equalsIgnoreCase("是")) {
add();
} else {
try {
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
oos.writeObject(stu);
} catch (IOException e) {
e.printStackTrace();
}
t.tools("添加成功!");
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void change() {
t.tools("请输入需要修改的学生学号:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
for (Student student : stu) {
if (i == student.getId()) {
t.tools("修改性别请输入1\n修改姓名请输入2\n修改年龄请输入3");
int a = sc.nextInt();
if (a == 1) {
student.setSex(sc.next());
t.tools("修改成功");
} else if (a == 2) {
student.setName(sc.next());
t.tools("修改成功");
} else {
student.setAge(i);
t.tools("修改成功");
}
}
}
oos.writeObject(stu);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void select() {
if(file.length() != 0){
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
for (Student student : stu) {
t.tools(student);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Scanner sc = new Scanner(System.in);
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
t.tools("无学生信息请添加学生");
Scanner sc = new Scanner(System.in);
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void delete() {
t.tools("请输入需要删除的学生学号:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if(file.length()!=0){
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
Iterator<Student> it = stu.iterator();
while(it.hasNext()){
if(it.next().getId()==i){
it.remove();
break;
}
}
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
oos.writeObject(stu);
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}t.tools("无学生信息");
}
}
public static void main(String[] args) {
new Test().start();
}
}
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.nio.BufferOverflowException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class Test extends Student implements Manager {
int i;
ArrayList<Student> stu = new ArrayList<>();
File file = new File(
"C:\\Documents and Settings\\Administrator\\桌面\\新建 文本文档.txt");
ObjectInputStream ois;
ObjectOutputStream oos;
public void start() {
t.tools("*********");
t.tools("1.添加学生");
t.tools("2.修改学生");
t.tools("3.查询全体学生");
t.tools("4.删除学生");
t.tools("5.退出");
t.tools("请输入:");
manage();
}
public void manage() {
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
switch (i) {
case 1:
add();
break;
case 2:
change();
break;
case 3:
select();
break;
case 4:
delete();
break;
case 5:
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void add() {
FileInputStream fis;
if (file.length() != 0) {
try {
fis = new FileInputStream(file);
ois = new ObjectInputStream(fis);
stu = (ArrayList<Student>) ois.readObject();
} catch (ClassNotFoundException | IOException e1) {
e1.printStackTrace();
}
}
Scanner sc = new Scanner(System.in);
t.tools("请输入学生学号:");
id = sc.nextInt();
t.tools("请输入学生姓名:");
name = sc.next();
t.tools("请输入学生性别:");
sex = sc.next();
t.tools("请输入学生年龄:");
age = sc.nextInt();
Student s = new Student(id, name, sex, age);
stu.add(s);
t.tools("是否继续添加:");
if (sc.next().equalsIgnoreCase("是")) {
add();
} else {
try {
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
oos.writeObject(stu);
} catch (IOException e) {
e.printStackTrace();
}
t.tools("添加成功!");
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void change() {
t.tools("请输入需要修改的学生学号:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
for (Student student : stu) {
if (i == student.getId()) {
t.tools("修改性别请输入1\n修改姓名请输入2\n修改年龄请输入3");
int a = sc.nextInt();
if (a == 1) {
student.setSex(sc.next());
t.tools("修改成功");
} else if (a == 2) {
student.setName(sc.next());
t.tools("修改成功");
} else {
student.setAge(i);
t.tools("修改成功");
}
}
}
oos.writeObject(stu);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void select() {
if(file.length() != 0){
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
for (Student student : stu) {
t.tools(student);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Scanner sc = new Scanner(System.in);
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
t.tools("无学生信息请添加学生");
Scanner sc = new Scanner(System.in);
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}
}
@Override
public void delete() {
t.tools("请输入需要删除的学生学号:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if(file.length()!=0){
try {
ois = new ObjectInputStream(new FileInputStream(file));
stu = (ArrayList<Student>) ois.readObject();
Iterator<Student> it = stu.iterator();
while(it.hasNext()){
if(it.next().getId()==i){
it.remove();
break;
}
}
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
oos.writeObject(stu);
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
t.tools("进入主菜单请按1,退出请按2");
if (sc.nextInt() == 1) {
start();
} else {
t.tools("谢谢使用!");
System.exit(0);
}t.tools("无学生信息");
}
}
public static void main(String[] args) {
new Test().start();
}
}
阅读全文
0 0
- 学生管理系统·
- 一个学生管理系统
- 学生同学录管理系统
- 学生管理系统
- 销售学生管理系统
- 学生通讯管理系统
- 学生管理系统
- 学生管理系统
- 学生管理系统
- 学生管理系统
- 学生学籍管理系统
- 学生管理系统
- 学生通讯录管理系统
- 学生管理系统
- 学生管理系统源程序
- 学生管理系统源程序
- 学生管理系统实现
- 学生管理系统
- java每日一练
- 实例解释inner join 和 natural join 的区别
- Python-爬取2345电影并写入文件
- 浏览器如何渲染页面?
- 扩展SQLite使其能从apk文件中读取db
- 学生管理系统·
- Hadoop基础教程-第11章 Hive:SQL on Hadoop(11.7 HQL:数据查询)(草稿)
- 替换空格
- Rsync远程数据同步工具
- 网络编程
- 朴素贝叶斯:分母相对于所有类别为常数
- 网站开发(三)网站前台的导入及控制器对应
- 进程间通讯--动态库的共享数据
- gopher meetup