java實(shí)現(xiàn)學(xué)生宿舍系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)學(xué)生宿舍管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
學(xué)生類代碼
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("歡迎進(jìn)入登入頁(yè)面!"); ? ? ? ? ? ? Scanner input=new Scanner(System.in); ? ? ? ? ? ? System.out.println("請(qǐng)輸入賬號(hào):"); ? ? ? ? ? ? String account=input.nextLine(); ? ? ? ? ? ? System.out.println("請(qǐng)輸入密碼:"); ? ? ? ? ? ? String code=input.nextLine(); ? ? ? ? ? ? a=account.equals("admin"); ? ? ? ? ? ? b=code.equals("admin"); ? ? ? ? } while(!(a==true&&b==true)); ? ? ? ? Menu();? ? ? } ? ? //系統(tǒng)菜單頁(yè)面 ? ? private void Menu() throws IOException{ ? ? ? ? Scanner input=new Scanner(System.in); ? ? ? ? System.out.println("------ ?歡迎進(jìn)入宿舍管理系統(tǒng) ?------"); ? ? ? ? System.out.println("------ ?請(qǐng)選擇下列操作 ? ? ? ? ? ? ------"); ? ? ? ? System.out.println("--- ? ? 1.顯示所有學(xué)生信息 ? ? ? ? ?---"); ? ? ?//Show() ? ? ? ? System.out.println("--- ? ? 2.查詢學(xué)生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Find() ? ? ? ? System.out.println("--- ? ? 3.增加學(xué)生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Add() ? ? ? ? System.out.println("--- ? ? 4.修改學(xué)生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Renew() ? ? ? ? System.out.println("--- ? ? 5.刪除學(xué)生信息 ? ? ? ? ? ? ? ? ---"); ? ? ?//Delete() ? ? ? ? System.out.println("--- ? ? 0.退出系統(tǒng) ? ? ? ? ? ? ? ? ? ? ? ? ---"); ? ? ? ? System.out.println("請(qǐng)輸入1~5:"); ? ? ? ? int a=input.nextInt(); ? ? ? ? while(a<0||a>5) ? ? ? ? { ? ? ? ? ? ? System.out.println("輸入有誤,請(qǐng)重新輸入:"); ? ? ? ? ? ? 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; ? ? ? ? } ? ? } ? ? //顯示學(xué)生的全部信息 ? ? 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("學(xué)號(hào):"+stu[i].getId()+"\t姓名:"+stu[i].getName()+"\t性別:"+stu[i].getSex()+"\t宿舍號(hào):"+stu[i].getDormid()); ? ? ? ? } ? ? ? ? System.out.println("返回主菜單"); ? ? ? ? Menu(); ? ? }? ? ? //查詢學(xué)生信息 ? ? 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("學(xué)號(hào)")){ ? ? ? ? ? ? ? ? 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()+"個(gè)學(xué)生信息"); ? ? ? ? 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("請(qǐng)輸入學(xué)生的學(xué)號(hào):"); ? ? ? ? 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("查詢成功,以下為該學(xué)生的信息"); ? ? ? ? ? ? ? ? System.out.println("學(xué)號(hào):"+stu1[i][0]+"\t姓名:"+stu1[i][1]+"\t性別:"+stu1[i][2]+"\t宿舍號(hào):"+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("輸入有誤!請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? ? ? cho=input.next(); ? ? ? ? ? ? ? ? ? ? ch=cho.charAt(0); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? while(ch=='Y'||ch=='y'){ ? ? ? ? ? ? ? ? ? ? Find(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? while(ch=='N'||ch=='n'){ ? ? ? ? ? ? ? ? ? ? Menu(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? System.out.println("沒有找到該學(xué)生,是繼續(xù)輸入,否返回菜單,是Y否N"); ? ? ? ? String cho=input.next(); ? ? ? ? char ch=cho.charAt(0); ? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') ? ? ? ? { ? ? ? ? ? ? System.out.println("輸入有誤!請(qǐng)重新輸入:"); ? ? ? ? ? ? cho=input.next(); ? ? ? ? ? ? ch=cho.charAt(0); ? ? ? ? } ? ? ? ? while(ch=='Y'||ch=='y'){ ? ? ? ? ? ? Find(); ? ? ? ? } ? ? ? ? while(ch=='N'||ch=='n'){ ? ? ? ? ? ? Menu(); ? ? ? ? } ? ? } ? ? //增加一個(gè)學(xué)生 ? ? 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("輸入有誤!請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? 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("學(xué)號(hào) ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號(hào) \r\n"); ? ? ? ? System.out.println("請(qǐng)輸入學(xué)生的學(xué)號(hào):"); ? ? ? ? id=input.next(); ? ? ? ? stu[n].setId(id); ? ? ? ? fw.write(stu[n].getId()+" ? ? ? "); ? ? ? ? System.out.println("請(qǐng)輸入學(xué)生的姓名:"); ? ? ? ? name=input.next(); ? ? ? ? stu[n].setName(name); ? ? ? ? fw.write(stu[n].getName()+" ? ? "); ? ? ? ? System.out.println("請(qǐng)輸入學(xué)生的性別:"); ? ? ? ? sex=input.next(); ? ? ? ? stu[n].setSex(sex); ? ? ? ? fw.write(stu[n].getSex()+" ? ? ?"); ? ? ? ? System.out.println("請(qǐng)輸入學(xué)生的宿舍號(hào):"); ? ? ? ? dormid=input.next(); ? ? ? ? stu[n].setDormid(dormid); ? ? ? ? fw.write(stu[n].getDormid()+" ? ? ? "); ? ? ? ? n++; ? ? ? ? fw.close(); ? ? ? ? System.out.println("是否繼續(xù)添加學(xué)生?否返回主菜單,是Y否N"); ? ? ? ? cho=input.next(); ? ? ? ? ch=cho.charAt(0); ? ? ? ? while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') ? ? ? ? { ? ? ? ? ? ? System.out.println("輸入有誤!請(qǐng)重新輸入:"); ? ? ? ? ? ? cho=input.next(); ? ? ? ? ? ? ch=cho.charAt(0); ? ? ? ? } ? ? ? ? while(ch=='Y'||ch=='y'){ ? ? ? ? ? ? Add(); ? ? ? ? } ? ? ? ? while(ch=='N'||ch=='n'){ ? ? ? ? ? ? Menu(); ? ? ? ? } ? ? } ? ? //修改學(xué)生信息 ? ? 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("學(xué)號(hào)")){ ? ? ? ? ? ? ? ? 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("請(qǐng)輸入要修改學(xué)生的學(xué)號(hào):"); ? ? ? ? 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("輸入的學(xué)號(hào)有誤,未找到該學(xué)生,是否再次進(jìn)入修改,是Y,否N"); ? ? ? ? ? ? String cho1=input.next(); ? ? ? ? ? ? char ch1=cho1.charAt(0); ? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y') ? ? ? ? ? ? { ? ? ? ? ? ? ? ? System.out.println("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? 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("您要修改的學(xué)生的信息如下:"); ? ? ? ? ? ? System.out.println("學(xué)號(hào):"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性別:"+stu1[temp][2]+"\t宿舍號(hào):"+stu1[temp][3]); ? ? ? ? ? ? System.out.println("請(qǐng)以下選擇要修改的內(nèi)容:"); ? ? ? ? ? ? System.out.println("------ ? 1.姓名 ? ? ? ------"); ? ? ? ? ? ? System.out.println("------ ? 2.性別 ? ? ? ------"); ? ? ? ? ? ? System.out.println("------ ? 3.宿舍號(hào) ? ? ?------"); ? ? ? ? ? ? Scanner input1=new Scanner(System.in); ? ? ? ? ? ? int a=input1.nextInt(); ? ? ? ? ? ? if(a==1) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入新的姓名:"); ? ? ? ? ? ? ? ? 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"+" ? ? ? ? ? "+"學(xué)生信息表\r\n"); ? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? fw.write("\r\n學(xué)號(hào) ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號(hào) \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("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? ? ? 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("請(qǐng)輸入新的性別:"); ? ? ? ? ? ? ? ? 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"+" ? ? ? ? ? "+"學(xué)生信息表\r\n"); ? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? fw.write("\r\n學(xué)號(hào) ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號(hào) \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("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? ? ? 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("請(qǐng)輸入新的宿舍號(hào):"); ? ? ? ? ? ? ? ? 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"+" ? ? ? ? ? "+"學(xué)生信息表\r\n"); ? ? ? ? ? ? ? ? for(int i=0;i<stu1.length;i++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? fw.write("\r\n學(xué)號(hào) ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號(hào) \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("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? ? ? 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("輸入有誤,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? Renew(); ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? //刪除學(xué)生信息 ? ? 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("學(xué)號(hào)")){ ? ? ? ? ? ? ? ? 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("請(qǐng)輸入你想要?jiǎng)h除該學(xué)生的學(xué)號(hào):"); ? ? ? ? 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("輸入的學(xué)號(hào)有誤,未找到該學(xué)生,再次進(jìn)入刪除,請(qǐng)重新輸入:"); ? ? ? ? ? ? String cho1=input2.next(); ? ? ? ? ? ? char ch1=cho1.charAt(0); ? ? ? ? ? ? while (ch1!='N'&&ch1!='n'&&ch1!='Y'&&ch1!='y') ? ? ? ? ? ? { ? ? ? ? ? ? ? ? System.out.println("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? ? ? 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("您要?jiǎng)h除的學(xué)生的信息如下:"); ? ? ? ? ? ? System.out.println("學(xué)號(hào):"+stu1[temp][0]+"\t姓名:"+stu1[temp][1]+"\t性別:"+stu1[temp][2]+"\t宿舍號(hào):"+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"+" ? ? ? ? ? "+"學(xué)生信息表\r\n"); ? ? ? ? ? ? for(int i=0;i<stu1.length-1;i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? fw.write("\r\n學(xué)號(hào) ? ? ? ?姓名 ? ? ?性別 ? ? ?宿舍號(hào) \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("刪除該學(xué)生信息成功!"); ? ? ? ? ? ? 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("輸入無效,請(qǐng)重新輸入:"); ? ? ? ? ? ? cho2=input2.next(); ? ? ? ? ? ? ch2=cho2.charAt(0); ? ? ? ? } ? ? ? ? if (ch2=='y'||ch2=='Y'){ ? ? ? ? ? ? Delete(); ? ? ? ? } ? ? ? ? if (ch2=='N'||ch2=='n'){ ? ? ? ? ? ? System.out.println("返回主菜單"); ? ? ? ? ? ? Menu(); ? ? ? ? }? ? ? } ?}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot配置mybatis駝峰命名規(guī)則自動(dòng)轉(zhuǎn)換的實(shí)現(xiàn)
這篇文章主要介紹了SpringBoot配置mybatis駝峰命名規(guī)則自動(dòng)轉(zhuǎn)換的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Java郵件發(fā)送程序(可以同時(shí)發(fā)給多個(gè)地址、可以帶附件)
不錯(cuò)的功能比較齊全的郵件發(fā)送程序源碼2008-07-07SpringBoot+MyBatisPlus+Vue 前后端分離項(xiàng)目快速搭建過程(前端篇)
這篇文章主要介紹了SpringBoot+MyBatisPlus+Vue 前后端分離項(xiàng)目快速搭建過程(前端篇),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-05-05springboot學(xué)習(xí)筆記之 profile多環(huán)境配置切換的實(shí)現(xiàn)方式
這篇文章主要介紹了springboot profile多環(huán)境配置切換的實(shí)現(xiàn)方式,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-07-07JAVA復(fù)制數(shù)組和重置數(shù)組大小操作
這篇文章主要介紹了JAVA復(fù)制數(shù)組和重置數(shù)組大小操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09MyBatis二級(jí)緩存實(shí)現(xiàn)關(guān)聯(lián)刷新
本文主要介紹了MyBatis二級(jí)緩存實(shí)現(xiàn)關(guān)聯(lián)刷新,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01Java網(wǎng)絡(luò)編程之基于TCP協(xié)議
本文主要將Java基于TCP的網(wǎng)絡(luò)編程主要分解成5個(gè)功能:功能分解1:單向通信功能分解,2:雙向通信功能分解,3:對(duì)象流傳送功能分解,4:加入完整的處理異常方式功能分解,5:多線程接收用戶請(qǐng)求,需要的朋友可以參考下2021-05-05