Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java program. take your time and submit with comments. Assignment 5 Problem 1 Write a program that inputs a word and a justification then, using

image text in transcribed

image text in transcribed

image text in transcribed

java program. take your time and submit with comments.

Assignment 5 Problem 1 Write a program that inputs a word and a justification then, using nested loops, displays a pattern based on the letters in that word as shown in the following sample runs: Please enter a word: motorcycle Justification (L Left, RRight)? L lull Please enter a word: butterflies Justification (L-Left, R-Right)? r HINT: For right justification, you'll need a loop to print spaces before the loop that prints characters in each row Problem 2: Write a program to play the simple game Rock-Paper-Scissors (RPS), with the user playing against the computer. Rock In a non-computerized version of the game, two players would stand face to face and, at the count of three, each displays a hand gesture - one of the three shown at the right, representing a rock, paper or scissors Paper The winner is declared based on the following simple rules Scissor Rock breaks scissors rock wins .Scissors cut Paper scissors win .Paper covers Rock paper wins lueJ: Terminal Window-RPS In your version of RPS, the program will allow multiple games to be played. The user will be playing against the computer. The user's guess will be an input value, while computer's guess will be chosen randomly. Let's play... Your turn (ROCK 1, PAPER 2, SCISSORS 3):2 I picked ROCK, you win! Play again (y)? y Let's play... Your turn (ROCK-1, PAPER 2, SCISSORS 3): 2 I picked SCISSORS I win! The result of each game should be displayed Play again (y)? y When the user is tired and doesn't want to play any more games, the program should display the following statistics Let's play... Your turn (ROCK 1, PAPER-2, SCISSORS 3): 1 I picked SCISSORS you win! Play again (y)? y o The number of user wins o Number of user losses o Number of ties Let's play Your turn (ROCK-1, PAPER-2, SCISSORS 3): 2 I picked SCISSORS I win! Play again (y)? y A sample run is shown on the left. Let's play.. Your turn (ROCK-1, PAPER 2, SCISSORS 3): 1 I picked ROCK, we tied! Play again (y)?n Here are the stats: You won 2 times You lost 2 times We tied 1 times That was fun! 2 Problem 3: This problem is called the Monty Hall Problem, named after the original host of the game show "Let's Make a Deal" t's a perplexing little problem about probability The basic idea is that the game show host shows you three closed doors and asks you to pick one. Behind one door is a brand new car. The other two doors have goats behind them Whatever you pick is your prize. After you choose a door, but before it is opened, Monty (who knows where the goats are) opens one of the other doors revealing a goat. Then he says, "Before opening your door, l'll give you a chance to change your mind and swap your door for the remaining closed door." The dilemma is should you do it? It turns out, somewhat surprisingly, that you definitely should swap doors. Watch this YouTube video: to get an explanation of the problem and the logic behind its (non-obvious) answer For this assignment, you are to write a program that simulates the Monty Hall Problem for 10,000 trials. In each trial, first randomly pick a door (1, 2 or 3) where the car is placed. Then, randomly pick a door as the player's guess. Then pick a door for the host to reveal (not the same door the player chose, must have a goat behind it, chosen randomly if the remaining two doors both have goats). Then pick a strategy (either stay or swap) at random. Then increment appropriate counters. You'll need to count the number of times each of the two strategies was selected and also to count the number of wins for each strategy. After all trials are complete, print the counter values and the win percentage for each strategy

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Solve 2 cos(x) - 3 cos(x) + 1 = 0 for all solutions 0 < x < 2.

Answered: 1 week ago