Question: Write a public static void method named shiftRight which takes a single parameter of an ArrayList of String objects. The method should shift every element

Write a public static void method named shiftRight which takes a single parameter of an ArrayList of String objects. The method should shift every element of the parameter ArrayList one position to the right, and move the last element of the list into the first position.

For example, if the parameter list passed to the method initially prints as [I, am, here], this would become [here, I, am] after the method is executed.

Write your shiftRight method in the U7_L3_Activity_One class. Use the runner class to test your method but do not add a main method to your U7_L3_Activity_One.java file or your code will not be scored correctly.

Hint: think about which built in ArrayList methods can cause multiple elements to shift when they are called.

RUNNER CODE

import java.util.Scanner; import java.util.ArrayList;

public class runner_U7_L3_Activity_One{

public static void main(String[] args){ Scanner scan = new Scanner(System.in); ArrayList words = new ArrayList(); System.out.println("Please enter words, enter STOP to stop the loop."); String input = scan.nextLine(); while(!input.equals("STOP")){ words.add(input); input = scan.nextLine(); } U7_L3_Activity_One.shiftRight(words); System.out.println(words); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!