java学生管理系统练习,做了一个简易的管理系统,练科一
package studentsystem;
public class Student {
private String id;
private String name;
private String home;
private long number;
public Student(String id, String name, String home, long number) {
super();
this.id = id;
this.name = name;
this.home = home;
this.number = number;
}
public Student() {
}
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 getHome() {
return home;
}
public void setHome(String home) {
this.home = home;
}
public long getNumber() {
return number;
}
public void setNumber(long number) {
this.number = number;
}
}
package studentsystem;
import java.util.ArrayList;
import java.util.Scanner;
public class system {
public static boolean Changestu(ArrayList<Student> stu) {
System.out.println("请输入要更改信息的学生的id");
Scanner sc = new Scanner(System.in);
String sid;
sid=sc.next();
for(int i=0;i<stu.size();i++) {
Student temp = stu.get(i);
if(temp.getId().equals(sid)) {
System.out.println("请输入更改后的name,home,number:");
String cname=sc.next(),chome=sc.next();
long cnumber=sc.nextLong();
temp.setName(cname);
temp.setHome(chome);
temp.setNumber(cnumber);
return true;
}
}
return false;
}
public static boolean deletestu(ArrayList<Student> stu) {
Scanner sc = new Scanner(System.in);
String sid;
System.out.println("请输入要删除学生信息的id");
sid=sc.next();
for(int i=0;i<stu.size();i++) {
Student temp = stu.get(i);
if(temp.getId().equals(sid)) {
stu.remove(i);
return true;
}
}
return false;
}
public static boolean Addstu(ArrayList<Student> stu) {
Scanner sc = new Scanner(System.in);
String sid,sname,shome;
sid=sc.next();
sname=sc.next();
shome=sc.next();
long snumber=sc.nextLong();
Student s = new Student(sid,sname,shome,snumber);
for(int i=0;i<stu.size();i++) {
Student temp = stu.get(i);
if(temp.getId().equals(s.getId())) {
return false;
}
}
stu.add(s);
return true;
}
public static void check(ArrayList<Student> stu) {
Scanner sc = new Scanner(System.in);
System.out.println("请选择查询方式:");
System.out.println("1:全部");
System.out.println("2:输入Id");
int type = sc.nextInt();
switch(type) {
case 1:
if(stu.size()==0) {
System.out.println("目前未录入学生信息");
}else {
for(int i=0;i<stu.size();i++) {
Student temp = stu.get(i);
System.out.print(temp.getId() );
System.out.print(temp.getName() );
System.out.print(temp.getHome() );
System.out.println(temp.getNumber());
}
}
break;
case 2:
System.out.println("输入要查询的id");
String n = sc.next();
int flag=0;
for(int i=0;i<stu.size();i++) {
Student temp = stu.get(i);
if(n.equals(temp.getId())) {
flag=1;
System.out.print(temp.getId() );
System.out.print(temp.getName() );
System.out.print(temp.getHome() );
System.out.println(temp.getNumber());
}
}
if(flag==0) {
System.out.println("未录入该id信息");
}
break;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList <Student> stu=new ArrayList<>();
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:退出系统");
while(true) {
int type=sc.nextInt();
switch(type) {
case 1:
System.out.println("进行添加操作:");
boolean result = Addstu(stu);
if(result) {
System.out.println("添加成功");
}else {
System.out.println("添加失败,该用户已存在");
}
break;
case 2:
System.out.println("进行查询操作:");
check(stu);
System.out.println("查询完毕");
break;
case 3:
System.out.println("进行删除操作:");
result = deletestu(stu);
if(result) {
System.out.println("删除成功");
}else {
System.out.println("删除失败,未录入该学生信息");
}
break;
case 4:
System.out.println("进行更改操作");
result = Changestu(stu);
if(result) {
System.out.println("修改成功");
}else {
System.out.println("修改失败,该id未录入");
}
break;
case 5:
System.exit(0);
}
}
}
}
标签:7.16,String,temp,System,println,public,out From: https://www.cnblogs.com/dddjm/p/17558288.html