package homeWork;
import java.util.Scanner;
import static java.lang.System.exit;
public class IOSstudents {
public static Scanner input=new Scanner(System.in);
public static MySQL mySQL=new MySQL();
public static void main(String[] args) {
System.out.println("——————————————————————————欢迎使用学生管理系统——————————————————————————————————");
int flag=4;
while(true) {
System.out.println("你具有如下的功能选择:");
System.out.println("1:添加学生基本信息");
System.out.println("2:删除学生基本信息");
System.out.println("3:查找学生基本信息");
System.out.println("5:录入学生的基本成绩");
System.out.println("6:查询对应年级对应专业学生的总成绩");
System.out.println("4:退出学生管理系统");
flag=input.nextInt();
switch (flag){
case 1: Add();break;
case 2: Delect();break;
case 3: Discover();break;
case 4: System.out.println("——————————————————————————退出学生管理系统——————————————————————————————————");exit(0);
case 5: update();break;
case 6: SumScore();break;
default:exit(0);
}
}
}
private static void Add(){
int grade;
Speciality speciality;
String name,gender,province, city;
MyDate brithDate;
System.out.println("请输入你的必要信息");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("请输入年级");
grade=input.nextInt();
System.out.println("请选择你的专业:A为网络工程:B为软件工程.....");
char flag='c';
String s;
s=input.next();
flag=s.charAt(0);
if(flag=='A'){
speciality=Speciality.Wangluogongcheng;
}
else {
speciality=Speciality.Ruanjiangongchneg;
}
System.out.println("请输入你的名字");
name=input.next();
System.out.println("请输入你的性别");
gender=input.next();
System.out.println("请输入你的省份");
province=input.next();
System.out.println("请输入你的城市");
city=input.next();
System.out.println("填写你的出生日期 -- 年 -- 月 -- 日");
int year,month,day;
year=input.nextInt();
month=input.nextInt();
day=input.nextInt();
MyDate myDate=new MyDate(year,month,day);
Student student=new Student(grade,speciality,name,myDate,gender,province,city);
long number;
number=mySQL.add(student);
System.out.println("添加成功你的学号为:"+number);
}
private static void Delect(){
Speciality speciality;
System.out.println("请输入你的必要的删除信息");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("请输入你的专业:A为网络工程:B为软件工程.....");
char flag='c';
String s;
s=input.next();
flag=s.charAt(0);
if(flag=='A'){
speciality=Speciality.Wangluogongcheng;
}
else {
speciality=Speciality.Ruanjiangongchneg;
}
System.out.println("输入你的学号");
int num;
num=input.nextInt();
int flag1;
flag1= mySQL.delete(speciality,num);
if(flag1==1){
System.out.println("删除成功");
}
}
private static void Discover(){
Speciality speciality;
System.out.println("请输入你的必要的查询信息");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("请输入你的专业:A为网络工程:B为软件工程.....");
char flag='c';
String s;
s=input.next();
flag=s.charAt(0);
if(flag=='A'){
speciality=Speciality.Wangluogongcheng;
}
else {
speciality=Speciality.Ruanjiangongchneg;
}
System.out.println("输入你的学号");
long num;
num=input.nextInt();
int flag1;
flag1=mySQL.discover(speciality,num);
if(flag1==0){
System.out.println("没有此对应的消息");
}
}
private static void update(){
Speciality speciality;
System.out.println("请输入你的必要的查询信息");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("请输入你的专业:A为网络工程:B为软件工程.....");
char flag='c';
String s;
s=input.next();
flag=s.charAt(0);
if(flag=='A'){
speciality=Speciality.Wangluogongcheng;
}
else {
speciality=Speciality.Ruanjiangongchneg;
}
System.out.println("输入你的学号");
long num;
num=input.nextInt();
int flag1;
int score;
System.out.println("输入对应学号的成绩");
score=input.nextInt();
flag1=mySQL.update(speciality,num,score);
if(flag1==1){
System.out.println("成绩录入成功");
}
else {
System.out.println("成绩录入失败");
}
}
private static void SumScore(){
Speciality speciality;
System.out.println("请输入你的必要的查询信息");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("请输入你的专业:A为网络工程:B为软件工程.....");
char flag='c';
String s;
s=input.next();
flag=s.charAt(0);
if(flag=='A'){
speciality=Speciality.Wangluogongcheng;
}
else {
speciality=Speciality.Ruanjiangongchneg;
}
System.out.println("输入你的年级");
int grade;
double sum;
grade=input.nextInt();
sum=mySQL.SumScore(speciality,grade);
System.out.println("专业为:"+speciality+"年级为:"+grade+"总成绩为:"+sum);
}
}
package homeWork;
public class MyDate {
private int year,month,day;
private static int thisYear;
public int getMonth() {
return month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public void setYear(int year) {
this.year = year;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
static {
thisYear=2018;
}
public MyDate(int year,int month,int day){
this.day=day;
this.month=month;
this.year=year;
}
public MyDate(){
this(1900,1,1);
System.out.println("默认出生日期数据");
}
public static void set (){
}
public String toString(){
return year+" "+month+" "+day;
}
}
package homeWork;
import java.util.ArrayList;
import java.util.List;
public class MySQL {
private List<Student> list1=new ArrayList<Student>();//专业软件的
public static int count1=0;
private List<Student> list2=new ArrayList<Student>();//专业网络的
public static int count2=0;
public long add(Student student){
long num;
if(student.speciality.equals(Speciality.Ruanjiangongchneg)){
list1.add(student);
count1++;
num= student.number;
}
else {
list2.add(student);
count2++;
num= student.number;
}
return num;
}
public int delete(Speciality speciality,long number){
int flag=0;
if(speciality.equals(Speciality.Ruanjiangongchneg)){
for (Student student: list1) {
if (student.number==number){
list1.remove(student);
count1--;
flag=1;
break;
}
}
}
else {
for (Student student: list2) {
if (student.number==number){
list2.remove(student);
count1--;
flag=1;
break;
}
}
}
return flag;
}
public int discover(Speciality speciality,long number){
int flag=0;
if(speciality.equals(Speciality.Ruanjiangongchneg)){
for (Student student: list1) {
if (student.number==number){
System.out.println(student.toString());
flag=1;
break;
}
}
}
else {
for (Student student: list2) {
if (student.number==number){
System.out.println(student.toString());
flag=1;
break;
}
}
}
return flag;
}
public int update(Speciality speciality,long number,int score){
int flag=0;
if(speciality.equals(Speciality.Ruanjiangongchneg)){
int i=0;
for (Student student: list1) {
if (student.number==number){
student.score=score;
list1.set(i,student);
flag=1;
break;
}
i++;
}
}
else {
int i=0;
for (Student student: list2) {
if (student.number==number){
student.score=score;
list2.set(i,student);
flag=1;
break;
}
i++;
}
}
return flag;
}
public double SumScore(Speciality speciality,int grade){
double sum=0.0;
if(speciality.equals(Speciality.Ruanjiangongchneg)){
for (Student student: list1) {
if(student.grade==grade){
sum=sum+student.score;
System.out.println(student);
}
}
}
else {
for (Student student: list2) {
if(student.grade==grade){
sum=sum+student.score;
System.out.println(student);
}
}
}
return sum;
}
}
package homeWork;
public class Person {
public String name;
public MyDate brithDate;
public String gender,province,city;
private static int count=0;
protected Person(){
name="xxx";
brithDate=null;
gender="x";
city="x";
province="x";
}
protected Person(String name,MyDate brithDate, String gender,String province,String city){
this.brithDate=brithDate;
this.city=city;
this.gender=gender;
this.name=name;
this.province=province;
count++;
}
protected void set(){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MyDate getBrithDate() {
return brithDate;
}
public void setBrithDate(MyDate brithDate) {
this.brithDate = brithDate;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
package homeWork;
public enum Speciality {
Wangluogongcheng,Ruanjiangongchneg;
}
package homeWork;
public class Student extends Person {
public Speciality speciality;//专业
protected long number;
public int grade;
public int score=0;
public static int grade1=20170000;
public static int grade2=20180000;
public static int grade3=20190000;
public Student(int grade,Speciality speciality,String name,MyDate brithDate,String gender,String province,String city){
super(name,brithDate,gender,province,city);//调用构造函数在第一句
this.speciality=speciality;
this.grade=grade;
if(grade==2017){
number=grade1;
grade1++;
}
else if(grade==2018){
number=grade2;
grade2++;
}
else {
number=grade3;
grade3++;
}
}
public Student(int grade,Speciality speciality){
super();
this.speciality=speciality;
if(grade==2017){
number=grade1;
grade1++;
}
else if(grade==2018){
number=grade2;
grade2++;
}
else {
number=grade3;
grade3++;
}
}
public String toString(){
return "专业 "+speciality+"学号 "+number+"name: "+name+"brithDate: "+brithDate+"gender: "+gender+"province: "+province+"city: "+city+"score: "+score;
}
}