Javaで学生管理システムを書く(学生情報の追加、削除、修正、照会)
32814 ワード
くだらないことを言わないで、コードをつけます:
package keeper;
public class Student {
//Java
private String id;
private String name;
private String mobile;
private String address;
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 getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", mobile=" + mobile + ", address=" + address + "]";
}
}
package keeper;
import java.util.Scanner;
public class Main {
static int index = 0; // main() static, static,
static Student [] students = new Student[45];
public static void main(String[] args) {
System.out.println("***********************************");
System.out.println("* *");
System.out.println("***********************************");
for(;;) { //
information();
}
}
public static void information() {
System.out.println("1、 ");
System.out.println("2、 ");
System.out.println("3、 ");
System.out.println("4、 ");
System.out.println(" , enter ");
Scanner scanner = new Scanner(System.in);
int option = scanner.nextInt();
switch (option) {
case 1:{
if(index>students.length-1) { //
System.out.println(" ");
return;
}
System.out.println("· :");
Student student = new Student();
System.out.println(" , enter : ");
String id = scanner.next();
student.setId(id);
if(index>0) {
for (Student stu : students) {
if(stu == null) { // null , null,
break;
}
if(stu.getId().equals(student.getId())) {//
System.out.println(" , :");
student.setId(scanner.next());
break;
}
}
}
System.out.println(" , enter ");
student.setName(scanner.next());
System.out.println(" , enter ");
student.setMobile(scanner.next());
System.out.println(" , enter ");
student.setAddress(scanner.next());
students[index] = student; //
index++;
System.out.println(" ");
break;
}
case 2:{
System.out.println("· ");
System.out.println(" :");
String id = scanner.next();
index=0;
for(Student student:students) {
if(student == null) {
break;
}
if(student.getId().equals(id)) { //
while(index<students.length-1) {
students[index] = students[index+1]; //
index++;
}
students[students.length-1] = null; // , null; , ,
System.out.println(" , !");
return;
}
index++;
}
System.out.println(" "+id+" , ");
return;
}
case 3:{
System.out.println("· ");
System.out.println(" :");
String id = scanner.next();
for(Student student:students) {
if(student == null) {
break;
}
if(student.getId().equals(id)) {
System.out.println(" , enter ");
student.setName(scanner.next());
System.out.println(" , enter ");
student.setMobile(scanner.next());
System.out.println(" , enter ");
student.setAddress(scanner.next());
System.out.println(" , !");
return;
}
}
System.out.println(" "+id+" , !");
return;
}
case 4:{
boolean flag = false;
System.out.println("· ");
System.out.println(" :");
String name = scanner.next();
for(Student student: students) {
if(student == null) {
break;
}
if(student.getName().equals(name)) {
System.out.println(student);
flag = true;
}
}
if(!flag) {
System.out.println(" "+name+" ");
return;
}
break;
}
default:
System.out.println(" "+option+" ");
}
}
}