目錄

興大物件導向程式設計 Assignment Ch07 完整版題目

什麼叫作「完整版」題目?

在此篇文章中出現的內容為中興大學物件導向程式設計課派發的 Assignment Ch07 作業。

原本照理講打開 iLearning 3.0 就該看到「完整」的題目了,但此次作業的題目中常出現 Fig6.8 這類的字樣,卻沒見到圖片本身,需要自行去原文參考書或者查閱上課的 PDF 檔。

本篇文章會把作業的題幹和圖檔一併附上,方便查閱。

7.18 (Game of Craps)

Write an application that runs 1,000,000 games of craps (Fig. 6.8) and answers the following questions:

  • a) How many games are won on the first roll, second roll, …,twentieth roll and after the twentieth roll?

  • b) How many games are lost on the first roll, second roll, …,twentieth roll and after the twentieth roll?

  • c) What are the chances of winning at craps? [Note: You should discover that craps is one of the fairest casino games. What do you suppose this means?]

  • d) What is the average length of a game of craps?

  • e) Do the chances of winning improve with the length of the game?

Fig.6.8(點擊展開)

7.30 (Card Shuffling and Dealing)

Modify Fig. 7.11 to deal a five-card poker hand. Then modify class DeckOfCards of Fig. 7.10 to include methods that determine whether a hand contains:

  • a) a pair
  • b) two pairs
  • c) three of a kind (e.g., three jacks)
  • d) four of a kind (e.g., four aces)
  • e) a flush (i.e., all five cards of the same suit)
  • f) a straight (i.e., five cards of consecutive face values)
  • g) a full house (i.e., two cards of one face value and three cards of another face value)

[Hint: Add methods getFace and getSuit to class Card of Fig. 7.9.]

Fig.7.11(點擊展開)
Fig.7.10(點擊展開)
Fig.7.9(點擊展開)

7.31 (Card Shuffling and Dealing)

Use the methods developed in Exercise 7.30 to write an application that deals two five-card poker hands, evaluates each hand and determines which is better.