Begin this assignment by first creating a new Java Project called Assignment 5.There is only one part to this assignment.

Similar documents
CMPT 125/128 with Dr. Fraser. Assignment 3

HW4: The Game of Pig Due date: Tuesday, Mar 15 th at 9pm. Late turn-in deadline is Thursday, Mar 17th at 9pm.

HW4: The Game of Pig Due date: Thursday, Oct. 29 th at 9pm. Late turn-in deadline is Tuesday, Nov. 3 rd at 9pm.

Project 2 - Blackjack Due 7/1/12 by Midnight

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Computer Science 25: Introduction to C Programming

ECE2049: Foundations of Embedded Systems Lab Exercise #1 C Term 2018 Implementing a Black Jack game

CS 371M. Homework 2: Risk. All submissions should be done via git. Refer to the git setup, and submission documents for the correct procedure.

CIDM 2315 Final Project: Hunt the Wumpus

Ok, we need the computer to generate random numbers. Just add this code inside your main method so you have this:

Welcome to JigsawBox!! How to Get Started Quickly...

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Craps Wizard App Quick Start Guide

How to Use EZ Appoint

Discrete Random Variables Day 1

Assignment 1. Due: 2:00pm, Monday 14th November 2016 This assignment counts for 25% of your final grade.

PMM. Chronological Notes

LISTING THE WAYS. getting a total of 7 spots? possible ways for 2 dice to fall: then you win. But if you roll. 1 q 1 w 1 e 1 r 1 t 1 y

Programming Exam. 10% of course grade

Building a Personal Portfolio in Blackboard UK SLIS

STATION 1: ROULETTE. Name of Guesser Tally of Wins Tally of Losses # of Wins #1 #2

Student activity sheet Gambling in Australia quick quiz

SEEM3460/ESTR3504 (2017) Project

Physical Inventory System User Manual. Version 19

Materials: Game board, dice (preferable one 10 sided die), 2 sets of colored game board markers.

Project 1: A Game of Greed

TABLE OF CONTENTS. Logging into the Website Homepage and Tab Navigation Setting up Users on the Website Help and Support...

Instructions [CT+PT Treatment]

Module 5: Probability and Randomness Practice exercises

CS1301 Individual Homework 5 Olympics Due Monday March 7 th, 2016 before 11:55pm Out of 100 Points

JOU4308: Magazine & Feature Writing

Electronic Plans Management Training. Submitting a Revision to Approved Plans (RTAP) Application & Uploading Drawings

How to Build a LimeSurvey: The Basics for Beginners

Smyth County Public Schools 2017 Computer Science Competition Coding Problems

Author Instructions FPIN Editorial Manager

BLACKJACK TO THE NTH DEGREE - FORMULA CYCLING METHOD ENHANCEMENT

My Earnings from PeoplePerHour:

Lab 2. CS 3793/5233 Fall 2016 assigned September 13, 2016 Tom Bylander, Instructor due midnight, September 30, 2016

Programming Problems 14 th Annual Computer Science Programming Contest

Design Document for: Math Town Where Math Meets Fun!

Reviewing Your Tax Return In Your Portal

Approving an Expense Voucher eform Travel Expense Voucher eform Instructions for the Approver. Introduction. Finding the eform.

When accessing our class network, you can get there in one of two ways. The easiest is to put this web address directly into your browser.

Math Steven Noble. November 24th. Steven Noble Math 3790

Electronic Plans Management Training. Upload Drawings

For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.

To use one-dimensional arrays and implement a collection class.

AP Studio Art. Demo: Digital Submission.

Harrison Allen s Online Tutor Management System. Online Tutor System Help Sheet

WebFire Wednesday Webinars: Get Paid to Promote Your Business

CONCEPTS EXPLAINED CONCEPTS (IN ORDER)

NET PAY USING EXCEL***

CyberDominance.com Author Guide

You Can Make a Difference! Due November 11/12 (Implementation plans due in class on 11/9)

CSE231 Spring Updated 04/09/2019 Project 10: Basra - A Fishing Card Game

Part II: Number Guessing Game Part 2. Lab Guessing Game version 2.0

CSE 231 Fall 2012 Programming Project 8

RULES AND REGULATIONS Title 58 RECREATION

Probability (Devore Chapter Two)

In this project you will learn how to write a Python program telling people all about you. Type the following into the window that appears:

Microsoft Excel Lab Three (Completed 03/02/18) Transcript by Rev.com. Page 1 of 5

Assignment 5 due Monday, May 7

