是Java大神的都进来看看,帮帮忙
编写一个基于集合操作的学籍管理系统,包括对学生的添加,查找,删除,显示操作。要求分别用ArrayList和HashMap两种集合结构实现,其中HashMap结构实现“学号...
编写一个基于集合操作的学籍管理系统,包括对学生的添加,查找,删除,显示操作。要求分别用ArrayList和HashMap两种集合结构实现,其中HashMap结构实现“学号”“学生”,也就是学号到学生的映射。
提示及思路:
一.学生Student类:具有四个属性,分别是姓名,性别,年龄和学号。
二.对学生集合进行的操作,分别对应相应的方法:
(1)添加方法add(Students):该方法实现对学生对象的添加。注意:添加学生对象前要先对现有集合进行查询,如果该生信息已存在,则提示:该生信息已存在,添加失败;否则添加成功,并返回提示成功信息。
(2)查找方法findStudentByNum(String num):该方法实现了根据学号num对学生的查询,返回成功查询后所查询到的学生信息或删除失败信息。
(3)删除方法deleteStudentByNum(String num):该方法实现了根据学号num对相应学生的删除,返回成功删除信息或删除失败信息。
(4)显示方法printAllStudent()方法和printStudentAtNum(String num)方法:第一个显示方法显示所有学生信息,通过迭代器+while循环或者增强for循环实现对集合中所有学生对象的遍历输出。第二个显示方法,实现对指定学生的对象信息进行输出。 展开
提示及思路:
一.学生Student类:具有四个属性,分别是姓名,性别,年龄和学号。
二.对学生集合进行的操作,分别对应相应的方法:
(1)添加方法add(Students):该方法实现对学生对象的添加。注意:添加学生对象前要先对现有集合进行查询,如果该生信息已存在,则提示:该生信息已存在,添加失败;否则添加成功,并返回提示成功信息。
(2)查找方法findStudentByNum(String num):该方法实现了根据学号num对学生的查询,返回成功查询后所查询到的学生信息或删除失败信息。
(3)删除方法deleteStudentByNum(String num):该方法实现了根据学号num对相应学生的删除,返回成功删除信息或删除失败信息。
(4)显示方法printAllStudent()方法和printStudentAtNum(String num)方法:第一个显示方法显示所有学生信息,通过迭代器+while循环或者增强for循环实现对集合中所有学生对象的遍历输出。第二个显示方法,实现对指定学生的对象信息进行输出。 展开
4个回答
展开全部
写的有点乱,你可以自己修改下
package com.softeem.operateStudent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Student {
private Integer id;
private String name;
private String sex;
private int age;
private static Map<Integer,Student> students = new HashMap<Integer,Student>();
public Student(Integer id,String name,String sex,int age){
this.id =id;
this.name = name;
this.sex = sex;
this.age = age;
}
public static void add(Student student){
students.put(student.id, student);
}
public static void findStudentByNum(int num){
Object o = students.get(Integer.valueOf(num));
if(o==null) System.out.println("学号不存在");
else System.out.println((Student)o);
}
public static void deleteStudentByNum(int num){
Student s = students.remove(Integer.valueOf(num));
if(s == null) System.out.println("学号不存在!!");
else System.out.println("删除成功");
}
public static void printAllStudent(){
Iterator it = students.keySet().iterator();
while(it.hasNext()) {
Object key = it.next();
// System.out.println("key:" + key);
System.out.println(students.get(key));
}
}
public static void printStudentAtNum(int num){
findStudentByNum(num);
}
public String toString(){
return "学号:"+this.id+"\t"+"姓名:"+this.name+"\t"+"性别:"+this.sex+"\t"+"年龄:"+this.age;
}
public static void main(String[] args) {
Student A = new Student(Integer.valueOf(2014), "rey", "male", 22);
Student B = new Student(Integer.valueOf(2015), "jason", "male", 25);
Student.add(A);
Student.add(B);
printAllStudent();
deleteStudentByNum(2015);
findStudentByNum(2015);
printStudentAtNum(2015);
}
}
package com.softeem.operateStudent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Student {
private Integer id;
private String name;
private String sex;
private int age;
private static Map<Integer,Student> students = new HashMap<Integer,Student>();
public Student(Integer id,String name,String sex,int age){
this.id =id;
this.name = name;
this.sex = sex;
this.age = age;
}
public static void add(Student student){
students.put(student.id, student);
}
public static void findStudentByNum(int num){
Object o = students.get(Integer.valueOf(num));
if(o==null) System.out.println("学号不存在");
else System.out.println((Student)o);
}
public static void deleteStudentByNum(int num){
Student s = students.remove(Integer.valueOf(num));
if(s == null) System.out.println("学号不存在!!");
else System.out.println("删除成功");
}
public static void printAllStudent(){
Iterator it = students.keySet().iterator();
while(it.hasNext()) {
Object key = it.next();
// System.out.println("key:" + key);
System.out.println(students.get(key));
}
}
public static void printStudentAtNum(int num){
findStudentByNum(num);
}
public String toString(){
return "学号:"+this.id+"\t"+"姓名:"+this.name+"\t"+"性别:"+this.sex+"\t"+"年龄:"+this.age;
}
public static void main(String[] args) {
Student A = new Student(Integer.valueOf(2014), "rey", "male", 22);
Student B = new Student(Integer.valueOf(2015), "jason", "male", 25);
Student.add(A);
Student.add(B);
printAllStudent();
deleteStudentByNum(2015);
findStudentByNum(2015);
printStudentAtNum(2015);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是写控制台应用吗 还是需要界面 还好不包括数据库 我能写出来的
package student;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class StudentTest
{
private HashSet set;
public static void main(String[] args){
StudentTest st = new StudentTest();
st.set = new HashSet();
while(true){
System.out.println("请输入以下数字完成操作 1、添加学生 2、查找学生通过学号 3、删除学生通过学号 4、查询所有学生 5、查询学生通过学号 6、退出系统");
Scanner sc = new Scanner(System.in);
int selectNum = sc.nextInt();
if(selectNum == 1){
Student temp = new Student();
System.out.println("请输入学生的姓名");
String name = sc.next();
System.out.println("请输入学生的性别");
String sex = sc.next();
System.out.println("请输入学生的年龄");
int age = sc.nextInt();
System.out.println("请输入学生的学号");
String number = sc.next();
temp.setName(name);
temp.setAge(age);
temp.setSex(sex);
temp.setNumber(number);
st.Add(temp);
}else if(selectNum == 2){
System.out.println("请输入学生的学号");
String number = sc.next();
Student student = st.findStudentByNum(number);
st.printStudentAtNum(student.getNumber());
}else if(selectNum == 3){
System.out.println("请输入学生的学号");
String number = sc.next();
boolean isDelete = st.deleteStudentByNum(number);
if(isDelete){
System.out.println("删除成功");
}else{
System.out.println("删除失败");
}
}else if(selectNum == 4){
st.printAllStudent();
}else if(selectNum == 5){
System.out.println("请输入学生的学号");
String number = sc.next();
st.printStudentAtNum(number);
}else if(selectNum == 6){
break;
}
}
}
public boolean Add(Student student){
boolean isExist = set.add(student);
return isExist;
}
public Student findStudentByNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
return temp;
}
}
return null;
}
public boolean deleteStudentByNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
set.remove(temp);
return true;
}
}
return false;
}
public void printAllStudent(){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
System.out.print("姓名:" + temp.getName());
System.out.print("性别:" + temp.getSex());
System.out.print("年龄:" + temp.getAge());
System.out.print("学号:" + temp.getNumber());
System.out.println();
}
}
public void printStudentAtNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
System.out.print("姓名:" + temp.getName());
System.out.print("性别:" + temp.getSex());
System.out.print("年龄:" + temp.getAge());
System.out.print("学号:" + temp.getNumber());
}
System.out.println();
}
}
}
class Student{
private String name;
private String sex;
private int age;
private String number;
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 int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number = number;
}
}
写了那么多我都怀疑你应该给点钱了
package student;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class StudentTest
{
private HashSet set;
public static void main(String[] args){
StudentTest st = new StudentTest();
st.set = new HashSet();
while(true){
System.out.println("请输入以下数字完成操作 1、添加学生 2、查找学生通过学号 3、删除学生通过学号 4、查询所有学生 5、查询学生通过学号 6、退出系统");
Scanner sc = new Scanner(System.in);
int selectNum = sc.nextInt();
if(selectNum == 1){
Student temp = new Student();
System.out.println("请输入学生的姓名");
String name = sc.next();
System.out.println("请输入学生的性别");
String sex = sc.next();
System.out.println("请输入学生的年龄");
int age = sc.nextInt();
System.out.println("请输入学生的学号");
String number = sc.next();
temp.setName(name);
temp.setAge(age);
temp.setSex(sex);
temp.setNumber(number);
st.Add(temp);
}else if(selectNum == 2){
System.out.println("请输入学生的学号");
String number = sc.next();
Student student = st.findStudentByNum(number);
st.printStudentAtNum(student.getNumber());
}else if(selectNum == 3){
System.out.println("请输入学生的学号");
String number = sc.next();
boolean isDelete = st.deleteStudentByNum(number);
if(isDelete){
System.out.println("删除成功");
}else{
System.out.println("删除失败");
}
}else if(selectNum == 4){
st.printAllStudent();
}else if(selectNum == 5){
System.out.println("请输入学生的学号");
String number = sc.next();
st.printStudentAtNum(number);
}else if(selectNum == 6){
break;
}
}
}
public boolean Add(Student student){
boolean isExist = set.add(student);
return isExist;
}
public Student findStudentByNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
return temp;
}
}
return null;
}
public boolean deleteStudentByNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
set.remove(temp);
return true;
}
}
return false;
}
public void printAllStudent(){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
System.out.print("姓名:" + temp.getName());
System.out.print("性别:" + temp.getSex());
System.out.print("年龄:" + temp.getAge());
System.out.print("学号:" + temp.getNumber());
System.out.println();
}
}
public void printStudentAtNum(String num){
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Object next = iterator.next();
Student temp = (Student)next;
if(temp.getNumber().equals(num)){
System.out.print("姓名:" + temp.getName());
System.out.print("性别:" + temp.getSex());
System.out.print("年龄:" + temp.getAge());
System.out.print("学号:" + temp.getNumber());
}
System.out.println();
}
}
}
class Student{
private String name;
private String sex;
private int age;
private String number;
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 int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number = number;
}
}
写了那么多我都怀疑你应该给点钱了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SSH 框架写就行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询