TAILIEUCHUNG - Java™ How to Program ( Deitel - Deitel) - Phần 11

Tham khảo tài liệu 'java™ how to program ( deitel - deitel) - phần 11', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | PREV NEXT Page 250 continued . Case Study A Game of Chance Introducing Enumerations A popular game of chance is a dice game known as craps which is played in casinos and back alleys throughout the world. The rules of the game are straightforward You roll two dice. Each die has six faces which contain one two three four five and six spots respectively. After the dice have come to rest the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw you win. If the sum is 2 3 or 12 on the first throw called craps you lose . the house wins . If the sum is 4 5 6 8 9 or 10 on the first throw that sum becomes your point. To win you must continue rolling the dice until you make your point . roll that same point value . You lose by rolling a 7 before making the point. The application in Fig. and Fig. simulates the game of craps using methods to define the logic of the game. In the main method of class CrapsTest Fig. line 8 creates an object of class craps Fig. and line 9 calls its play method to start the game. The play method Fig. lines 2165 calls the roiiDice method Fig. lines 6881 as necessary to roll the two dice and compute their sum. Four sample outputs in Fig. show winning on the first roll losing on the first roll winning on a subsequent roll and losing on a subsequent roll respectively. Figure . Craps class simulates the dice game craps. This item is displayed on pages 251 - 252 in the print version 1 Fig. 2 Craps class simulates the dice game craps. 3 import 4 5 public class Craps 6 7 create random number generator for use in method rollDice 8 private Random randomNumbers new Random 9 10 enumeration with constants that represent the game status 11 private enum Status CONTINUE WON LOST 12 13 constants that represent common rolls of the dice 14 private final static int SNAKE_EYES 2 15 private final static int TREY 3 16 private final static int SEVEN 7 17

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.