当前位置:网站首页>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;
}
}
边栏推荐
- Instant messaging project (I)
- Use of pytorch tensorboard
- Detailed summary of flex layout
- Various pits encountered in the configuration of yolov3 on win10
- Notes on non replacement elements in the line (padding, margin, and border)
- 2022.1.21 diary
- HR took the initiative to raise the salary of the test lady. How did she do it?
- Deeply understand the characteristics of standard flow and off standard elements
- Excel splits a worksheet into multiple worksheets according to conditions, and how to split multiple worksheets into independent tables
- Fundamentals of C language
猜你喜欢

Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review

Personalized Federated Learning with Moreau Envelopes

Deep analysis of recursion in quick sorting

C language -- Sanzi chess

Voxel based and second network learning

Use of MySQL variables

Design of IM login server and message server

Use serialize in egg to read and write split tables

UVA816 Abbott’s Revenge

Jenkins installation and configuration
随机推荐
Jason learning
Semantic segmentation cvpr2020 unsupervised intra domain adaptation for semantic segmentation through self supervision
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30
Oracle SQL statement operand: rounding, rounding, differentiation and formatting
Design of IM login server and message server
Charles and iPhone capture
Page electronic clock (use js to dynamically obtain time display)
Word quickly makes multiple single-sided table labels, number plates, etc
Get the first letter of Chinese phonetic alphabet in Excel and capitalize it
DOM document object model (I)
2022.1.23 diary
Analysis of IM project framework
[QT] for multithreaded programs, do not use the printf() function to print out
Day16 (regular expression, enumeration)
Synchonized introduction
CVPR2021-Semi-supervised Domain Adaptation based on Dual-level Domain Mixing for Semantic Segmentati
Incorrect dependency of POM file
Learn the interface test, see it is very good, and make a note
First blog
Professional things use professional people