亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

java實現(xiàn)學生宿舍系統(tǒng)

 更新時間:2022年03月16日 16:32:46   作者:DialogD  
這篇文章主要為大家詳細介紹了java實現(xiàn)學生宿舍系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現(xiàn)學生宿舍管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

學生類代碼

Student.java

package dormitory;

public class Student {
? ? private String ?id;
? ? private String name;
? ? private String sex;
? ? private String dormid;
? ? public String ?getId() {
? ? ? ? return id;
? ? }
? ? public void setId(String ?id) {
? ? ? ? this.id = id;
? ? }
? ? 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 String getDormid() {
? ? ? ? return dormid;
? ? }
? ? public void setDormid(String dormid) {
? ? ? ? this.dormid = dormid;
? ? }

}

主操作代碼

IntailStudent.java

package dormitory;
import java.awt.List;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

import javax.print.DocFlavor.INPUT_STREAM;
import javax.swing.event.ListSelectionEvent;

import org.omg.PortableInterceptor.IORInterceptor;


public class InitailStudent {
? ? private static int n=0;
? ? private static Student[] stu=new Student[100];
? ? //主函數(shù)
? ? public static void main(String[] args) throws IOException {
? ? ? ? boolean a=false;
? ? ? ? boolean b=false;
? ? ? ? InitailStudent student=new InitailStudent();
? ? ? ? student.judge(a, b);
? ? }
? ? //登入函數(shù)
? ? private void judge(boolean a, boolean b) throws IOException
? ? {
? ? ? ? do {
? ? ? ? ? ? System.out.println("歡迎進入登入頁面!");
? ? ? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? ? ? System.out.println("請輸入賬號:");
? ? ? ? ? ? String account=input.nextLine();
? ? ? ? ? ? System.out.println("請輸入密碼:");
? ? ? ? ? ? String code=input.nextLine();
? ? ? ? ? ? a=account.equals("admin");
? ? ? ? ? ? b=code.equals("admin");
? ? ? ? } while(!(a==true&&b==true));

? ? ? ? Menu();?
? ? }

? ? //系統(tǒng)菜單頁面
? ? private void Menu() throws IOException{
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? System.out.println("------ ?歡迎進入宿舍管理系統(tǒng) ?------");
? ? ? ? System.out.println("------ ?請選擇下列操作 ? ? ? ? ? ? ------");
? ? ? ? System.out.println("--- ? ? 1.顯示所有學生信息 ? ? ? ? ?---"); ? ? ?//Show()
? ? ? ? System.out.println("--- ? ? 2.查詢學生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Find()
? ? ? ? System.out.println("--- ? ? 3.增加學生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Add()
? ? ? ? System.out.println("--- ? ? 4.修改學生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Renew()
? ? ? ? System.out.println("--- ? ? 5.刪除學生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Delete()
? ? ? ? System.out.println("--- ? ? 0.退出系統(tǒng) ? ? ? ? ? ? ? ? ? ? ? ? ---");
? ? ? ? System.out.println("請輸入1~5:");
? ? ? ? int a=input.nextInt();
? ? ? ? while(a<0||a>5)
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入有誤,請重新輸入:");
? ? ? ? ? ? a=input.nextInt();
? ? ? ? }
? ? ? ? switch (a) {
? ? ? ? case 1:
? ? ? ? ? ? Show();
? ? ? ? ? ? break;
? ? ? ? case 2:
? ? ? ? ? ? Find();
? ? ? ? ? ? break;
? ? ? ? case 3:
? ? ? ? ? ? Add();
? ? ? ? ? ? break;
? ? ? ? case 4:
? ? ? ? ? ? Renew();
? ? ? ? ? ? break;
? ? ? ? case 5:
? ? ? ? ? ? Delete();
? ? ? ? ? ? break;
? ? ? ? case 0:
? ? ? ? ? ? System.out.println("成功退出系統(tǒng)!");
? ? ? ? ? ? System.exit(0);
? ? ? ? ? ? break;
? ? ? ? }
? ? }

? ? //顯示學生的全部信息
? ? private void Show() throws IOException{
? ? ? ? System.out.println("您總錄入的信息如下:");
? ? ? ? System.out.println("*****************************");
? ? ? ? BufferedReader br=new BufferedReader(new FileReader("student.txt"));
? ? ? ? String line;
? ? ? ? while((line=br.readLine())!=null){
? ? ? ? ? ? System.out.println(line);
? ? ? ? }
? ? ? ? br.close();
? ? ? ? System.out.println("\n\r");
? ? ? ? System.out.println("此次錄入的信息為");
? ? ? ? System.out.println("*****************************");
? ? ? ? int i;
? ? ? ? for(i=0;i<n;i++)
? ? ? ? {
? ? ? ? ? ? System.out.println("學號:"+stu[i].getId()+"\t姓名:"+stu[i].getName()+"\t性別:"+stu[i].getSex()+"\t宿舍號:"+stu[i].getDormid());
? ? ? ? }
? ? ? ? System.out.println("返回主菜單");
? ? ? ? Menu();

? ? }?

? ? //查詢學生信息
? ? private void Find() throws IOException{
? ? ? ? ArrayList<ArrayList<String>> lists = new ArrayList<>();
? ? ? ? BufferedReader br=new BufferedReader(new FileReader("student.txt"));
? ? ? ? String line;
? ? ? ? ArrayList<String> list = new ArrayList<>();
? ? ? ? ArrayList<String> validlist = new ArrayList<>();
? ? ? ? while((line=br.readLine())!=null){
? ? ? ? ? ? list.add(line.toString());
? ? ? ? }
? ? ? ? br.close();
? ? ? ? for(int i = 0;i<list.size();i++)

? ? ? ? ? ? if(i!=0&&list.get(i-1).startsWith("學號")){
? ? ? ? ? ? ? ? validlist.add(list.get(i));

? ? ? ? }
? ? ? ? for (String string : validlist) {
? ? ? ? ? ? String[] split = string.split(" ? ? ");
? ? ? ? ? ? ArrayList<String> tempString = new ArrayList<>();
? ? ? ? ? ? for (String string2 : split) {
? ? ? ? ? ? ? ? tempString.add(string2);
? ? ? ? ? ? }

? ? ? ? ? ? lists.add(tempString);
? ? ? ? } ??
? ? ? ? System.out.println("共有"+lists.size()+"個學生信息");
? ? ? ? String[][] stu1=new String[lists.size()][4];
? ? ? ? for(int i=0;i<lists.size();i++)
? ? ? ? ? ? for(int j=0;j<4;j++){
? ? ? ? ? ? ? ? stu1[i][j]=lists.get(i).get(j);
? ? ? ? ? ? }
? ? ? ? System.out.println("請輸入學生的學號:");
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? String ?d=input.next();
? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? {
? ? ? ? ? ? if(d.equals(stu1[i][0]))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("查詢成功,以下為該學生的信息");
? ? ? ? ? ? ? ? System.out.println("學號:"+stu1[i][0]+"\t姓名:"+stu1[i][1]+"\t性別:"+stu1[i][2]+"\t宿舍號:"+stu1[i][3]);
? ? ? ? ? ? ? ? System.out.println("是否繼續(xù)查詢,否返回菜單,是Y否N");
? ? ? ? ? ? ? ? String cho=input.next();
? ? ? ? ? ? ? ? char ch=cho.charAt(0);
? ? ? ? ? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? System.out.println("輸入有誤!請重新輸入:");
? ? ? ? ? ? ? ? ? ? cho=input.next();
? ? ? ? ? ? ? ? ? ? ch=cho.charAt(0);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? while(ch=='Y'||ch=='y'){
? ? ? ? ? ? ? ? ? ? Find();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? while(ch=='N'||ch=='n'){
? ? ? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? ? ? }

? ? ? ? ? ? }
? ? ? ? }
? ? ? ? System.out.println("沒有找到該學生,是繼續(xù)輸入,否返回菜單,是Y否N");
? ? ? ? String cho=input.next();
? ? ? ? char ch=cho.charAt(0);
? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入有誤!請重新輸入:");
? ? ? ? ? ? cho=input.next();
? ? ? ? ? ? ch=cho.charAt(0);
? ? ? ? }
? ? ? ? while(ch=='Y'||ch=='y'){
? ? ? ? ? ? Find();
? ? ? ? }
? ? ? ? while(ch=='N'||ch=='n'){
? ? ? ? ? ? Menu();
? ? ? ? }
? ? }

? ? //增加一個學生
? ? private void Add() throws IOException{
? ? ? ? String ?id;
? ? ? ? String dormid;
? ? ? ? String name;
? ? ? ? String sex;
? ? ? ? String cho;
? ? ? ? char ch;
? ? ? ? stu[n]=new Student();
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? if(n==0)
? ? ? ? {

? ? ? ? ? ? System.out.println("您此次還沒有錄入任何信息,是否錄入,是Y否N");
? ? ? ? ? ? cho=input.next();
? ? ? ? ? ? ch=cho.charAt(0);

? ? ? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("輸入有誤!請重新輸入:");
? ? ? ? ? ? ? ? cho=input.next();
? ? ? ? ? ? ? ? ch=cho.charAt(0);
? ? ? ? ? ? }

? ? ? ? ? ? while(ch=='Y'||ch=='y'){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? while(ch=='N'||ch=='n'){
? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? FileWriter fw=new FileWriter("student.txt",true);
? ? ? ? fw.write("\r\n");
? ? ? ? fw.write("學號 ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號 \r\n");
? ? ? ? System.out.println("請輸入學生的學號:");
? ? ? ? id=input.next();
? ? ? ? stu[n].setId(id);
? ? ? ? fw.write(stu[n].getId()+" ? ? ? ");
? ? ? ? System.out.println("請輸入學生的姓名:");
? ? ? ? name=input.next();
? ? ? ? stu[n].setName(name);
? ? ? ? fw.write(stu[n].getName()+" ? ? ");
? ? ? ? System.out.println("請輸入學生的性別:");
? ? ? ? sex=input.next();
? ? ? ? stu[n].setSex(sex);
? ? ? ? fw.write(stu[n].getSex()+" ? ? ?");
? ? ? ? System.out.println("請輸入學生的宿舍號:");
? ? ? ? dormid=input.next();
? ? ? ? stu[n].setDormid(dormid);
? ? ? ? fw.write(stu[n].getDormid()+" ? ? ? ");
? ? ? ? n++;
? ? ? ? fw.close();
? ? ? ? System.out.println("是否繼續(xù)添加學生?否返回主菜單,是Y否N");
? ? ? ? cho=input.next();
? ? ? ? ch=cho.charAt(0);
? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入有誤!請重新輸入:");
? ? ? ? ? ? cho=input.next();
? ? ? ? ? ? ch=cho.charAt(0);
? ? ? ? }
? ? ? ? while(ch=='Y'||ch=='y'){
? ? ? ? ? ? Add();
? ? ? ? }
? ? ? ? while(ch=='N'||ch=='n'){
? ? ? ? ? ? Menu();
? ? ? ? }
? ? }

? ? //修改學生信息
? ? private void Renew() throws IOException{
? ? ? ? ArrayList<ArrayList<String>> lists = new ArrayList<>();
? ? ? ? BufferedReader br=new BufferedReader(new FileReader("student.txt"));
? ? ? ? String line;
? ? ? ? ArrayList<String> list = new ArrayList<>();
? ? ? ? ArrayList<String> validlist = new ArrayList<>();
? ? ? ? while((line=br.readLine())!=null){
? ? ? ? ? ? list.add(line.toString());
? ? ? ? }
? ? ? ? br.close();
? ? ? ? for(int i = 0;i<list.size();i++)

? ? ? ? ? ? if(i!=0&&list.get(i-1).startsWith("學號")){
? ? ? ? ? ? ? ? validlist.add(list.get(i));

? ? ? ? }
? ? ? ? for (String string : validlist) {
? ? ? ? ? ? String[] split = string.split(" ? ? ");
? ? ? ? ? ? ArrayList<String> tempString = new ArrayList<>();
? ? ? ? ? ? for (String string2 : split) {
? ? ? ? ? ? ? ? tempString.add(string2);
? ? ? ? ? ? }

? ? ? ? ? ? lists.add(tempString);
? ? ? ? } ??
? ? ? ? String[][] stu1=new String[lists.size()][4];
? ? ? ? for(int i=0;i<lists.size();i++)
? ? ? ? ? ? for(int j=0;j<4;j++){
? ? ? ? ? ? ? ? stu1[i][j]=lists.get(i).get(j);
? ? ? ? ? ? }

? ? ? ? int temp=0;
? ? ? ? boolean flag=false;
? ? ? ? System.out.println("請輸入要修改學生的學號:");
? ? ? ? Scanner input=new Scanner(System.in);
? ? ? ? String ?d=input.next();
? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? {
? ? ? ? ? ? while(d.equals(stu1[i][0]))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp=i;
? ? ? ? ? ? ? ? flag=true;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(!flag)
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入的學號有誤,未找到該學生,是否再次進入修改,是Y,否N");
? ? ? ? ? ? String cho1=input.next();
? ? ? ? ? ? char ch1=cho1.charAt(0);
? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y')
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? ? ? cho1=input.next();
? ? ? ? ? ? ? ? ch1=cho1.charAt(0);
? ? ? ? ? ? }
? ? ? ? ? ? if (ch1=='y'||ch1=='Y'){
? ? ? ? ? ? ? ? Renew();
? ? ? ? ? ? }
? ? ? ? ? ? if (ch1=='N'||ch1=='n'){
? ? ? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? }?
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? System.out.println("您要修改的學生的信息如下:");
? ? ? ? ? ? System.out.println("學號:"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性別:"+stu1[temp][2]+"\t宿舍號:"+stu1[temp][3]);
? ? ? ? ? ? System.out.println("請以下選擇要修改的內(nèi)容:");
? ? ? ? ? ? System.out.println("------ ? 1.姓名 ? ? ? ------");
? ? ? ? ? ? System.out.println("------ ? 2.性別 ? ? ? ------");
? ? ? ? ? ? System.out.println("------ ? 3.宿舍號 ? ? ?------");
? ? ? ? ? ? Scanner input1=new Scanner(System.in);
? ? ? ? ? ? int a=input1.nextInt();
? ? ? ? ? ? if(a==1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("請輸入新的姓名:");
? ? ? ? ? ? ? ? String name=input1.next();
? ? ? ? ? ? ? ? stu1[temp][1]=name;
? ? ? ? ? ? ? ? FileWriter fw1=new FileWriter("student.txt");
? ? ? ? ? ? ? ? fw1.write(" ? ? ?");
? ? ? ? ? ? ? ? fw1.close();
? ? ? ? ? ? ? ? FileWriter fw=new FileWriter("student.txt",true);
? ? ? ? ? ? ? ? fw.write("\r\n"+" ? ? ? ? ? "+"學生信息表\r\n");
? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? fw.write("\r\n學號 ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號 \r\n");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][0]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][1]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][2]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][3]+" ? ? ? ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? fw.close();
? ? ? ? ? ? ? ? System.out.println("修改成功!");
? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?是繼續(xù)修改,否返回主菜單,是Y否N");
? ? ? ? ? ? ? ? String cho1=input1.next();
? ? ? ? ? ? ? ? char ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y')
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? ? ? ? ? cho1=input.next();
? ? ? ? ? ? ? ? ? ? ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='y'||ch1=='Y'){
? ? ? ? ? ? ? ? ? ? Renew();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='N'||ch1=='n'){
? ? ? ? ? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? }
? ? ? ? ? ? else if(a==2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("請輸入新的性別:");
? ? ? ? ? ? ? ? String sex=input1.next();
? ? ? ? ? ? ? ? stu1[temp][2]=sex;
? ? ? ? ? ? ? ? FileWriter fw1=new FileWriter("student.txt");
? ? ? ? ? ? ? ? fw1.write(" ? ? ?");
? ? ? ? ? ? ? ? fw1.close();
? ? ? ? ? ? ? ? FileWriter fw=new FileWriter("student.txt",true);
? ? ? ? ? ? ? ? fw.write("\r\n"+" ? ? ? ? ? "+"學生信息表\r\n");
? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? fw.write("\r\n學號 ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號 \r\n");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][0]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][1]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][2]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][3]+" ? ? ? ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? fw.close();
? ? ? ? ? ? ? ? System.out.println("修改成功!");
? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?是繼續(xù)修改,否返回主菜單,是Y否N");
? ? ? ? ? ? ? ? String cho1=input1.next();

