Java实现学生简易信息管理系统

写一个简易的学生管理系统,要求如下:
1.使用list接口
2.实现增加学生信息,要求不能重复添加相同学号的学生(类名add)
3.实现根据学号删除学生信息(类名remove)
4.实现根据学号查找学生信息(类名find)
5.实现根据学号更改对应学生信息,要求修改之后不能是已有学生(类名modify)
6.遍历学生信息
7.每个功能拆分为单个类
8.根据用户输入的信息使用I/O流存放在txt文件中
9.实现类功能:根据用户输入的数字,进入对应功能,如:1.增加信息,2.删除信息
10.学生信息有:学号(int id),姓名(String name),年龄(int age)

这道编程题知道一些眉目,但却没法用代码详细写出,求大神帮助!
感激不尽!

import java.util.*;
import java.io.*;

class StuMgr{

public static class Student{

public int id;
public String name;
public int age;

public Student(int id ,String name,int age){
this.id = id;
this.name = name;
this.age = age;
}

@Override
public String toString(){
return id + "," + name + "," + age;
}
}

public List<Student> stuList = new LinkedList<>();

public void add(){
Scanner sc = new Scanner(System.in); 
System.out.println("请输入学生学号:");
String id = sc.nextLine();
int intId = 0;
try{
intId = Integer.parseInt(id);
}catch(NumberFormatException ex){
System.out.println("学号输入有误,请输入数字!");
return;
}
if (find(intId) != null){
System.out.println("该学号已经存在!");
return ;
}
System.out.println("请输入学生姓名:");
String name = sc.nextLine();
System.out.println("请输入学生年龄:");
String age = sc.nextLine();
int intAge = 0;
try{
intAge = Integer.parseInt(age);
}catch(NumberFormatException ex){
System.out.println("年龄输入有误,请输入数字!");
return;
}
Student stu = new Student(intId,name,intAge);
stuList.add(stu);
store();
System.out.println("-----------------------");
System.out.println("学生信息已增加");
System.out.println(stu);
System.out.println("-----------------------");
}

public void del(){
Scanner sc = new Scanner(System.in); 
System.out.println("请输入学生学号:");
String id = sc.nextLine();
int intId = 0;
try{
intId = Integer.parseInt(id);
}catch(NumberFormatException ex){
System.out.println("学号输入有误,请输入数字!");
return;
}
Student stu = find(intId);
if ( stu == null){
System.out.println("该学号不存在!");
return ;
}
stuList.remove(stu);
store();
System.out.println("-----------------------");
System.out.println("学生信息已删除");
System.out.println(stu);
System.out.println("-----------------------");
}

public void find(){
Scanner sc = new Scanner(System.in); 
System.out.println("请输入学生学号:");
String id = sc.nextLine();
int intId = 0;
try{
intId = Integer.parseInt(id);
}catch(NumberFormatException ex){
System.out.println("学号输入有误,请输入数字!");
return;
}
Student stu = find(intId);
if ( stu == null){
System.out.println("该学号不存在!");
return ;
}
System.out.println("-----------------------");
System.out.println("查找学生信息如下");
System.out.println(stu);
System.out.println("-----------------------");
}

public Student find(int id){
for(Student stu : stuList){
if(stu.id == id){
return stu;
}
}
return null;
}

public void modify(){
store();
}

public void foreach(){
System.out.println("-----------------------");
for(Student stu : stuList){
System.out.println(stu);
}
System.out.println("-----------------------");
}

public void store(){
Iterator iterator = stuList.iterator();
File file = new File("stuList.txt");
        FileWriter fw = null;
        BufferedWriter writer = null;
        try {
            fw = new FileWriter(file);
            writer = new BufferedWriter(fw);
            while(iterator.hasNext()){
                writer.write(iterator.next().toString());
                writer.newLine();//换行
            }
            writer.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                writer.close();
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}

public static void main(String[] args){
StuMgr mgr = new StuMgr();
while(true){
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("6:退出");
System.out.println("-----------------------");
Scanner sc = new Scanner(System.in); 
String op = sc.nextLine();
if("6".equals(op)){
return;
}
if("1".equals(op)){
mgr.add();
}
if("2".equals(op)){
mgr.del();
}
if("3".equals(op)){
mgr.find();
}
if("4".equals(op)){
mgr.modify();
}
if("5".equals(op)){
mgr.foreach();
}
}

}
}

时间仓促,还有一个modify方法没实现,留给你自己练手。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-15
如果是你一个人开发,那就照着需求一步步做呗。比如: 首先要有登录界面,登录界面设计好,需要传入的参数有 用户名,密码,登录身份;这时你就设计一个数据库表 user(login_name,login_password,login_type);这时候登录进去,因为不同人的权限...本回答被网友采纳
第2个回答  2018-05-15

不知道你要的是不是这个意思,随便写了点,你运行下,是这样就接着写就好了 ,很简单的.我就写了个新增的功能.保存到了你的e盘user.txt文件了

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class HasStatic {
public static FileOutputStream fos;

public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
//初始化
init();
System.out.println("请输入对应功能:1.增加信息,2.删除信息,3.查询信息");
int order = sc.nextInt();
switch(order){
case 1 :
addUser();
break;
case 2:
break;
case 3:
break;
}
fos.close();
}

public static void init() throws IOException{
File file = new File("E://user.txt");
fos = new FileOutputStream(file);
if(!file.exists()){
file.createNewFile();
String title = "学号 | 姓名 | 年龄\r\n";
fos.write(title.getBytes());
}
}

public static void addUser() throws IOException{
int id ; //学号
String name ;//姓名
int age;//年龄
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生学号:");
 id = sc.nextInt();
System.out.println("请输入学生姓名:");
name = sc.next();
System.out.println("请输入学生年龄:");
age = sc.nextInt();
System.out.println("新增学生信息:");
System.out.println("学号:"+id);
System.out.println("姓名:"+name);
System.out.println("年龄"+age);
System.out.println("是否确定保存:1.确定   2.取消并退出");
int order = sc.nextInt();
switch(order){
case 1 :
saveUser(id,name,age);
break;
case 2:
break;

}
}
public static void saveUser(int id,String name,int age) throws IOException{
//获取输入流
String idStr = id+" | ";
name = name + " | ";
String ageStr = age+"\r\n";
fos.write(idStr.getBytes());
fos.write(name.getBytes());
fos.write(ageStr.getBytes());
}

第3个回答  2020-02-24
这里有很多的源代码,都是Java源码开发

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网