编写一个控制台应用程序,实现一个学生管理系统。每个学生有二个属性:学号与姓名。
要求此程序实现以下功能:
启动程序时从文件读取学生数据库。结束程序前保存学生的信息到文件。
程序运行时显示一个主菜单:
[0]Main Menu [1]search [2]input  [3]delete   [4]list all [5]exit
用户通过输入0-5之间的数字进行相应的操作:
选项0:回到主菜单
选项1:查找一个学生。提示输入学生的学号,查到则输出学生的姓名,未查到给出提示信息。执行完毕回到主菜单。
选项2:新增一个学生。先提示输入学生的学号,输入之后提示输入姓名,输入结束返回主菜单。
选项3:删除一个学生。提示输入学生的学号,通过学号来删除学生,执行完毕回到主菜单。
选项4:列出所有的学生信息,包括学号和姓名。
选项5:结束程序。

解决方案 »

  1.   

    java io 操作
    以前我提的一个帖子...实现了部分功能....
    连接:http://topic.csdn.net/u/20080514/15/4a1b657e-df89-4602-a007-46a0d2fcadf5.html
    我的小项目:http://download.csdn.net/source/457634
      

  2.   

    就是编写简单了就可以啦!在djk下编就可以了。大家试试看,我也在写。
      

  3.   

    http://topic.csdn.net/u/20080521/22/879336d3-f15b-4975-b007-0c29363a176d.html?seed=948776924?dd
      

  4.   

    import java.util.*;
    import java.io.*;
    public class xsglxt {
        public static void main(String args[])throws Exception{               
           Student s=new Student();
           s.main();
        }
    }
    class Student{
       public void main()
        {
         System.out.println("------------------"); 
         System.out.println("   学生管理系统   "); 
         System.out.println("------------------"); 
         System.out.println("[0]Main Menu"); 
         System.out.println("[1]search"); 
         System.out.println("[2]input"); 
         System.out.println("[3]delete "); 
         System.out.println("[4]list all"); 
         System.out.println("[5]exit"); 
         System.out.println("------------------"); 
         System.out.println("请输入您的选择:"); 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));          try { 
              String str=br.readLine(); 
              int num=Integer.parseInt(str); 
              switch(num) 
                { 
                  case 0: 
                  System.out.println("返回主菜单"); 
                  this.main(); 
                  break; 
                  case 1: 
                  this.search();
                  break; 
                  case 2: 
                  this.input();
                  break; 
                  case 3: 
                  this.delete();
                  break; 
                  case 4: 
                  this.list();
                  break; 
                  case 5:    
                  this.exit();
                  break; 
                  default: 
                  this.defaut();
                  break; 
                 }
             }catch (Exception e) {
             System.out.println("您输入的不是数字,请重新输入!");this.main(); }
         }
      public void search()
       {
        try{  System.out.print("请输入学号:");
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
               String s=br.readLine();
               this.find(s);
            }catch(IOException e){
             System.out.println(e);   }
        }
      public void input()
       {
          try{ System.out.print("请输入学号:");
      BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
               String s1=br1.readLine();
               System.out.print("请输入姓名:");
      BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
               String s2=br2.readLine();
               s2=s2.toString();
               this.shulu(s1, s2);
               }catch(IOException e){System.out.println(e);   }
         }
      public void delete()
       {
        try{  System.out.print("请输入学号:");
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
              String s=br.readLine();
              this.del(s);
            }catch(IOException e){System.out.println(e);   }
        }
      public void list()
       {
         try{
      InputStream in = new BufferedInputStream(new FileInputStream(filePath));
            Student.load(in);
            Enumeration en = Student.propertyNames();
            if(Student.isEmpty()) 
            {System.out.println("列表为空");this.main();}
            else 
            { System.out.println("列表中的记录为:");
              while (en.hasMoreElements()) 
              { String key = (String) en.nextElement();
                String Property = Student.getProperty(key);
                System.out.println(key + "  "+Property);
               }this.main();}
            }catch(Exception e){}
        }
     public void exit()
      { 
         System.out.println("您己退出学生管理系统!"); 
         System.exit(0); 
       }
     public void defaut()
      {
        System.out.println("您的选择不在选项中!");
        this.main(); 
      } 
      public static Properties Student=new Properties(); 
      InputStream in = null;
      String filePath="stu.txt";
      public Student(){}
      public void find(String xh)
      {
       try{
            InputStream fis = new FileInputStream(filePath);
            Student.load(fis);
            if(Student.containsKey(xh)){
    System.out.println("查找结果为:");   
         System.out.print(xh+"  ");
            System.out.println(Student.getProperty(xh)); this.main();
            }
            else {System.out.println("该学号不存在."); this.main();}
           }
            catch(Exception e){}
        }
       public void shulu(String xh,String xm)
       {
         try{
            InputStream fis = new FileInputStream(filePath);
            Student.load(fis);
            OutputStream fos = new FileOutputStream(filePath);
            if(Student.containsKey(xh))
    { System.out.println("该学生已存在");this.main();}
            else Student.setProperty(xh, xm); 
            Student.store(fos, "Update '" + xh + "' value  " +xm);
            this.main();
             }catch(Exception e){  e.printStackTrace();  }
       }
      public void del(String xh)
      {
        try{
            InputStream fis = new FileInputStream(filePath);
            OutputStream fos = new FileOutputStream(filePath);
            Student.load(fis);
            if(Student.containsKey(xh)) 
              {
                Student.remove(xh);
                Student.store(fos, filePath);
                System.out.println("该记录已删除");
    this.main();
              }
            else { System.out.println("该学号不存在."); this.main();}
            } catch(Exception e){}
        }
    }