package com.st.text;
import java.util.ArrayList;
import java.util.Scanner;
import com.st.dao.StudentDao;
import com.st.entity.Student;
/**
- 在类中,主要是通过菜单部分,最终显示在控制台上,根据用户的输入需求完成显示
- @author 30693
*/
public class Text {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
muen();
}
public static void muen() {
System.out.println("-------------欢迎您来到生态学生管理系统------------------");
System.out.println("1.向系统中新增学生信息");
System.out.println("2.删除学生信息");
System.out.println("3.修改学生信息");
System.out.println("4.查询所有学生信息");
System.out.println("5.查询所有同样性别的信息");
System.out.println("6.退出系统");
System.out.println("------------------------------------------------");
while (true) {
System.out.print("请输入您要操作的编号:");
int choic = input.nextInt();
if (choic == 1) {
addStudent();
} else if (choic == 2) {
delStudent();
} else if (choic == 3) {
updStudent();
} else if (choic == 4) {
getAllStudent();
} else if (choic == 5) {
getStudentSex();
} else if (choic == 6) {
System.out.println("退出系统");
return;
}
}
}
/**
* 新增学生
*/
public static void addStudent() {
System.out.print("请输入新学生的编号:");
int id = input.nextInt();
System.out.print("请输入新学生的名字:");
String name = input.next();
System.out.print("请输入新学生的性别:");
String sex = input.next();
StudentDao sd = new StudentDao();
boolean flag = sd.addStudent(new Student(id, name, sex));
if (flag) {
System.out.println("学生信息新增成功");
} else {
System.out.println("学生信息新增失败");
}
}
/**
* 修改
*/
public static void updStudent() {
System.out.print("请输入您需要修改的学生编号:");
int id = input.nextInt();
System.out.print("请输入您需要修改的学生姓名:");
String name = input.next();
System.out.print("请输入您需要修改的学生性别:");
String sex = input.next();
StudentDao sd = new StudentDao();
boolean flag = sd.updateStudent(id, name, sex);
if (flag) {
System.out.println("编号为" + id + "的学生信息修改完毕");
} else {
System.out.println("编号为" + id + "的学生信息修改失败");
}
}
/**
* 查询
*/
public static void getAllStudent() {
StudentDao sd = new StudentDao();
ArrayList<Student> alist = sd.getAllStudent();
System.out.println("系统中所有的学生信息如下:");
System.out.println("学生编号\t学生姓名\t学生性别");
for (int i = 0; i < alist.size(); i++) {
System.out.println(alist.get(i));
}
}
/**
* 删除
*/
public static void delStudent() {
System.out.print("请输入您需要删除的学生编号:");
int id = input.nextInt();
StudentDao sd = new StudentDao();
boolean flag = sd.delStudent(id);
if (flag) {
System.out.println("编号为" + id + "的学生已经删除");
} else {
System.out.println("编号为" + id + "的学生不存在");
}
}
// public static void getStudentSex() {
// StudentDao sd = new StudentDao();
// ArrayList<Student> alist = sd.getAllStudent();
// System.out.print("请输入您要查询的学生的性别:");
// String sex = input.next();
// System.out.println("系统中所有的" + sex + "的信息如下:");
// System.out.println("学生编号\t学生姓名\t学生性别");
// for (int i = 0; i < alist.size(); i++) {
// Student s = alist.get(i);
// if (s.getStusex().equals(sex)) { // 判断是否相等
// System.out.println(s);
// }
// }
// }
public static void getStudentSex() {
System.out.print("请输入您要查询的性别:");
String sex=input.next();
StudentDao sd = new StudentDao();
ArrayList<Student> aList=new ArrayList<>();
aList=sd.getAllStudentSex(sex);
System.out.println("性别为"+sex+"学生信息如下:");
System.out.println("学生编号\t学生姓名\t学生性别");
for (int i = 0; i < aList.size(); i++) {
System.out.println(aList.get(i));
}
}
}
标签:Text,System,学生,StudentDao,println,sd,out From: https://www.cnblogs.com/Breeze-lele/p/17180564.html