USING METHODS PROGRAMMING EXAMPLES



Similar documents
CS170 Lab 11 Abstract Data Types & Objects

Chapter 16: law of averages

Elementary Statistics and Inference. Elementary Statistics and Inference. 16 The Law of Averages (cont.) 22S:025 or 7P:025.

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Iteration CHAPTER 6. Topic Summary

Section 7C: The Law of Large Numbers

Roulette-Tools PATTERN RECOGNITION TRAINING

Automatic Bet Tracker!

THE 10 IDEAS BEHIND FOREX TRADING

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Solution (Done in class)

CMM Subject Support Strand: FINANCE Unit 1 Exchange Rates: Text. 1.1 Straightforward Exchanges. 1.2 Buying and Selling

GAMBLING DISC. Script ROULETTE TUTORIAL

MA 1125 Lecture 14 - Expected Values. Friday, February 28, Objectives: Introduce expected values.

AN INTRODUCTION TO TRADING CURRENCIES

36 Odds, Expected Value, and Conditional Probability

Chapter 16. Law of averages. Chance. Example 1: rolling two dice Sum of draws. Setting up a. Example 2: American roulette. Summary.

Chapter 1.1. The Forex Market

Expected Value. 24 February Expected Value 24 February /19

AMS 5 CHANCE VARIABILITY

Russell Hunter Publishing Inc

INTRODUCTION TO FOREIGN EXCHANGE

We rst consider the game from the player's point of view: Suppose you have picked a number and placed your bet. The probability of winning is

Note: To increase your bet by another amount, select another chip from the bottom right of the game panel.

How to Play Roulette Online

(1) American Wheel: Thirty-eight (38) compartments containing the numbers one through thirty-six (1-36) and a zero (0) and double zero (00).

THE WINNING ROULETTE SYSTEM.

Presents ITALIAN QUALITY & DESIGN. New AR Side Bet

Chapter 1.1. The Forex Market

Term Project: Roulette

Chapter 1.1. The Forex Market

Chapter 1.1. The Forex Market

Financial Management in IB. Exercises 1. I. Foreign Exchange Market

FTS Real Time System Project: Trading Currencies


Slides for Krugman and Obstfeld Chapter 13

Roulette. Math 5 Crew. Department of Mathematics Dartmouth College. Roulette p.1/14

Probability: The Study of Randomness Randomness and Probability Models. IPS Chapters 4 Sections

Making $200 a Day is Easy!

LAB4 Making Classes and Objects

The Student s Guide to. International Student Payments Made Simple. Your Guide to Saving Hundreds of Dollars When Paying Your Tuition Fees.

Minimax Strategies. Minimax Strategies. Zero Sum Games. Why Zero Sum Games? An Example. An Example

Introduction to Forex Trading

J a v a Quiz (Unit 3, Test 0 Practice)

Statistics 100A Homework 3 Solutions

Martin J. Silverthorne. Triple Win. Roulette. A Powerful New Way to Win $4,000 a Day Playing Roulette! Silverthorne Publications, Inc.

This Method will show you exactly how you can profit from this specific online casino and beat them at their own game.

Beating Roulette? An analysis with probability and statistics.

EASY MONEY? Compiled by. Campbell M Gold (2008) CMG Archives --()-- Important Note

How To Consistently Make $900 - $9,000 in 48 Hours or Less

Would You Like To Earn $1000 s With The Click Of A Button?

Worldwide Casino Consulting Inc.

Greg Fletcher. Sharpshooter Roulette. Video Guide. Russell Hunter Publishing, Inc.

INTRODUCTION. This program should serve as just one element of your due diligence.

3.2 Roulette and Markov Chains

University of Economics Prague Department of International Trade. International Financial Strategies. Content: 1. Foreign Exchange Markets

How to Win At Online Roulette

The purpose of this ebook is to introduce newcomers to the forex marketplace and CMTRADING. Remember that trading in forex is inherently risky, and

HSBC Premier Card Standard Account Fees

Roulette. Wheel layout. Betting. History

LIVE CASINO 1. ROULETTE GAME RULES. 1.1 Game Overview. 1.2 How to Play. 1.3 Bet Type Explanation

Elementary Statistics and Inference. Elementary Statistics and Inference. 17 Expected Value and Standard Error. 22S:025 or 7P:025.

Probability and Expected Value

Understanding Trading Performance in an Order Book Market Structure TraderEx LLC, July 2011

Forward exchange rates

The Perfect Investment

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

You can place bets on the Roulette table until the dealer announces, No more bets.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java CPD (I) Frans Coenen Department of Computer Science

1 Introduction. 1.5 Margin and Variable Margin Feature

101 Roulette Winning tips

Maverick FX Trading. Forex 101 Session #2 Forex Market Basics

How to Beat Online Roulette!

Building Java Programs

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

THE ROULETTE BIAS SYSTEM

STRIKE FORCE ROULETTE

TRADING CURRENCIES. OhMyGeorge! Gamers Make The Best Traders!

Online Roulette. American Roulette

Easy Casino Profits. Congratulations!!

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Lecture 4: Futures and Options Steven Skiena. skiena

CASINO GAMING AMENDMENT RULE (No. 1) 2002

Roulette Best Winning System!!!

The 3 Best Individual Strength Patterns. Thomas Yeomans

1) I met him. the concert. a) on b) during c) in d) for

TCM040 MSOM NEW:TCM040 MSOM 01/07/ :13 Page 1. A book of games to play with children

NEW TO FOREX? FOREIGN EXCHANGE RATE SYSTEMS There are basically two types of exchange rate systems:

Frequently Asked Questions. regarding CIB Bank Zrt. s. ecommerce online card-acceptance service

