Java言語を使用して、簡単な「学生情報管理システム」を設計します.
10484 ワード
1.需要分析
学生情報管理システムは、すべての学生情報の表示、学生情報の追加、学生情報の変更、学生情報の削除などの機能を含むべきである.各学生には、学号、氏名、性別、連絡電話、家庭の住所などの情報が含まれなければならない.その中で、学号には唯一性があるべきだ.
2.設計プロセス
2.1学生クラスの作成
2.2学生情報管理システムの作成メニュー(すなわちホームページ)
2.3すべての学生情報を照会する方法を作成する
2.4学生情報を追加する方法を作成し、その中で学生の学号が唯一であることを保証する.
2.5学生情報の削除方法の作成
2.6学生関連情報の修正方法の作成
3.コード
3.1学生クラス(Student.java)のコードは以下の通りです.
3.2マスタークラス(StudentManagerTest.java)のコードは次のとおりです.
学生情報管理システムは、すべての学生情報の表示、学生情報の追加、学生情報の変更、学生情報の削除などの機能を含むべきである.各学生には、学号、氏名、性別、連絡電話、家庭の住所などの情報が含まれなければならない.その中で、学号には唯一性があるべきだ.
2.設計プロセス
2.1学生クラスの作成
, 。
2.2学生情報管理システムの作成メニュー(すなわちホームページ)
、 、 、 、 , , 。
: switch , , , , 。
2.3すべての学生情報を照会する方法を作成する
: , “ , " " , 。” , , 。
2.4学生情報を追加する方法を作成し、その中で学生の学号が唯一であることを保証する.
: , , , , , ; , 。
2.5学生情報の削除方法の作成
: , , , , ; , , , 。
2.6学生関連情報の修正方法の作成
: , , , , ; , , , 。 , , 。
3.コード
3.1学生クラス(Student.java)のコードは以下の通りです.
/*
* , , 。
* : 、 、 、 、
*/
public class Student {
//
private String student_id;
private String student_name;
private String student_sex;
private String student_telephone;
private String student_address;
public Student() {
}
public Student(String student_id, String student_name, String student_sex, String student_telephone,
String student_address) {
this.student_id = student_id;
this.student_name = student_name;
this.student_sex = student_sex;
this.student_telephone = student_telephone;
this.student_address = student_address;
}
public String getStudent_id() {
return student_id;
}
public void setStudent_id(String student_id) {
this.student_id = student_id;
}
public String getStudent_name() {
return student_name;
}
public void setStudent_name(String student_name) {
this.student_name = student_name;
}
public String getStudent_sex() {
return student_sex;
}
public void setStudent_sex(String student_sex) {
this.student_sex = student_sex;
}
public String getStudent_telephone() {
return student_telephone;
}
public void setStudent_telephone(String student_telephone) {
this.student_telephone = student_telephone;
}
public String getStudent_address() {
return student_address;
}
public void setStudent_address(String student_address) {
this.student_address = student_address;
}
}
3.2マスタークラス(StudentManagerTest.java)のコードは次のとおりです.
import java.util.ArrayList;
import java.util.Scanner;
/*
*
* :
* 1.
* 2. ( )
* 3.
* 4. ,
* 5.
* 6.
*/
public class StudentManagerTest {
public static void main(String[] args) {
//
ArrayList array = new ArrayList();
while (true) {
//
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.
");
//
Scanner sc = new Scanner(System.in);
//
System.out.println(" :");
String option = sc.nextLine();
switch (option) {
//
case "1":
findAllStudentInfo(array);
break;
//
case "2":
addStudentInfo(array);
break;
//
case "3":
deleteStudentInfo(array);
break;
//
case "4":
updateStudentInfo(array);
break;
//
case "5":
System.out.println(" !");
// Java
System.exit(0);
break;
//
default:
System.out.println("
, !
");
break;
}
}
}
//
public static void findAllStudentInfo(ArrayList array) {
//
if (array.size() == 0) {
System.out.println("
, \" \" , 。
");
return;
}
System.out.println();
System.out.println("----------- -----------");
System.out.println(" \t\t \t \t \t\t ");
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (i != array.size() - 1)
System.out.println(s.getStudent_id() + "\t" + s.getStudent_name() + "\t" + s.getStudent_sex() + "\t"
+ s.getStudent_telephone() + "\t" + s.getStudent_address());
else
System.out.println(s.getStudent_id() + "\t" + s.getStudent_name() + "\t" + s.getStudent_sex() + "\t"
+ s.getStudent_telephone() + "\t" + s.getStudent_address() + "
");
}
}
//
public static void addStudentInfo(ArrayList array) {
//
Scanner sc = new Scanner(System.in);
String student_id;
System.out.println();
while (true) {
//
System.out.print(" :");
student_id = sc.nextLine();
//
boolean flag = false;
//
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (s.getStudent_id().equals(student_id)) {
flag = true;
break;
}
}
if (flag)
System.out.println(" , !
");
else
break;
}
System.out.print(" :");
String student_name = sc.nextLine();
System.out.print(" :");
String student_sex = sc.nextLine();
System.out.print(" :");
String student_telephone = sc.nextLine();
System.out.print(" :");
String student_address = sc.nextLine();
//
Student s = new Student();
s.setStudent_id(student_id);
s.setStudent_name(student_name);
s.setStudent_sex(student_sex);
s.setStudent_telephone(student_telephone);
s.setStudent_address(student_address);
//
array.add(s);
//
System.out.println("
!
");
}
//
public static void deleteStudentInfo(ArrayList array) {
//
Scanner sc = new Scanner(System.in);
//
System.out.println();
System.out.print(" :");
String student_id = sc.nextLine();
//
int index = -1;
//
Student s = null;
for (int i = 0; i < array.size(); i++) {
s = array.get(i);
if (s.getStudent_id().equals(student_id)) {
index = i;
break;
}
}
if (index == -1)
System.out.println("
, 。
");
else {
System.out.println("
, ?
\"1\" \" \", \" \"
");
System.out.println(" \t\t \t \t \t\t ");
System.out.println(s.getStudent_id() + "\t" + s.getStudent_name() + "\t" + s.getStudent_sex() + "\t"
+ s.getStudent_telephone() + "\t" + s.getStudent_address() + "
");
System.out.print(" :");
String j = sc.nextLine();
switch (j) {
case "1":
array.remove(index);
System.out.println("
:" + student_id + "
");
break;
default:
System.out.println("
:" + student_id + "
");
break;
}
}
}
//
public static void updateStudentInfo(ArrayList array) {
//
Scanner sc = new Scanner(System.in);
//
System.out.println();
System.out.print(" :");
String student_id = sc.nextLine();
//
int index = -1;
Student s = null;
for (int i = 0; i < array.size(); i++) {
s = array.get(i);
if (s.getStudent_id().equals(student_id)) {
index = i;
break;
}
}
if (index == -1)
System.out.println("
, 。
");
else {
System.out.println("
, ?
\"1\" \" \", \" \"
");
System.out.println(" \t\t \t \t \t\t ");
System.out.println(s.getStudent_id() + "\t" + s.getStudent_name() + "\t" + s.getStudent_sex() + "\t"
+ s.getStudent_telephone() + "\t" + s.getStudent_address() + "
");
System.out.print(" :");
String j = sc.nextLine();
switch (j) {
case "1":
System.out.println();
//
System.out.print(" :");
String student_name = sc.nextLine();
System.out.print(" :");
String student_sex = sc.nextLine();
System.out.print(" :");
String student_telephone = sc.nextLine();
System.out.print(" :");
String student_address = sc.nextLine();
//
s.setStudent_name(student_name);
s.setStudent_sex(student_sex);
s.setStudent_telephone(student_telephone);
s.setStudent_address(student_address);
System.out.println("
:" + student_id + " !
");
break;
default:
System.out.println("
:" + student_id + " !
");
break;
}
}
}
}