import java.io.*;
import java.util.*;
public class ScoreSystem {
static Data[] d = new Data[5];
static BufferedReader input;
public static void main(String[] args) {
try {
menu();
} catch (IOException e) {
System.out.println("程式出現輸出入錯誤,請參考以下錯誤代碼");
e.printStackTrace();
}
}//main() end
static void menu() throws IOException {
System.out.println("---------------學員成績管理系統---------------");
System.out.println("1.顯示所有資料 2.增/修學員資料 3.離開系統");
System.out.print("請選擇要執行的項目:");
input = new BufferedReader(new InputStreamReader(System.in));
try {
int sel = Integer.parseInt(input.readLine());
while(true){
switch (sel){
case 1:
dis_data();
break;
case 2:
mod_data();
break;
case 3:
System.out.println();
System.out.print("謝謝您的使用");
System.exit(0);
break;
default :
System.out.println();
System.out.println("輸入錯誤!請輸入選單中選項");
System.out.println();
menu();
break;
}
}//while end
} catch(NumberFormatException e) {
System.out.println();
System.out.println("輸入錯誤!請輸入選單中選項");
System.out.println();
menu();
}//try catch end
}//menu() end
static void dis_data() throws IOException {
System.out.println();
System.out.println("===============列印所有學生成績===============");
//System.out.printf("%2s%5s%6s%6s%6s%6s%6s","學號","姓名","國文","數學","英文","總分","平均");
System.out.print("學號\t姓名\t國文\t數學\t英文\t總分\t平均");
System.out.println();
try {
for(int i=0; i<d.length; i++){
System.out.printf("%3s",d[i].num);
System.out.printf("%4s",d[i].name);
System.out.printf("%5s",d[i].mandarin);
System.out.printf("%5s",d[i].meth);
System.out.printf("%5s",d[i].english);
System.out.printf("%5s",d[i].sum);
System.out.printf("%5s",d[i].avg + "\n");
}
System.out.println();
} catch(NullPointerException e) {
System.out.println();
System.out.println("學員資料不夠完整,請輸入完整學員資料");
System.out.println();
menu();
}//try catch end
}//dis_data() end
static void mod_data() throws IOException {
input = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
try {
System.out.print("您要增/修的第幾筆的學員資料? ");
int x = sc.nextInt();
d[x-1] = new Data();
System.out.print("請輸入學員學號:");
String num = input.readLine();
d[x-1].num = num;
System.out.print("請輸入學員姓名:");
String name = input.readLine();
d[x-1].name = name;
System.out.print("請輸入國文分數:");
double mandarin = Double.parseDouble(input.readLine());
d[x-1].mandarin = mandarin;
System.out.print("請輸入數學分數:");
double meth = Double.parseDouble(input.readLine());
d[x-1].meth = meth;
System.out.print("請輸入英文分數:");
double english = Double.parseDouble(input.readLine());
d[x-1].english = english;
d[x-1].sum = d[x-1].mandarin + d[x-1].meth + d[x-1].english;
d[x-1].avg = (d[x-1].mandarin + d[x-1].meth + d[x-1].english) / 3;
System.out.println("增/修完成");
} catch(NumberFormatException e) {
System.out.println();
System.out.println("輸入錯誤,請輸入阿拉伯數字");
System.out.println();
mod_data();
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println();
System.out.println("輸入錯誤,此系統只能有5個學員資料,ㄎㄎ");
System.out.println();
mod_data();
}
try {
while(true) {
System.out.print("是否要繼續增修? 1.是 2.否(回主選單): ");
int sel = sc.nextInt();
switch(sel) {
case 1:
mod_data();
break;
case 2:
menu();
break;
default:
System.out.println();
System.out.println("輸入錯誤!回主選單");
System.out.println();
menu();
break;
}
}
} catch(InputMismatchException e) {
System.out.println();
System.out.println("輸入錯誤!回主選單");
System.out.println();
menu();
}
}//mod_data() end
}//ScoreSystem class end
class Data {
String num, name;
double mandarin, meth, english, sum, avg;
void Data(String num, String name, double mandarin, double meth, double english, double sum, double avg){
}
}
- Dec 23 Wed 2009 21:46
學員成績管理系統 1.0
全站熱搜
留言列表