An introduction to the foreign exchange market Moorad Choudhry September 2002

The Best Online Roulette Games

FACT A computer CANNOT pick numbers completely at random!

So we thought we knew money

Topic Exploration Pack

Debugging Strategies

Björn Bäckström, Lars Olsén and Simon Renström Copyright 2011 ClaroBet AB. Updated: May. 12, 11 You may not distribute or copy any of the text or use

Exchange Rates: Application of Supply and Demand

Transcription:

USING METHODS PROGRAMMING EXAMPLES Roulette French Roulette is a casino game that uses a wheel with 37 pockets numbered 0 to 36. To play a straight-up bet, you lay your money beside any single number. The croupier spins the wheel in one direction and a ball in the opposite direction. When everything slows to a stop, if the ball lands in the pocket with your chosen number then you win $35 for every $ you bet. Let s write a simple Java application that uses the Spinner class to build an object that can simulate a French Roulette wheel. The simple application will spin the wheel and print the resulting number. The algorithm is: build a spinner object that can spin numbers from 0 to 36 spin the spinner print the spinner s stoppedat value Here s the application: 2 3 4 5 6 7 8 9 0 2 public class FrenchRoulette public static void main( String [] args ) // build the French Roulette wheel Spinner spinner = new Spinner( 0, 36 ); // spin it spinner.spin( ); // print the final result System.out.println( "Wheel rolls " + spinner.stoppedat ); Using Methods Programming s Page

Foreign Currency Exchange People who travel abroad can t normally buy stuff using the currency of their homeland. For example, a European traveling in the U.S. can t use euros to pay for his breakfast at Ma s Diner in Kit Carson, Colorado. Instead, he must go to a bank and use his euros to buy an equivalent amount of U.S. dollars. Since currencies differ in value, the bank applies an exchange rate to determine how many dollars the traveler can buy. Suppose dollar = euro so that dollars = euro. Let s pretend that our European visitor arrives with 250 and needs to buy dollars. 250 = 250 = $270.86 He returns to his home country with $55 left in his pocket. Since he no longer needs the left-over dollars, he sell them to the bank for: $55 = 55 = 50.77 In the world of finance, it is convention to express the X-to-Y exchange rate as X/Y where X and Y are standard codes taken from the ISO 427 code list published by the International Organization for Standardization. The ISO 427 code for the U.S. dollar is USD and for the euro is EUR. The dollar-to-euro exchange rate is expressed as USD/EUR. USD/EUR = means that USD = EUR. The X/Y exchange rate is Y / X exchange rate. If USD/EUR = then EUR/USD = 0. 9230 x USD = x EUR and x EUR = x USD Using Methods Programming s Page 2

I want to build a class from which programmers can build objects that do USD/X currency conversions, where X is some foreign currency. The details of the class are not important so long as its methods are well enough specified so that my fellow programmers can effectively use it. The name of the class is USD_X_Exchange and it provides this explicit constructor: public USD_X_Exchange( double rate ) // Construct object to convert U.S. dollars and currency X. // Parameter rate is the USD/X exchange rate. Using the information from this specification and the Java idiom for building objects, a programmer can write the following Java statement to build an object that does conversions between U.S. dollars and euros. I m assuming that USD/EUR = ; USD_X_Exchange usd_eur = new USD_X_Exchange( ); The class provides this method for buying dollars with euros: public double buydollars( double x ) // Use x of currency X to buy and return equivalent // amount of dollars. The following Java statement uses the usd_eur object to determine the amount of U.S. dollars that can be bought with 250: double dollars = usd_eur.buydollars( 250 ); The class has this method for buying euros with dollars: public double selldollars( double d ) // Sell d dollars and return equivalent amount in X. The following Java statement uses the usd_eur object to determine how many euros $55 will bring: double euros = usd_eur.selldollars( 55 ); The complete Java class is found on the next page. It is best, however, if you don t look at it. Your goal in this topic is to learn how to read the specification of the constructors and methods. Using Methods Programming s Page 3

2 3 4 5 6 7 8 9 0 2 3 4 5 6 7 8 9 20 2 22 23 24 25 26 // A USD_X_Exchange exchanges U.S. and foreign currency. public class USD_X_Exchange private double er; // USD/X exchange rate, USD = er X public USD_X_Exchange( double rate ) // Construct object to convert U.S. dollars and currency X. // Parameter rate is the USD/X exchange rate. er = rate; public double selldollars( double d ) // Sell d dollars and return equivalent amount in X. return d * er; // USD = er X public double buydollars( double x ) // Use x of currency X to buy and return equivalent // amount of dollars. return x / er; // X = /er USD Using Methods Programming s Page 4

Exercises Enter class USD_X_Exchange into jgrasp and save it to a file. Compile it. Perform the following experiments using jgrasp s Interactions pane. To answer the questions, observe jgrasp s Workbench pane.. In jgrasp s Interactions pane, enter and execute the statement: USD_X_Exchange usd_eur = new USD_X_Exchange( ); In jgrasp s Workbench pane, what is the value of reference variable usd_eur? Find the entry for usd_eur and click the so that it becomes. What is the value of the object s instance variable? 2. In jgrasp s Interactions pane, enter and execute the statement: double dollars = usd_eur.buydollars( 250 ); In jgrasp s Workbench pane, what is the value of the variable dollars? Is this result consistent with the first example on page 2? 3. In jgrasp s Interactions pane, enter and execute the statement: double euros = usd_eur.selldollars( 55 ); In jgrasp s Workbench pane, what is the value of the variable euros? Is this result consistent with the first example on page 2? Using Methods Programming s Page 5