package student;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Objects;
import java.util.Scanner;
/*
* 业务类 Manage
* 主要处理各种业务
* */
public class Manage {
int length = 0;
Student[] students = new Student[10];
Scanner input = new Scanner(System.in);
public Manage() {}
public void login(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入用户名");
while (!Objects.equals(sc.next(), "123456")){
System.out.println("用户名错误错误!请重新输入");
}
Scanner sc1=new Scanner(System.in);
System.out.println("请输入密码");
while (!Objects.equals(sc.next(), "123456")){
System.out.println("密码错误!请重新输入");
}
}
//添加记录方法
public void add() {
students[length] = new Student();
System.out.print("请输入学生的学号: ");
students[length].setNum(input.next());
System.out.print("请输入学生的姓名:");
students[length].setName(input.next());
System.out.print("请输入学生的性别:");
students[length].setSex(input.next());
System.out.print("请输入学生语文成绩:");
students[length].setYuwen(input.nextDouble());
System.out.print("请输入学生数学成绩:");
students[length].setMath(input.nextDouble());
System.out.print("请输入学生英语成绩:");
students[length].setEnlish(input.nextDouble());
System.out.print("请输入学生物理成绩:");
students[length].setWuli(input.nextDouble());
System.out.print("请输入学生地理成绩:");
students[length].setDili(input.nextDouble());
length++;
System.out.println("添加成功!");
}
//显示成绩单方法
public void transcript() {
System.out.println("=====================================");
System.out.println("学号 姓名 性别 语文 数学 英语 物理 地理 ");
for(int i = 0; i < length; i++) {
System.out.println(" "+students[i].getNum() + "\t"+ students[i].getName() + "\t" + students[i].getSex() + "\t" + students[i].getYuwen() + "\t" + students[i].getMath() + "\t" + students[i].getEnlish()+ "\t" + students[i].getWuli()+ "\t" + students[i].getDili());
}
System.out.println("=====================================\n");
}
public void sortYuwen(){
}
//删除学生记录方法
public void delete() {
System.out.print("请输入您要删除信息的学生的学号: ");
String number1 = input.next();
int i, flag = length;
for(i = 0; i < length; i++) {
if(number1.equals(students[i].getNum())) {
flag = i; break;
}
}
if(i == length) {
System.out.println("查无此人!请核对后重新输入 \n");
delete();
}
else {
for(int j = flag; j < length; j++) {
students[j] = students[j + 1];
}
System.out.println("删除成功!\n");
length -= 1; //不减1会报数组越界的错误
}
}
//修改学生信息方法
public void recompose() {
System.out.print("请输入您要修改信息的学生的学号:");
String number3 = input.next();
int i;
for(i = 0; i < length; i++) {
if(number3.equals(students[i].getNum())) {
System.out.println("请输入该学生新的学号,姓名,语文成绩,数学成绩,英语成绩:");
students[i].setNum(input.next());
students[i].setName(input.next());
students[i].setYuwen(input.nextDouble());
students[i].setMath(input.nextDouble());
students[i].setEnlish(input.nextDouble());
students[i].setWuli(input.nextDouble());
students[i].setDili(input.nextDouble());
System.out.println("修改成功!\n");
break;
}
}
if(i == length) {
System.out.println("查无此人!请核对后重新输入学号\n");
recompose();
}
}
public void daochu() throws IOException {
File file=new File("d:student\\student.txt");
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("学号 姓名 性别 语文 数学 英语 物理 化学");
fileWriter.write("\r\n");
for (int i = 0; i < students.length; i++) {
if (students[i]==null){
break;
}
String num=students[i].getNum();
String name=students[i].getName();
String sex=students[i].getSex();
Double yuwen=students[i].getYuwen();
Double math=students[i].getMath();
Double enlish=students[i].getEnlish();
Double dili=students[i].getDili();
Double wuli=students[i].getWuli();
fileWriter.write(num+" "+name+" "+sex+" "+yuwen+" "+math+" "+enlish+" "+wuli+" "+dili);
fileWriter.write("\r\n");
}
fileWriter.close();
System.out.println("导入成功");
}
}
评论0