? ? ? ? ? ? ? ? char ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y')
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? ? ? ? ? cho1=input.next();
? ? ? ? ? ? ? ? ? ? ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='y'||ch1=='Y'){
? ? ? ? ? ? ? ? ? ? Renew();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='N'||ch1=='n'){
? ? ? ? ? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? }
? ? ? ? ? ? else if(a==3)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("請輸入新的宿舍號:");
? ? ? ? ? ? ? ? String ?dormid=input1.next();
? ? ? ? ? ? ? ? stu1[temp][3]=dormid;
? ? ? ? ? ? ? ? FileWriter fw1=new FileWriter("student.txt");
? ? ? ? ? ? ? ? fw1.write(" ? ? ?");
? ? ? ? ? ? ? ? fw1.close();
? ? ? ? ? ? ? ? FileWriter fw=new FileWriter("student.txt",true);
? ? ? ? ? ? ? ? fw.write("\r\n"+" ? ? ? ? ? "+"學生信息表\r\n");
? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? fw.write("\r\n學號 ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號 \r\n");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][0]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][1]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][2]+" ? ? ? ");
? ? ? ? ? ? ? ? ? ? fw.write(stu1[i][3]+" ? ? ? ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? fw.close();
? ? ? ? ? ? ? ? System.out.println("修改成功!");
? ? ? ? ? ? ? ? System.out.println("還要繼續(xù)修改嗎?是繼續(xù)修改,否返回主菜單,是Y否N");
? ? ? ? ? ? ? ? String cho1=input1.next();
? ? ? ? ? ? ? ? char ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y')
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? ? ? ? ? cho1=input.next();
? ? ? ? ? ? ? ? ? ? ch1=cho1.charAt(0);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='y'||ch1=='Y'){
? ? ? ? ? ? ? ? ? ? Renew();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (ch1=='N'||ch1=='n'){
? ? ? ? ? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? System.out.println("輸入有誤,請重新輸入:");
? ? ? ? ? ? ? ? Renew();
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? //刪除學生信息
? ? private void Delete() throws IOException{
? ? ? ? ArrayList<ArrayList<String>> lists = new ArrayList<>();
? ? ? ? BufferedReader br=new BufferedReader(new FileReader("student.txt"));
? ? ? ? String line;
? ? ? ? ArrayList<String> list = new ArrayList<>();
? ? ? ? ArrayList<String> validlist = new ArrayList<>();
? ? ? ? while((line=br.readLine())!=null){
? ? ? ? ? ? list.add(line.toString());
? ? ? ? }
? ? ? ? br.close();
? ? ? ? for(int i = 0;i<list.size();i++)

? ? ? ? ? ? if(i!=0&&list.get(i-1).startsWith("學號")){
? ? ? ? ? ? ? ? validlist.add(list.get(i));

? ? ? ? }
? ? ? ? for (String string : validlist) {
? ? ? ? ? ? String[] split = string.split(" ? ? ");
? ? ? ? ? ? ArrayList<String> tempString = new ArrayList<>();
? ? ? ? ? ? for (String string2 : split) {
? ? ? ? ? ? ? ? tempString.add(string2);
? ? ? ? ? ? }

? ? ? ? ? ? lists.add(tempString);
? ? ? ? }
? ? ? ? String[][] stu1=new String[lists.size()][4];
? ? ? ? for(int i=0;i<lists.size();i++)
? ? ? ? ? ? for(int j=0;j<4;j++){
? ? ? ? ? ? ? ? stu1[i][j]=lists.get(i).get(j);
? ? ? ? ? ? }
? ? ? ? int temp=0;
? ? ? ? boolean flag=true;
? ? ? ? System.out.println("請輸入你想要刪除該學生的學號:");
? ? ? ? Scanner input2=new Scanner(System.in);
? ? ? ? String ?d=input2.next();
? ? ? ? for(int i=0;i<stu1.length;i++)
? ? ? ? {
? ? ? ? ? ? while(d.equals(stu1[i][0]))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? temp=i;
? ? ? ? ? ? ? ? flag=true;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(!flag)
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入的學號有誤,未找到該學生,再次進入刪除,請重新輸入:");
? ? ? ? ? ? String cho1=input2.next();
? ? ? ? ? ? char ch1=cho1.charAt(0);
? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y')
? ? ? ? ? ? {
? ? ? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? ? ? cho1=input2.next();
? ? ? ? ? ? ? ? ch1=cho1.charAt(0);
? ? ? ? ? ? }
? ? ? ? ? ? if (ch1=='y'||ch1=='Y'){
? ? ? ? ? ? ? ? Delete();
? ? ? ? ? ? }
? ? ? ? ? ? if (ch1=='N'||ch1=='n'){
? ? ? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? ? ? Menu();
? ? ? ? ? ? }?

? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? System.out.println("您要刪除的學生的信息如下:");
? ? ? ? ? ? System.out.println("學號:"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性別:"+stu1[temp][2]+"\t宿舍號:"+stu1[temp][3]);
? ? ? ? ? ? for (int i=temp;i<stu1.length-1;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? stu1[i]=stu1[i+1];
? ? ? ? ? ? }
? ? ? ? ? ? FileWriter fw1=new FileWriter("student.txt");
? ? ? ? ? ? fw1.write(" ? ? ?");
? ? ? ? ? ? fw1.close();
? ? ? ? ? ? FileWriter fw=new FileWriter("student.txt",true);
? ? ? ? ? ? fw.write("\r\n"+" ? ? ? ? ? "+"學生信息表\r\n");
? ? ? ? ? ? for(int i=0;i<stu1.length-1;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? fw.write("\r\n學號 ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號 \r\n");
? ? ? ? ? ? ? ? fw.write(stu1[i][0]+" ? ? ? ");
? ? ? ? ? ? ? ? fw.write(stu1[i][1]+" ? ? ? ");
? ? ? ? ? ? ? ? fw.write(stu1[i][2]+" ? ? ? ");
? ? ? ? ? ? ? ? fw.write(stu1[i][3]+" ? ? ? ");
? ? ? ? ? ? }
? ? ? ? ? ? fw.close(); ??
? ? ? ? ? ? System.out.println("刪除該學生信息成功!");
? ? ? ? ? ? System.out.println("---------------------");
? ? ? ? }
? ? ? ? System.out.println("還要繼續(xù)刪除嗎?是繼續(xù)刪除,否返回主菜單,是Y否N");
? ? ? ? String cho2=input2.next();
? ? ? ? char ch2=cho2.charAt(0);
? ? ? ? while (ch2!='N'&&ch2!='n'&&ch2!='Y'&&ch2!='y')
? ? ? ? {
? ? ? ? ? ? System.out.println("輸入無效,請重新輸入:");
? ? ? ? ? ? cho2=input2.next();
? ? ? ? ? ? ch2=cho2.charAt(0);
? ? ? ? }
? ? ? ? if (ch2=='y'||ch2=='Y'){
? ? ? ? ? ? Delete();
? ? ? ? }
? ? ? ? if (ch2=='N'||ch2=='n'){
? ? ? ? ? ? System.out.println("返回主菜單");
? ? ? ? ? ? Menu();
? ? ? ? }?

? ? }
?}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論