Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code is to completed using JAVA: Here is an example of the permutation game that is supposed to be coded and how it

The following code is to completed using JAVA:

Here is an example of the permutation game that is supposed to be coded and how it should run:

How many elements (5-20) would you like to shuffle? 345 How many elements (5-20) would you like to shuffle? -543 How many elements (5-20) would you like to shuffle? 10 Here is your shuffled array: 5 4 9 10 7 8 6 2 1 3 You have 17 turns remaining. Enter # of elements (2 - 10) to reverse: -5 Enter # of elements (2 - 10) to reverse: 12 Enter # of elements (2 - 10) to reverse: 4 Here is your array with the first 4 elements reversed. 10 9 4 5 7 8 6 2 1 3 You have 16 turns remaining. Enter # of elements (2 - 10) to reverse: 10 Here is your array with the first 10 elements reversed. 3 1 2 6 8 7 5 4 9 10 You have 15 turns remaining. Enter # of elements (2 - 10) to reverse: 5 Here is your array with the first 5 elements reversed. 8 6 2 1 3 7 5 4 9 10 You have 14 turns remaining. Enter # of elements (2 - 10) to reverse: 8 Here is your array with the first 8 elements reversed. 4 5 7 3 1 2 6 8 9 10 You have 13 turns remaining. Enter # of elements (2 - 10) to reverse: 3 Here is your array with the first 3 elements reversed. 7 5 4 3 1 2 6 8 9 10 You have 12 turns remaining. Enter # of elements (2 - 10) to reverse: 7 Here is your array with the first 7 elements reversed. 6 2 1 3 4 5 7 8 9 10 You have 11 turns remaining. Enter # of elements (2 - 10) to reverse: 6 Here is your array with the first 6 elements reversed. 5 4 3 1 2 6 7 8 9 10 You have 10 turns remaining. Enter # of elements (2 - 10) to reverse: 5 Here is your array with the first 5 elements reversed. 2 1 3 4 5 6 7 8 9 10 You have 9 turns remaining. Enter # of elements (2 - 10) to reverse: 2 Here is your array with the first 2 elements reversed. 1 2 3 4 5 6 7 8 9 10 Congratulations, you sorted it! Would you like to play again? Enter 1 for yes Enter 2 for no 1 How many elements (5-20) would you like to shuffle? 5 Here is your shuffled array: 1 3 5 2 4 You have 7 turns remaining. Enter # of elements (2 - 5) to reverse: 5 Here is your array with the first 5 elements reversed. 4 2 5 3 1 You have 6 turns remaining. Enter # of elements (2 - 5) to reverse: 4 Here is your array with the first 4 elements reversed. 3 5 2 4 1 You have 5 turns remaining. Enter # of elements (2 - 5) to reverse: 3 Here is your array with the first 3 elements reversed. 2 5 3 4 1 You have 4 turns remaining. Enter # of elements (2 - 5) to reverse: 2 Here is your array with the first 2 elements reversed. 5 2 3 4 1 You have 3 turns remaining. Enter # of elements (2 - 5) to reverse: 5 Here is your array with the first 5 elements reversed. 1 4 3 2 5 You have 2 turns remaining. Enter # of elements (2 - 5) to reverse: 4 Here is your array with the first 4 elements reversed. 2 3 4 1 5 You have 1 turn remaining. Enter # of elements (2 - 5) to reverse: 3 Here is your array with the first 3 elements reversed. 4 3 2 1 5 Out of turns - Game Over! Would you like to play again? Enter 1 for yes Enter 2 for no 2 Good-bye!

_________________________________________________________________________________________________________________________________________

INSTRUCTIONS FOR COMPLETING THE CODE:

Requirements:

  • Use at least three methods outside of main

  • Use while loops to error check and validate all user input

Part One - Initializing the Game

  • Have the user input a number between 5 and 20 (validate the input) to represent their array size, n.

  • Fill an integer array with the elements {1, 2, 3, ..., n}

  • Shuffle the contents of the array.

  • Create an integer to represent the number of turns allowed, represented by 2*n-3

Part Two - Playing the Game

  • Display the shuffled array.

  • Have the user input a number, p, representing how many elements (counting from the left) they would like reversed (validate the input)

  • Display the resulting array.

  • The game continues until the array is re-sorted into ascending order, OR until the user runs out of turns.

  • Ask the user if they would like to play again (validate the input)

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

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions