Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CPSC6548 Lab Assignment #3

Assigned: Week 3 Due: Week 4 Points: 40

Part I (20 Points): The objective of this lab is to find out the “true” MPG (Miles Per Gallon) of a vehicle, given a group of
conditions which the user provides values for. 5 are given, 1 you create on your own. Requirements:

 Prompt the user for the car’s MPG first. i.e. Please Enter MPG: 26
 Then prompt the user to enter a value for six factors which will affect the MPG of the vehicle, prompting for single
value inputs after showing menus (i.e. a series of println() statements showing the options/valid values to enter)
 After collecting all of the inputs, provide a detailed report of the inputs, their meaning, how much they affect
MPG, as well as the beginning and final MPG.

The following criteria will be used for the six inputs.

1. City or Highway Driving: Use a boolean type variable for input


City Subtracts 2 from MPG
Highway Adds 5 to MPG
2. Rainy or Sunny: Use a String type variable for input
“Rainy” Subtracts 1 from MPG
“Sunny” No Change to MPG
3. Elevation: Use a char type variable for input
‘S’ for Steep, Steep Subtracts from 5MPG
‘H’ for Hilly, Hilly Subtracts 3 from MPG
‘F’ for Flat, No Change to MPG
4. Weight in Vehicle (cargo or passenger): Use double type for input
Each 100lbs subtracts 0.5 MPG
5. Speed Preference: Use an int type variable for input
1 for under speed limit, Add 2 to MPG
2 for at speed limit, No Change to MPG
3 for 5% above speed limit, Subtract 1 from MPG
4 for 10% above speed limit, Subtract 3 from MPG
5 for over 20% above speed limit, Subtract 5 from MPG

Suggestion: Use a switch() statement for Speed Preference

6. Add one additional factor which you will prompt the user for, that affects MPG such as
 tire pressure/condition,
 hybrid vs. gas powered,
 engine condition,
 towing load,
 2WD/4WD,
 etc.

Turning in your work, .zip file contents: Do not submit the .class file or other project files. Please submit only working
java programs (i.e. debugged without syntax errors, and compile-able) as well as the Word document containing the
output (screenshots or text copy/paste) produced by your programs.
Part II (20 Points): The purpose of this program is to use data types/variables, various selection structures, random
number generation, input/output, performing calculations and formatting output.

Description:  You have just been given the opportunity to win prizes from a sweepstakes entry you made at the county
fair!  The opportunity includes winning 4 prizes, each will be determined by a different game of chance.  You may create
your own descriptions for the prizes and values as you like, just make sure they are patterned as follows.  Each of these
requires a random number generation.

1. Flip a coin: Depending upon the heads or tails result, you will get prize1:
a. Heads:  A smartphone charger worth $9.99
b. Tails:  A 9-volt battery and a wire worth $0.49 (the booby prize)
2. Roll a six-sided die:  Depending upon the number that comes up, you will get prize2:
a. 1:  A refrigerator magnet worth $1.49
b. 2:  A handy grocery bag worth $.59 (the booby prize)
c. 3:  A half-price ticket to next year’s fair worth $4.00
d. 4:  A CD with hits from 12 bands playing at the fair worth $12.00
e. 5:  A coupon for a free item at one of the concession stands worth $5.00
f. 6:  A stuffed animal penguin worth $8.00
3. Spin a roulette wheel:  Depending on the color (red or black) and the number (1 to 100), you will get prize3:
a. Red doubles the prize, Black triples the prize
b. Spin 1-20:  Earn a penny (the booby prize)
c. Spin 21-40:  Earn $4.00
d. Spin 41-60:  Earn $1.00
e. Spin 61-80:  Earn $2.00
f. Spin 81-100:  Earn $3.00
4. Draw one card from a deck of 52:  Depending on the number, suit, or face card, you will get prize4:
a. Suits (multiplier):  Club (x1), Diamond (x2), Heart (x3), Spade (x4)
b. Numbers 2-10:  Get a deck of cards worth $1.00
c. Number 11 (Jack):  Get a game of jacks worth $.50 (the booby prize)
d. Number 12 (Queen):  Get an autographed picture of the fair queen worth $2.00
e. Number 13 (King):  Get an autographed picture of the fair king worth $2.00
f. Number 14: (Ace):  Get $10.00

After counting the number of booby prizes one person may get, use the following scale to award a consolation prize:
a. 1 booby prize:  $1.00
b. 2 booby prizes: $2.00
c. 3 booby prizes: $3.00
d. 4 booby prizes: $4.00
 
As you generate the random numbers (use any method you like), here are suggested variables:

 Store the following double values as prize1Value, prize2Value, prize3Value, prize4Value; 


 Store the following string values as prize1Desc, prize2Desc, prize3Desc, prize4Desc;
 Store the following string values as result1Desc, result2Desc, result3Desc, result4Desc;
 You should shorten the descriptions when storing them, keeping them to 20 chars or less.
 Store the count of booby prizes; 
 Accumulate the total dollar value of all prizes;
 Utilize as many other variables as you like
 You can experiment with validation loops (optional).
 Generate a report the information with a header and 4 detail lines formatted as such:
Example Output:
 
Game Result Value Booby Prize Description
 
1     flipped tails $ 0.49 yes 9-volt battery and wire
2     rolled 4 $12.00 no CD of hits
3     came up black 48 $ 3.00 no Money
4     drew Queen/Hearts $ 6.00 no Picture of Queen
 
Total Value:            $21.49
Total Booby Prizes:     1
 
You also earned $1.00 for on the booby prize contest!
 

You might also like