救命啊~~學長..:P

看板CKEFGISC-1st作者 (突破生活的不順利..)時間25年前 (2000/12/01 16:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我的程式又有問題摟..:P ㄚ我就一直想用java 的class來玩. 但是他就是不像c++一樣.. 把class宣告成陣列純取成績.. 怎麼搞都出問題><~~~ 一直跑出java.lang.NullpointerException import java.io.*; import java.math.*; /* * 學生成幾處理系統1.2Beta版 * 本版本嘗試使用class和陣列來處理, * 另外也加入搜尋的功能,儲存的功能. * */ class StudentScore { int num; int math; int chinese; int english; String name; public StudentScore(int m,int c,int e,String n ) { name=n; math=m; english=e; chinese=c; } public String GetName() { return name; } int total() { return math+chinese+english; }//傳回總分 double avg() { return (math+chinese+english)/3; }//傳回平均 public void Modify(int math,int english,int chinese) { this.math=math; this.english=english; this.chinese=chinese; } }//StudentScore /** * @com.register ( clsid=555D0FC4-C78F-11D4-83D1-0080C8D89738, typelib=555D0FC3-C78F-11D4-83D1-0080C8D89738 ) */ public class score { public static void main(String args[])throws IOException{ BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int w=0,num=0; String temp=null,temp1=null,temp2=null,temp3=null; StudentScore S[] =new StudentScore[100]; System.out.println("\t歡迎進入學生成績處理系統1.2Beta版"); System.out.println("\t1)增加 ,2)修改 ,3)刪除 ,4)搜尋 ,5)列出 ,6)離開"); System.out.println("-----------------------------------------------------------------"); try{ System.out.flush(); temp=br.readLine(); w=Integer.parseInt(temp); } catch(ArithmeticException e) { System.out.println("It's a undefined number"); } do{ switch(w){ case 1: try{ ++num; System.out.print("請輸入姓名:"); System.out.flush(); temp=br.readLine(); System.out.print("請輸入國文成績:"); System.out.flush(); temp1=br.readLine(); c=Integer.parseInt(temp1); System.out.print("請輸入英文成績:"); System.out.flush(); temp2=br.readLine(); e=Integer.parseInt(temp2); System.out.print("請輸入數學成績:"); System.out.flush(); temp3=br.readLine(); m=Integer.parseInt(temp3); StudentScore S[num]=new StudentScore(m,c,e,temp); } catch(IOException e) { System.out.println("It's a undefined number"); } break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; default: }//switch }while(w==6); }//main }//score -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: PCA70.PC.tmtc.edu.tw
文章代碼(AID): #w9riZ00 (CKEFGISC-1st)