Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA LANGUAGE Problem: Flip and Grow is a game played by students in their spare time. In this game, all the players are given

IN JAVA LANGUAGE

Problem: Flip and Grow is a game played by students in their spare time. In this game, all the players are given a string of 1,5, and 2 characters of some fixed length and the goal is to convert this string to one where all characters are the first character in the string, scanning left to right flipping characters to match the first character of the string until the end is reached. In a turn, a student is allowed to perform only one operation: Replace a '2' by a '1'; replace a '1' by a '2'; or if it is a 5 you can replace it with a 1 or 2, flip the rest like before, but you have to add 12 to the end of the string.

For the replace 1 and 2 options, each such operation will flip all the 1s to 2s and vice versa for all the digits following the digit you changed (5s stay the same). Take for example, the string: 1121521. You decide to flip the '2' located at the 3rd position. The new string after the operation will be: 1112512. (Note that 4th to 7th numbers that were not a 5 flipped as a result of flipping the 3rd character.) If our string was 1111521, we would replace the 5 with the first character in this string (1 in this case) and add 12 to the end resulting in 111112112 Give the number of moves necessary to convert the string so all characters match the first character following the rules above.

Input File: FlipAndGrowIn.txt

Output File: FlipAndGrowOut.txt

Ex. input (values in parenthesis are showing steps and work but would not be in the input file:

15212 (15212->1121212 -> 1112121 -> 1111212 -> 1111121 -> 1111112 -> 1111111)

221551 (221551 -> 222552 -> 22225212 ->2222221212 -> 2222222121 -> 2222222212 -> 2222222221 -> 2222222222 )

Ex. Output

1111111,6

2222222222,7

Required: Include a 2-dimensional array of the digits The array must be exactly the length of the current string Whenever the array grows (i.e. flip 5), a new array accounting for the new longer size must be allocated and the previous values copied over to the new array.

NEED: source java file(s)and a picture or screenshot that shows the Eclipse debugger stopped at a breakpoint where it is checking if the next character is a 5.

FlipAndGrowIn.txt file has inside

15212

221551

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_2

Step: 3

blur-text-image_3

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Discuss cross-cultural differences in perception

Answered: 1 week ago

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago