Java_實例_作業(yè)(控制臺學(xué)生管理系統(tǒng))


import java.util.Arrays;
import java.util.Scanner;

public class StudentScore {
    static Scanner input = new Scanner(System.in);\
    //學(xué)生個數(shù)
    static String names[] = new String[2];
    //課程數(shù)量
    static int score[][] = new int[names.length][5];
    private static Scanner scan;
    /**
     * names[]長度
     */
    static int LEN = names.length;
    /**
     * score[]長度
     */
    static int SLEN = score.length;

    public static void main(String args[]) {
        welcome();
        options();

    }

    public static void welcome() {
        System.out.println("請輸入一個選項:");
        System.out.print("1`輸入學(xué)生成績    ");
        System.out.print("2`顯示全部學(xué)生成績        ");
        System.out.println("3`查詢學(xué)生成績");
        System.out.print("4`求學(xué)生總分     ");
        System.out.print("5`顯示最高分       ");
        System.out.println("6`顯示最低分");
        System.out.print("7`查看平均分     ");
        System.out.println("8`退出系統(tǒng)");
    }

    public static void options() {
        System.out.println("請輸入您所需查詢的選項:");

        int num = input.nextInt();
        switch (num) {
        case 1:
            entryResults();
            welcome();
            options();
            break;
        case 2:
            studentInfo();
            options();
            break;
        case 3:
            inquireInfo();
            welcome();
            options();
            break;
        case 4:
            totalScore();
            welcome();
            options();
            break;
        case 5:
            maxScore();
            welcome();
            options();
            break;
        case 6:
            minScore();
            welcome();
            options();
            break;
        case 7:
            avgScore();
            welcome();
            options();
            break;
        case 8:
            System.out.println("bye!");
            System.exit(0);
            break;
        default:
            System.out.println("輸入有誤,請重新輸入:");
            welcome();
            options();
        }
    }

    public static void entryResults() {
        for (int i = 0; i < LEN; i++) {
            System.out.println("請輸入第" + (i + 1) + "個學(xué)生姓名");
            names[i] = input.next();
        }
        for (int i = 0; i < SLEN; i++) {
            for (int j = 0; j < score[i].length; j++) {
                System.out.println("請錄入" + names[i] + "的" + getCoursName(j) + "成績");
                score[i][j] = input.nextInt();
            }
        }
        System.out.println("錄入完成!");
    }

    public static String getCoursName(int i) {
        switch (i) {
        case 0:
            return "數(shù)學(xué)";
        case 1:
            return "英語";
        case 2:
            return "計算機(jī)";
        case 3:
            return "體育";
        case 4:
            return "語文";
        default:
            return "無";

        }
    }

    public static void studentInfo() {
        System.out.println("顯示所有學(xué)生信息:");
        System.out.println("姓名\t數(shù)學(xué)\t英語\t計算機(jī)\t體育\t語文");
        for (int i = 0; i < LEN; i++) {
            System.out.println(names[i] + "\t");
            for (int j = 0; j < score[i].length; j++) {
                System.out.println(score[i][j] + "\t");
            }
        }
    }

    public static void inquireInfo() {
        System.out.println("請輸入要查詢的學(xué)生姓名:");
        scan = new Scanner(System.in);
        String name = scan.next();
        for (int i = 0; i < LEN; i++) {
            if (name.equals(names[i])) {
                for (int j = 0; j < 5; j++) {
                    System.out.println(names[i] + "的 " + getCoursName(j) + "成績是: " + score[i][j]);
                }
            }
        }
    }

    public static void totalScore() {
        int[] sum = new int[5];
        for (int i = 0; i < LEN; i++) {
            for (int j = 0; j < 5; j++) {
                sum[j] += score[i][j];
            }
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(getCoursName(i) + "總成績是: " + sum[i]);
        }
    }

    public static void maxScore() {
        for (int i = 0; i < SLEN; i++) {
            Arrays.sort(score[i]);
            System.out.println(names[i] + "最高分是 : " + score[i][score[i].length - 1]);
        }
    }

    public static void minScore() {
        for (int i = 0; i < SLEN; i++) {
            Arrays.sort(score[i]);
            System.out.println(names[i] + "最低分是 : " + score[i][0]);
        }
    }

    public static void avgScore() {
        int[] nums = new int[LEN];
        for (int i = 0; i < SLEN; i++) {
            for (int j = 0; j < score[i].length; j++) {
                nums[i] += score[i][j];
            }
        }
        for (int j = 0; j < LEN; j++) {
            System.out.println(names[j] + "平均分是 : " + (nums[j] / score[j].length));
        }

    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末虽画,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子惊奇,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,430評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異诽表,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)隅肥,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,406評論 3 398
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來袄简,“玉大人腥放,你說我怎么就攤上這事÷逃铮” “怎么了秃症?”我有些...
    開封第一講書人閱讀 167,834評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長吕粹。 經(jīng)常有香客問我种柑,道長,這世上最難降的妖魔是什么匹耕? 我笑而不...
    開封第一講書人閱讀 59,543評論 1 296
  • 正文 為了忘掉前任聚请,我火速辦了婚禮,結(jié)果婚禮上稳其,老公的妹妹穿的比我還像新娘驶赏。我一直安慰自己,他們只是感情好既鞠,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,547評論 6 397
  • 文/花漫 我一把揭開白布煤傍。 她就那樣靜靜地躺著,像睡著了一般嘱蛋。 火紅的嫁衣襯著肌膚如雪蚯姆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,196評論 1 308
  • 那天洒敏,我揣著相機(jī)與錄音龄恋,去河邊找鬼。 笑死凶伙,一個胖子當(dāng)著我的面吹牛篙挽,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播镊靴,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼铣卡,長吁一口氣:“原來是場噩夢啊……” “哼链韭!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起煮落,我...
    開封第一講書人閱讀 39,671評論 0 276
  • 序言:老撾萬榮一對情侶失蹤敞峭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蝉仇,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體旋讹,經(jīng)...
    沈念sama閱讀 46,221評論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,303評論 3 340
  • 正文 我和宋清朗相戀三年轿衔,在試婚紗的時候發(fā)現(xiàn)自己被綠了沉迹。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,444評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡害驹,死狀恐怖鞭呕,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情宛官,我是刑警寧澤葫松,帶...
    沈念sama閱讀 36,134評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站底洗,受9級特大地震影響腋么,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜亥揖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,810評論 3 333
  • 文/蒙蒙 一珊擂、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧费变,春花似錦未玻、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,285評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至昼激,卻和暖如春庇绽,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背橙困。 一陣腳步聲響...
    開封第一講書人閱讀 33,399評論 1 272
  • 我被黑心中介騙來泰國打工瞧掺, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人凡傅。 一個月前我還...
    沈念sama閱讀 48,837評論 3 376
  • 正文 我出身青樓辟狈,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子哼转,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,455評論 2 359

推薦閱讀更多精彩內(nèi)容