Published using Google Docs
Java 5 - Insurance / Poker
Updated automatically every 5 minutes

Assignment 5 - Insurance / Poker

Option 1: Using Return Values and Parameters to Calculate Age and Life Expectancy for Car and Life Insurance

Option 2: Finish the 2-Card Poker game

Option 1: Using Parameters for Insurance Data

Setup Instructions

Create a new file called Assign5_Insurance.java

In run(), set up the following 2 variables:

Then code the following functionality

  1. Create a calculateAge method that returns the age of the user. 

  1. In run(), print “Driving Insurance Application”

  1. In run(), call the calculateAge method and store the value it returns into the age variable.

  1. Create a testAge method that takes in the age as a parameter and returns nothing.

  1. In run(), print “Life Insurance Application”.

  1. Next, in run(), ask the user and scan for their sexAtBirth.

  1. Create a yearsLeft method that takes in the age and the sex as parameters.  It returns nothing.

6. Call the yearsLeft method from run() (passing in the age and gender)

Option 2: Finish the Poker Game

Several days ago, we introduced parameters with a Casino example that included an isFlush and an isPair method.  The code has been copied onto the next page if you need it.

NOTE: Our in-class example used Player1 and Player 2 rather than calling Player 2 the ‘casino’. You can leave the code as Player1.

Your goal is to complete this example so it determines who wins the hand.  The final result should say: “The Casino Wins!” or “The Player Wins!”. (I would recommend saying why but this is optional.  “The Casino has a pair.  The player has high card only.  The Casino wins!”)

Copy the original example file into a new file called Assig5_Casino.

Here are the rules for determining the winner.  This is NOT necessarily the order in which you should code your if statements:

Final 10% - What if both have a flush or a pair?  Well if both have a pair, the highest pair should win.  If both have  flush then the highest card should win.  

Ask your teacher for the Casino start code if you do not have it.  A version is below but your in-class example may be different.