《軟體工程》第二次作業:編寫小學生四則運算測試軟體

來源:互聯網
上載者:User

標籤:

一、題目:

  • 請編寫一個能自動產生小學四則運算題目的 “軟體”。
  • 讓程式能接受使用者輸入答案,並判定對錯。
  • 最後給出總共以及 對/錯      的數量。

二、基本要求:

  • 所編寫出來的“軟體”選擇介面設計,選擇加、減、乘、除運算。
  • 系統隨機產生一百以內的兩個數進行運算。
  • 使用該軟體時,使用者從鍵盤輸入結果,回答正確和回答錯誤都有提示,結束後系統會自動給出相應的總題數和 對/錯 的數量。

三、需求分析:

  • 程式能實現0~100以內的加法、減法、乘法以及除法的運算。
  • 使用者能在java控制視窗輸入自己的答案,該程式能夠判斷使用者所輸入答案的對錯。
  • 測試結束後,程式能給出所做題目的數量以及所做題目對/錯的數量。

四、設計:

  • 定義五個變數分別是:e, r, a, b, c,其中e表示答錯的題數,表示r表示答對的題數,a, b分別表示0~100之間隨機產生的兩個整數
  • 使用Scanner類建立了多個對象並對不同的運算類型調用相應的方法。
  • 加、減、乘、除用一個switch控制語句來實現,整個程式的實現在主函數中體現。

五、代碼實現:

 1 import java.util.Random; 2 import java.util.Scanner; 3  4 public class qq { 5     public static void main(String[] args) { 6         int e = 0, r = 0; 7         System.out.println("歡迎來到四則運算測試軟體!"); 8         System.out.println("做題前請認真讀題,祝您考試愉快!"); 9         Random r1 = new Random();10         for (int i = 0; i < 7; i++) {11             int m, n;12             int a, b, c;13             m = r1.nextInt() % 10;14             n = m % 4;15 16             switch (n) {17             case 0:18                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;19                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;20                 System.out.println(a + "+" + "" + b + "=?");21                 Scanner x1 = new Scanner(System.in);22                 c = x1.nextInt();23                 if (c != a + b) {24                     e++;25                     System.out.println("回答錯誤!!");26                 } else {27                     r++;28                     System.out.println("回答正確!!");29                 }30 31                 break;32 33             case 1:34                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;35                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;36                 System.out.println(a + "-" + " " + b + " =?");37                 Scanner x2 = new Scanner(System.in);38                 c = x2.nextInt();39                 if (c != a - b) {40                     e++;41                     System.out.println("回答錯誤!!");42                 } else {43                     r++;44                     System.out.println("回答正確!!");45                 }46 47                 break;48 49             case 2:50                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;51                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;52                 System.out.println(a + "*" + " " + b + " " + "=?");53                 Scanner y1 = new Scanner(System.in);54                 c = y1.nextInt();55                 if (c != a * b) {56                     e++;57                     System.out.println("回答錯誤!!");58                 } else {59                     r++;60                     System.out.println("回答正確!!");61                 }62 63                 break;64 65             case 3:66                 double d;67                 a = new Random().nextInt((int) Math.pow(10, 2)) + 1;68                 b = new Random().nextInt((int) Math.pow(10, 2)) + 1;69                 if (b == 0)70                     b++;71                 System.out.println(a + "/" + " " + b + " " + "=?");72                 Scanner y2 = new Scanner(System.in);73                 d = y2.nextDouble();74                 if (d != (a / b) / 1.00) {75                     e++;76                     System.out.println("回答錯誤!!");77                 } else {78                     r++;79                     System.out.println("回答正確!!");80 81                 }82 83                 break;84 85             }86         }87         System.out.println("考試結束!!");88         System.out.println("您一共做了:" + (r + e) + "道題目,其中正確的有" + r + "道,錯誤的有" + e + "道!");90     }91 }

六、程式:

七、PSP耗時:

   

     總結:老師剛開始布置作業的時候還沒有明白是怎麼回事,後來在第二次上機課的時候,老師再次的說明我才理解題目的意思。之前學過的相關電腦課程大部分都忘記了,例如c語言程式中的switch控制語句的用法以及java中類的用法也不怎麼記得了,在寫程式的過程中還好及時的查閱課本和資料、尋求同學和老師協助才算完成。其中的不足之處還希望老師指出,以後繼續努力!

 

 

    

     

 

 

 

 

 

《軟體工程》第二次作業:編寫小學生四則運算測試軟體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.