当前位置:网站首页>Simple student management system
Simple student management system
2022-06-25 05:41:00 【JiaXingNashishua】
import java.util.Scanner;
import java.util.ArrayList;
public class studentDemo {
public static void main(String[] args) {
ArrayList<student> array = new ArrayList<student>();
Scanner sc = new Scanner(System.in);
int i = 0;
do {
System.out.println("------- Welcome to the student management system -------");
System.out.println("1. Add student ");
System.out.println("2. Delete students ");
System.out.println("3. Revise students ");
System.out.println("4. Check out all the students ");
System.out.println("5. sign out ");
System.out.println(" Please enter your choice :");
i = sc.nextInt();
if (i == 1) {
toAdd(array);
} else if (i == 2) {
toRemove(array);
} else if (i == 3) {
toSet(array);
} else if (i == 4) {
toGet(array);
}
else if(i!=5){
System.out.println(" The choice you entered is wrong , Please re-enter !!!");
}
}
while (i != 5);
System.out.println(" Thank you for using. !!!");
}
public static void toRemove(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the name of the student you want to delete :");
String name = sc.nextLine();
for (int i = 0; i < array.size(); i++) {
student s = array.get(i);
if (s.getName().equals(name)) {
array.remove(i);
System.out.println(" Delete student information successfully !!!");
return;
}
}
System.out.println(" Check no one , Please re-enter the information !!!");
}
public static void toSet(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the name of the student you want to modify :");
String name = sc.nextLine();
for (int i = 0; i < array.size(); i++) {
student s2 = array.get(i);
if (s2.getName().equals(name)) {
student s = new student();
System.out.println(" Please enter the new name of the student you want to modify ");
s.setName(sc.nextLine());
System.out.println(" Please enter the new age of the student you want to modify :");
s.setAge(sc.nextLine());
System.out.println(" Please enter the new student number of the student you want to modify :");
s.setId(sc.nextLine());
System.out.println(" Please enter the new address of the student you want to modify :");
s.setDi(sc.nextLine());
array.set(i, s);
System.out.println(" The information was modified successfully !!!");
return;// End this method directly
}
}
System.out.println(" Check no one , Please re-enter the information !!!");
}
public static void toGet(ArrayList<student> array) {
// toGet(array);
// \t: In fact, that is tab Key position
// Shortcut key :ctrl+alt+l: formatting code
if (array.size() == 0) {
System.out.println(" No information , Please add information before querying !!!");
// It's OK in the back here + return;----- It means to end
} else {
System.out.println(" The student's name \t Student age \t Student student id \t Student address ");
for (int j = 0; j < array.size(); j++) {
student s = new student();
s = array.get(j);
System.out.println(s.getName() + "\t" + s.getAge() + " year \t" + s.getId() + "\t\t" + s.getDi());
}
}
}
public static void toAdd(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
student s = new student();
String name;
while (true) {
System.out.println(" Please enter the name of the added student :");
name = sc.nextLine();
boolean flag = isUsed(array, name);
if (flag) {
System.out.println(" The student name you entered is already occupied , Please re-enter !!!");
} else {
break;
}
}
System.out.println(" Please enter the age of the added student :");
String age = sc.nextLine();
System.out.println(" Please enter the student ID of the added student :");
String id = sc.nextLine();
System.out.println(" Please enter the address of the added student :");
String di = sc.nextLine();
s.setName(name);
s.setAge(age);
s.setId(id);
s.setDi(di);
array.add(s);
System.out.println(" Add student successfully !!!");
}
public static boolean isUsed(ArrayList<student> array, String name) {
boolean flag = false;
for (int i = 0; i < array.size(); i++) {
student s = array.get(i);
if (s.getName().equals(name)) {
flag = true;
break;
}
}
return flag;
}
}
class student {
private String name;// name
private String age;// Age
private String id;// Student number
private String di;// Address
public student() {
}
// Shortcut key :alt+ins---- Methods can be constructed quickly
public student(String name, String age, String id, String di) {
this.name = name;
this.age = age;
this.id = id;
this.di = di;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDi() {
return di;
}
public void setDi(String di) {
this.di = di;
}
}
边栏推荐
- DOM document object model (I)
- Day16 (regular expression, enumeration)
- A method of automatic continuation of previous tables in word table
- JS handwriting depth clone array and object
- ERDAS 9.2 installation tutorial
- Classic usage of the sumproduct function
- [day40 literature extensive reading] space and time in the child's mind: metallic or atomic
- C style string
- Use of pytorch tensorboard
- Voxel based and second network learning
猜你喜欢

Day18 (set, generic, hash table, tree, stack and queue, graph, array and linked list)

Small sample learning data set

BUUCTF(web:1-50)

Create an environment for new projects

2022.1.25
![[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30](/img/c7/e38a7a5cd4c1e4105c3f3f246276c6.jpg)
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30

Classic usage of the sumproduct function

How to add an external header file in vs?

Various pits encountered in the configuration of yolov3 on win10

Detailed summary of flex layout
随机推荐
Go Basics
A summary of the experiment of continue and break in C language
2022.1.23 diary
Array: force deduction dichotomy
[QT] for multithreaded programs, do not use the printf() function to print out
Penetration test - right raising topic
Guava immutable set
Guava-IO
Get the first letter of Chinese phonetic alphabet in Excel and capitalize it
Handwritten promise all
Using JS to realize the sidebar of life information network
Click to jump out and drag the pop-up window
JMeter stress testing and agent recording
By inserting a section break, the word header, footer, and page number can start from any page
05 virtual machine stack
投资理财产品的年限要如何选?
Day13 (inner class, anonymous inner class, API common class)
Understand JS high-order function and write a high-order function
Could not find “store“ in the context of “Connect(homePage)
Common cluster deployment schemes in redis