java編程實現學產生績管理系統,採用順序儲存結構

來源:互聯網
上載者:User

學產生績表如圖所示


問題分析:採用順序儲存結構,所以可以繼承順序表Sqlist(順序表Sqlist的建立在之前寫過了),簡化類的描述。

總體思路是先建立順序表,然後進行增刪改查的功能。

一個結點中包含5個資料元素,所以建立StudentNode結點如下:

import java.util.Scanner;public class StudentNode {private int number;  //學號private String name;  //姓名private String sex;    //性別private double english;   //大學英語成績private double math;     //高等數學成績public StudentNode(){      //無參數時的建構函式this(0,null,null,0,0);}public StudentNode(int number,String name,String sex,double english,double math){this.number=number;this.name=name;this.sex=sex;this.english=english;this.math=math;}public StudentNode(Scanner sc){this(sc.nextInt(),sc.next(),sc.next(),sc.nextDouble(),sc.nextDouble());}}

建立順序表並實現增刪改查功能

import java.util.*;public class StudentManageSystem extends Sqlist{    //按順序構造順序表,其中參數maxsize指的是順序表的最大儲存空間容量      public StudentManageSystem(int maxsize,int n)throws Exception{          super(maxsize);   //調用父類建構函式          Scanner sc=new Scanner(System.in);          for(int i=0;i<n;i++){     //建立含有n個資料元素的順序表              StudentNode node=new StudentNode(sc);              insert(node);      //將新的資料元素插入到順序表的表尾          }      }      //重載父類insert()方法在順序表表尾插入一個學生資訊      public void insert(StudentNode node)throws Exception{          super.insert(length(), node);      }      //覆蓋父類get()方法,從順序表中取出指定學號的學生資訊,返回StudentNode對象      public StudentNode get(int number)throws Exception{          for(int i=0;i<length();i++){   //遍曆順序表              StudentNode node=(StudentNode) super.get(i);  //調用父類Sqlist的get方法              if(node.number==number)                  return node;               //返回指定學生資訊          }          throw new Exception("學號"+number+"不存在");      }      //覆蓋父類的remove方法      public void remove(int number)throws Exception{              for(int i=0;i<length();i++){              StudentNode node=(StudentNode) super.get(i);              if(node.number==number)                  super.remove(i);              return;           //提前退出函數          }          throw new Exception("學號"+number+"不存在");      }      //重載父類display方法,輸出順序表中的所有資料元素      public void display(){          for(int i=0;i<length();i++){              try{                  StudentNode node =(StudentNode) super.get(i);                  displayNode(node);              }              catch(Exception e){}          }      }      //輸出一個資料元素的資訊      public void displayNode(StudentNode node){          System.out.println("學號:"+node.number+"姓名:"+node.name+"性別:"+node.sex+"英語成績:"+      node.english+"數學成績:"+node.math);      }      public static void main(String[] args)throws Exception{          int maxsize=100;          Scanner sc=new Scanner(System.in);          System.out.println("輸入學生總數");          int n=sc.nextInt();          System.out.println("請按學號,姓名,性別,英語成績,數學成績順序輸入學生資訊");          StudentManageSystem L=new StudentManageSystem(maxsize,n);          System.out.println("輸出學生資訊");          L.display();          System.out.println("輸入要查詢學生的學號");          L.displayNode(L.get(sc.nextInt()));          System.out.println("輸入要刪除學生的學號");          L.remove(sc.nextInt());          System.out.println("刪除成功");          L.display();          System.out.println("輸入需要增加的學生資訊");          L.insert(new StudentNode(sc));          L.display();      }  }
輸出結果


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.