Give a non-void Java method called "moveRow" that has three parameters: an array of chars "board, a char "dir," and an int "r." The method should copy row "r" either up or down depending on whether dir is 'U' or 'D,' respectively. For example, consider the following 2D array: hrfak bnoqs klq p z camz p tyuwb If moveRow is call on the above array with dir='U' and r=3, then array would be modified as follows: hrfak bnoqs cam z p cam z p tyuwb On the other hand, if moveRow is call on the above array with dir='D' and r-1. then array would be modified as follows: hrfak bnoqs bnoqs cam z p tyuw b Note that you may assume that r is a valid row number, and that dir is either 'U' or 'D. However, you may not assume the requested operation is a valid operation. For example, if the method is called on the above array with dir = D' and r-4, then the operation cannot be performed. Similarly, the operation cannot be performed if the mcthod is called on the above array with dir='U' and r-0. In these cases your method should not modify the array, but simply return false. If the operation can be performed, then your method should modify the array appropriately, and return true.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 13RQ
icon
Related questions
Question

In java please

Give a non-void Java method called "moveRow" that has three parameters: an array of chars "board,"
a char "dir," and an int "r."
The method should copy row "r" either up or down depending on whether dir is 'U' or 'D!
respectively.
For example, consider the following 2D array:
hrfak
bnoqs
klqp z
Camzp
tyuwb
If moveRow is call on the above array with dir='U' and r-3, then array would be modificd as follows:
hrfak
bnogs
camz p
camz p
tyu wb
On the other hand, if moveRow is call on the above array with dir-'D' and r-1. then array would be
modified as follows:
hrfak
bnoqs
bnoqs
Camz p
tyuwb
Note that you may assume that r is a valid row number, and that dir is either 'U' or 'D. However, you
may not assumc the requcsted opcration is a valid operation. For example, if the method is called on
the above array with dir = 'D' and r-4, then the operation cannot be porformed. Similarly, the
operation cannot be performed if the mcthod is called on the above array with dir='U' and r-0. In
these cases your method should not modify the array, but simply return false.
If the operation can be performed, then your method should modify the array appropriately, and
return truc.
Transcribed Image Text:Give a non-void Java method called "moveRow" that has three parameters: an array of chars "board," a char "dir," and an int "r." The method should copy row "r" either up or down depending on whether dir is 'U' or 'D! respectively. For example, consider the following 2D array: hrfak bnoqs klqp z Camzp tyuwb If moveRow is call on the above array with dir='U' and r-3, then array would be modificd as follows: hrfak bnogs camz p camz p tyu wb On the other hand, if moveRow is call on the above array with dir-'D' and r-1. then array would be modified as follows: hrfak bnoqs bnoqs Camz p tyuwb Note that you may assume that r is a valid row number, and that dir is either 'U' or 'D. However, you may not assumc the requcsted opcration is a valid operation. For example, if the method is called on the above array with dir = 'D' and r-4, then the operation cannot be porformed. Similarly, the operation cannot be performed if the mcthod is called on the above array with dir='U' and r-0. In these cases your method should not modify the array, but simply return false. If the operation can be performed, then your method should modify the array appropriately, and return truc.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr