用JAVA写一个学生管理系统,实现增加,查找,删除。用最简单的方法,不要有图形界面和SQL! 10
展开全部
package org.apache.dream.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Admin {
private static List data;
public static void main(String[] args) {
init();
Scanner in = new Scanner(System.in);
while (true) {
System.out.print("学生列表,请输入1 ");
System.out.print("查找列表,请输入2 ");
System.out.print("添加学生,请输入3 ");
System.out.print("删除学生,请输入4 ");
System.out.println("退出,请输入5");
int i = in.nextInt();
if (i == 1) {
list();
} else if (i == 2) {
find();
} else if (i == 3) {
add();
} else if (i == 4) {
del();
} else if (i == 5) {
System.out.println("您已退出系统!");
System.exit(0);
}
System.out.println("-------------------------------------------");
}
}
private static void del() {
Scanner in = new Scanner(System.in);
System.out.print("输入学号:");
String id = in.next();
boolean flg = false;
for (int i = 0; i < data.size(); i++) {
Student s = (Student) data.get(i);
if (s.getId().equalsIgnoreCase(id)) {
data.remove(i);
flg = true;
}
}
if (!flg) {
System.out.println("没有该学生!");
}
}
private static void add() {
Scanner in = new Scanner(System.in);
System.out.print("输入学号:");
String id = in.next();
System.out.print("输入姓名:");
String name = in.next();
System.out.print("输入性别:");
String sex = in.next();
Student s = new Student();
s.setId(id);
s.setName(name);
s.setSex(sex);
data.add(s);
}
private static void find() {
Scanner in = new Scanner(System.in);
System.out.print("输入关键字:");
String key = in.next();
for (int i = 0; i < data.size(); i++) {
Student s = (Student) data.get(i);
if (s.getId().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
if (s.getName().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
if (s.getSex().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
}
}
private static void list() {
if (data == null || data.size() == 0) {
System.out.println("当前没有数据!");
return;
}
for (int i = 0; i < data.size(); i++) {
System.out.println(data.get(i));
}
}
private static void init() {
if (data == null) {
data = new ArrayList();
}
}
}
class Student {
private String id;
private String name;
private String sex;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String toString() {
return "ID:" + id + " 名称:" + name + " 性别" + sex;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Admin {
private static List data;
public static void main(String[] args) {
init();
Scanner in = new Scanner(System.in);
while (true) {
System.out.print("学生列表,请输入1 ");
System.out.print("查找列表,请输入2 ");
System.out.print("添加学生,请输入3 ");
System.out.print("删除学生,请输入4 ");
System.out.println("退出,请输入5");
int i = in.nextInt();
if (i == 1) {
list();
} else if (i == 2) {
find();
} else if (i == 3) {
add();
} else if (i == 4) {
del();
} else if (i == 5) {
System.out.println("您已退出系统!");
System.exit(0);
}
System.out.println("-------------------------------------------");
}
}
private static void del() {
Scanner in = new Scanner(System.in);
System.out.print("输入学号:");
String id = in.next();
boolean flg = false;
for (int i = 0; i < data.size(); i++) {
Student s = (Student) data.get(i);
if (s.getId().equalsIgnoreCase(id)) {
data.remove(i);
flg = true;
}
}
if (!flg) {
System.out.println("没有该学生!");
}
}
private static void add() {
Scanner in = new Scanner(System.in);
System.out.print("输入学号:");
String id = in.next();
System.out.print("输入姓名:");
String name = in.next();
System.out.print("输入性别:");
String sex = in.next();
Student s = new Student();
s.setId(id);
s.setName(name);
s.setSex(sex);
data.add(s);
}
private static void find() {
Scanner in = new Scanner(System.in);
System.out.print("输入关键字:");
String key = in.next();
for (int i = 0; i < data.size(); i++) {
Student s = (Student) data.get(i);
if (s.getId().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
if (s.getName().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
if (s.getSex().equalsIgnoreCase(key)) {
System.out.println(s);
break;
}
}
}
private static void list() {
if (data == null || data.size() == 0) {
System.out.println("当前没有数据!");
return;
}
for (int i = 0; i < data.size(); i++) {
System.out.println(data.get(i));
}
}
private static void init() {
if (data == null) {
data = new ArrayList();
}
}
}
class Student {
private String id;
private String name;
private String sex;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String toString() {
return "ID:" + id + " 名称:" + name + " 性别" + sex;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这个简单的大家都不敢接招了。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就是完成任务是吧
不要图形界面怎么操作呢?直接操作代码啊
写个jsp的很简单 servlet怎删改查 数据库用mysql好了 很简单哦
不要图形界面怎么操作呢?直接操作代码啊
写个jsp的很简单 servlet怎删改查 数据库用mysql好了 很简单哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那不简单吗,建一个ArrayList在里面增删不就行了,再建一个Student类,总共不到一百行代码就能实现
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询