PLA Planner Student Handbook

Macro. Installation and User Guide. copyright 2012 C.T. Stump

Scripted Introduction

SIMS Autumn Census COMPLETION Document for Primary Schools

Math 1310: Intermediate Algebra Computer Enhanced and Self-Paced

2. Now you need to create permissions for all of your reviewers. You need to be in the Administration Tab to do so. Your screen should look like this:

Guide to Tier 4 Print and Send Online Applications

Final Project: NOTE: The final project will be due on the last day of class, Friday, Dec 9 at midnight.

Choose one person to be the immune system (IM player). All the other players are pathogens (P players).

nvision Actuals Drilldown (Non-Project Speedtypes) Training Guide Spectrum+ System 8.9 November 2010 Version 2.1

CHAPTER 659a. FORTUNE ASIA POKER

class TicTacToe: def init (self): # board is a list of 10 strings representing the board(ignore index 0) self.board = [" "]*10 self.

A PUZZLE OF TOSSING COINS

How to create a survey with SurveyMonkey

Lab Exercise #10. Assignment Overview

Payroll year end. Made easy.

Your starter pack learndirect.co.uk

SPREADSHEET SET-UP. To switch simply click on the gear icon in the upper-left side of the page. Then click Experience the new Drive

Products Brochure. isoftgaming Scalable Live Games

Human Capital Management: Step-by-Step Guide

One Hour YouTube Pro... 3 Section 1 One Hour YouTube System... 4 Find Your Niche... 4 ClickBank... 5 Tips for Choosing a Product...

Presentation by Toy Designers: Max Ashley

Beginning Game Programming, COMI 2040 Lab 6

CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

How to Blog to the Vanguard Website

System Audit Checklist

Organizing and Customizing Content

Chapter 7 Homework Problems. 1. If a carefully made die is rolled once, it is reasonable to assign probability 1/6 to each of the six faces.

Create Or Conquer Game Development Guide

LEVEL A: SCOPE AND SEQUENCE

Bridgemate App. Information for bridge clubs and tournament directors. Version 2. Bridge Systems BV

CQE Workbook. A step-by-step guide to applying for a Certificate of Qualification for Employment

CS Project 1 Fall 2017

An easy user guide AN EASY USER GUIDE

Using the Tax Research Center

Name: Checked: Answer: jack queen king ace

Ch. 670a SIX-CARD FORTUNE PAI GOW POKER a.1. CHAPTER 670a. SIX-CARD FORTUNE PAI GOW POKER

Pass-Words Help Doc. Note: PowerPoint macros must be enabled before playing for more see help information below

Transcription:

CSCI 2311, Spring 2013 Programming Assignment 5 The program is due Sunday, March 3 by midnight. Overview of Assignment Begin this assignment by first creating a new Java Project called Assignment 5.There is only one part to this assignment. From now on, we will start including comments in our code. For this assignment, the only comment you must have is a header comment at the top of your class that has the following format: /* * Author: <Your Name Here> * Assignment: <Assignment Number> * Due Date: <Date Assignment is Due> * * Purpose: * * The purpose of this assignment is to... */ You should also include comments in your code where ever you feel appropriate to help clarify variables and give meaning to sections of code. Be certain to follow the naming conventions we discussed in class when naming your identifiers. Also, don t assume your assignment works correctly just because it matches my example output. Try your program out with several different values to be sure it works. IMPORTANT: Starting with this assignment and all future assignments, point deductions will occur when failing to properly name variables, poor code formatting, forgetting to comment, failing to follow conventions, etc. This is the last assignment I will remind students of this, you are expected to remember it for future assignments.

