创建简单的学生管理系统
作者:互联网
package com.bk;
public class Student {
public String mark; //学号
public String name;
public String sex;
public int age;
public String grade;//年级
public String professional;//专业
public String homeAddress; //家庭住址
public Student() {
super();
}
public Student(String mark, String name, String sex, int age, String grade, String professional,
String homeAddress) {
super();
this.mark = mark;
this.name = name;
this.sex = sex;
this.age = age;
this.grade = grade;
this.professional = professional;
this.homeAddress = homeAddress;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getProfessional() {
return professional;
}
public void setProfessional(String professional) {
this.professional = professional;
}
public String getHomeAddress() {
return homeAddress;
}
public void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}
@Override
public String toString() {
return "学号:"+mark+"\n"
+"姓名:"+name+"\n"
+"性别:"+sex+"\n"
+"年龄:"+age+"\n"
+"年级:"+grade+"\n"
+"专业:"+professional+"\n"
+"家庭住址:"+homeAddress;
}
}
package com.bk;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentDAO {
Student arr1 = new Student();
ArrayList list = new ArrayList();
Scanner sc = new Scanner(System.in);
/**
* 添加学生
*/
public void addStudent() {
System.out.println("学生学号:");
String mark = sc.next();
System.out.println("学生姓名:");
String name = sc.next();
System.out.println("学生性别:");
String sex = sc.next();
System.out.println("学生年龄:");
int age = sc.nextInt();
System.out.println("学生年级:");
String grade = sc.next();
System.out.println("学生专业:");
String professional = sc.next();
System.out.println("学生家庭住址:");
String homeAddress = sc.next();
Student arr2 = new Student(mark,name,sex,age,grade,professional,homeAddress);
list.add(arr2);
}
/**
* 输出学生,学生信息表
*/
public void showStudents() {
for (int i = 0; i < list.size(); i++) {
Student s = list.get(i);
System.out.println(s);// 运行的是类中的toString
}
}
/**
* 查询某一个专业的学生的信息
*/
public void InquireProfessional() {
System.out.println("请输入你要查询的专业:");
String professional = sc.next();
for(int i = 0; i if(professional.equals(list.get(i).getProfessional())) {
System.out.println(list.get(i));
}else {
System.out.println("没有你要查询的专业");
}
}
}
/**
* 修改专业名称
*/
public void ReviseProfessional() {
System.out.println("请输入你要修改的专业:");
String professional = sc.next();
System.out.println("请输入修改后的专业:");
String s = sc.next();
for(int i = 0; i Student s1 = list.get(i);
if(professional.equals(list.get(i).getProfessional())) {
System.out.println("修改前的学生信息:");
System.out.println(list.get(i));
System.out.println("====修改成功====");
System.out.println("修改后的学生信息:");
s1.setProfessional(s);
System.out.println(list.get(i));
}else {
System.out.println("学生信息不存在");
}
}
}
/**
* 菜单
*/
public void menu() {
System.out.println("1.添加学生");
System.out.println("2.学生信息表");
System.out.println("3.查询某一个专业的学生的信息");
System.out.println("4.修改专业名称");
System.out.println("请输入你要选择的选项:");
int num = sc.nextInt();
switch(num) {
case 1:
addStudent();
menu();
break;
case 2:
showStudents();
menu();
break;
case 3:
InquireProfessional() ;
menu();
break;
case 4:
ReviseProfessional() ;
menu();
break;
}
}
}
package com.bk;
import java.util.ArrayList;
public class StudentTest {
public static void main(String[] args) {
StudentDAO st = new StudentDAO();
System.out.println("========学生管理系统======");
st.menu();
}
}
标签:String,管理系统,创建,System,学生,println,professional,public,out 来源: https://blog.csdn.net/m0_58566454/article/details/118277393