How to Play Craps To play craps (a simple version of it anyway), you need two dice. The total value of the dice is used to determine whether a roll is a win or a loss. The game starts when one person, the shooter, places a bet and then begins with an initial roll of the dice. If the two dice total 7 or 11, it is a winning roll. If the two dice total, 2, 3 or 12, it is a losing roll. If the two dice total 4, 5, 6, 8, 9, or 10, the shooter continues to roll until: 1. If the two dice equal the total of the original roll, it is a winning roll 2. If the two dice total 7, it is a losing roll 3. If the two dice total anything else, rolls continue until part 1 or 2 occur Bets are paid out at a ratio of 1:1; for example, a winning bet of $5.00 results in a gain of $5.00 and a losing bet of $5.00 results in a loss of $5.00. Play continues until the shooter decides to stop betting or runs out of money. As an example, consider the following scenario (assume the user starts with $50.00): The shooter bets $5.00 and on the first roll, gets a 2 and a 5 for a total of 7. This is a winning roll and now the shooter has $55.00. The shooter bets $10.00 and on the first roll, gets a 6 and a 6 for a total of 12. This is a losing roll and now the shooter has $45.00. The shooter bets $20.00 and on the first roll, gets a 2 and a 3 for a total of 5. The shooter rolls again and gets a 1 and a 1 for a total of 2. The shooter rolls again and gets a 6 and a 6 for a total of 12. The shooter rolls again and gets a 5 and a 6 for a total of 11. The shooter rolls again and gets a 1 and a 4 for a total of 5. This is a winning roll and now the shooter has $65.00. The shooter bets $65.00 and on the first roll, gets a 5 and a 4 for a total of 9. The shooter rolls again and gets a 1 and a 2 for a total of 3. The shooter rolls again and gets a 4 and a 4 for a total of 8. The shooter rolls again and gets a 2 and a 5 for a total of 7. This is a losing roll and now the shooter has $0.00. The game is over since the shooter is out of money.

Random Number Generator You will need to use a random number generator to complete this assignment. To use random numbers, we have to import that Random class, similar to how we import the Scanner class. We can handle this using the import java.util.random. Once we import the Random class, we have to create an instance of the class. (e.g, Random random = new Random();). Once created, we can use the variable name (in this case, random) to access the methods of the Random class. The only method you will need from this class for the assignment is the nextint(integer param) method. This method will return a value from 0 up to, but excluding, the value of the parameter. For a dice, we need a value from 1 to 6, so to do this we can use the following code: random.nextint(6) + 1. Below is an example of how to use the Random class: import java.util.random; public class ExampleClass { public static void main(string[] args) { int diceroll1, diceroll2; Random random = new Random(); diceroll1 = random.nextint(6) + 1; diceroll2 = random.nextint(6) + 1; } } You only need to have the statement Random random = new Random(); one time in your code. Every time you invoke random.nextint(6), it will return a random value from 0 to 5. Remember, every time you roll the dice, you will need to invoke this method for both die, similar to the example above. The Program Create a new class in this project called Craps. You will write a program that plays the craps dice game. Your program must do the following: 1) Create a constant and store in it the initial starting balance of 50. 2) Start the program by showing a welcome message and the rules of craps. You should only display this to the user ONE time (not every time we loop). 3) Begin a loop that should continue until either the user enters 0 as a bet, or the current balance is 0. If the user enters 0, the program should display the appropriate game ending messages such as in my output and then immediately terminate. 4) At the start of a new set of rolls, display the user s current balance and then prompt the user to enter a bet amount.

5) You may assume that all user bets will be an integer value (assume the user will not enter values like 1.5) the must be from 1 up to the current balance (at the start, users should only be allowed to enter a bet from 1 to 50, or 0 if they want to exit the game). a. If the user enters a bet less than 0 or greater than balance, the program should inform the user of an invalid bet and then again prompt the user for a another bet, as in my example, until a valid bet is entered. 6) After a valid bet, display the value of each dice roll and the total of the two dice together. For dice rolls, we need the random number generator described above. a. If it s a winning roll, inform the user and then add the value of the bet to the current balance b. If it s a losing roll, inform the user and then subtract the value of the bet from the current balance c. If it s a roll that requires more rolling, continue rolling and displaying the values of the rolls (as in my output) until either a winning roll or a losing roll occurs, based on the rules of Craps. 7) Continue to play the game until one of the conditions in part 3 above occurs. At the end of the game, display the appropriate game ending messages. If the current balance is greater than or equal to the starting balance, consider it a win and display the amount above $50.00 that was won; for example, You won $19.00. If the current balance is less than the starting balance, display something the amount lost, for example, You lost $25.00. 8) Don t forget that the balance at all times must be formatted as currency. The printf() method makes this easier. Refer back to assignment 4 if you don t remember how to do this. Tips: To complete this program, consider using a do-while loop for the outer loop, a nested do-while loop to verify the bet amount, and another nested while loop for the continuing dice rolls. When examining whether a first roll is a win, a loss, or a continuing roll, a switch statement works nicely. Example Output 1 (User input is the bolded blue text) Welcome to Craps! Rules 1. Start by placing a bet 2. The dice are then rolled - Rolling a 7 or 11 is a win - Rolling a 2, 3 or 12 is a loss - Otherwise, rolling continues until: -- Rolling the original total of the dice again (win) -- Rolling a 7 (loss)

Please enter a bet (or 0 to exit): -5 Invalid bet! Must be a value from 1 to 50. Please enter a bet (or 0 to exit): 51 Invalid bet! Must be a value from 1 to 50. Please enter a bet (or 0 to exit): 5 You rolled 5 and 3 totaling 8. More rolls needed: You rolled 5 and 2 totaling 7. Your current balance is $45.00 Please enter a bet (or 0 to exit): 46 Invalid bet! Must be a value from 1 to 45. Your current balance is $45.00 Please enter a bet (or 0 to exit): 0 GAME OVER Your final balance is $45.00 You lost $5.00 Thanks for playing! Example Output 2 (User input is the bolded blue text) Welcome to Craps! Rules 1. Start by placing a bet 2. The dice are then rolled - Rolling a 7 or 11 is a win - Rolling a 2, 3 or 12 is a loss - Otherwise, rolling continues until: -- Rolling the original total of the dice again (win) -- Rolling a 7 (loss) Please enter a bet (or 0 to exit): 5 You rolled 1 and 3 totaling 4. More rolls needed: You rolled 6 and 4 totaling 10. You rolled 3 and 5 totaling 8. You rolled 6 and 6 totaling 12. You rolled 1 and 2 totaling 3. You rolled 2 and 3 totaling 5. You rolled 4 and 4 totaling 8. You rolled 5 and 4 totaling 9. You rolled 3 and 6 totaling 9. You rolled 6 and 6 totaling 12. You rolled 1 and 2 totaling 3. You rolled 3 and 2 totaling 5.

You rolled 6 and 4 totaling 10. You rolled 1 and 6 totaling 7. Your current balance is $45.00 Please enter a bet (or 0 to exit): 1 You rolled 2 and 1 totaling 3. Your current balance is $44.00 Please enter a bet (or 0 to exit): 23 You rolled 3 and 4 totaling 7. You win! Your current balance is $67.00 Please enter a bet (or 0 to exit): 0 GAME OVER Your final balance is $67.00 You won $17.00 Thanks for playing! Example Output 3 (User input is the bolded blue text) Welcome to Craps! Rules 1. Start by placing a bet 2. The dice are then rolled - Rolling a 7 or 11 is a win - Rolling a 2, 3 or 12 is a loss - Otherwise, rolling continues until: -- Rolling the original total of the dice again (win) -- Rolling a 7 (loss) Please enter a bet (or 0 to exit): 50 You rolled 2 and 4 totaling 6. More rolls needed: You rolled 3 and 1 totaling 4. You rolled 2 and 1 totaling 3. You rolled 1 and 3 totaling 4. You rolled 3 and 2 totaling 5. You rolled 6 and 6 totaling 12. You rolled 3 and 1 totaling 4. You rolled 2 and 3 totaling 5. You rolled 5 and 6 totaling 11. You rolled 3 and 4 totaling 7. GAME OVER Your final balance is $0.00 You lost $50.00 Thanks for playing!

Example Output 4 (User input is the bolded blue text) Welcome to Craps! Rules 1. Start by placing a bet 2. The dice are then rolled - Rolling a 7 or 11 is a win - Rolling a 2, 3 or 12 is a loss - Otherwise, rolling continues until: -- Rolling the original total of the dice again (win) -- Rolling a 7 (loss) Please enter a bet (or 0 to exit): 13 You rolled 5 and 6 totaling 11. You win! Your current balance is $63.00 Please enter a bet (or 0 to exit): 25 You rolled 3 and 4 totaling 7. You win! Your current balance is $88.00 Please enter a bet (or 0 to exit): 60 You rolled 5 and 5 totaling 10. More rolls needed: You rolled 3 and 4 totaling 7. Your current balance is $28.00 Please enter a bet (or 0 to exit): 0 GAME OVER Your final balance is $28.00 You lost $22.00 Thanks for playing!

Assignment Submission Submit the following file to me on blackboard: Craps.java All assignments will be submitted through blackboard. You are only allowed ONE submission so do not submit the assignment until you are completely done with it. However, you can upload the assignment and save a draft without submitting it. If you do this, don t forget to submit it before the due date. Saving a draft and submitting it are not the same thing. To submit the assignment, login to http://blackboard.ecu.edu. Navigate to our course and then to the Assignments folder. Click the link that says Lab Assignment 5. On this new page, scroll down to where it says Attach File and attach the java files for your program. You will need to browse to the location where you saved the file on your computer. If you aren t sure where it is located, refer to assignment 1 on how to find out.