
Concept explainers
Write a class ArrayMethods, where the main method asks the user to enter the
number of inputs and stores them in an array called myList. Create a method
printArray that prints the array myList. Create another method copyArray that copies
the array using System.arraycopy, and multiplies each element in the copied array by
2, then finally returns the array to the main method. Invoke the printArray again to
print the array returned by copyArray. In summary, see below. (!5 points)
• main method does: asks user for inputs and stores in array. Invoke printArray. Invoke copyArray.
Invoke printArray again.
• printArray: void method, parameters passed is an array, prints an array
• copyArray: array-returning method, parameters passed is an array, copies array, multiplies 2 to each
element in the copied array, returns the copied array
Sample Run
Enter the number of items: 4
Enter the numbers: 2 3 4 6
Your printed array: 2 3 4 6
Your copied printed array: 4 6 8 12
2. Write a class ArrayClass, where the main method asks the user to enter the four
numbers. Create a method printArray that prints the array whenever required (use
Array.toString method). Make the program run as shown in the Sample Run below.
Green is user input. (15 points)
Use Array.sort, Arrach.bianrySearch, Array.equals
Sample Run
List1, Enter four numbers: 2 3 3 2
List2, Enter four numbers: 6 2 5 4
List3, Enter four numbers: 5 2 4 6
Your original List1: [2, 3, 3, 2]
Your original List2: [6, 2, 5, 4]
Your original List3: [5, 2, 4, 6]
Sorted List1 is: [2, 2, 3, 3]
Enter a number from the sorted List1 to search for: 3
Value 3 is in index 2 (or position 3)
List that are the same when sorted: [2, 4, 5, 6]

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Java this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…arrow_forwardShow your code and console with the exact sample run. Thankyouarrow_forwardJava Problem Create an object of type FitnessExperiment that stores an array ofStepsFitnessTracker, DistanceFitnessTracker, andHeartRateFitnessTracker objects. In the FitnessExperiment class Add to your FitnessExperimentclass a method called getTotalDistance() that calculates the total distance walked by all theobjects stored in your FitnessExperiment. appropriately both values (total number of steps and total distance walked in that experiment) usingthe printExperimentDetails() method. FitnessExperiemnt.java public class FitnessExperiment {FitnessTracker[] fitnessTrackers;public static void main(String[] args) {FitnessTracker[] trackers ={ new StepsFitnessTracker("steps", new Steps(230)),new StepsFitnessTracker("steps2", new Steps(150)),new StepsFitnessTracker("steps2", new Steps(150)),new HeartRateFitnessTracker("hr", new HeartRate(80)),new HeartRateFitnessTracker("hr", new HeartRate(80)),new DistanceFitnessTracker("dist1", new Distance(1000)),new DistanceFitnessTracker("dist2",…arrow_forward
- A class Date has methods intgetMonth() and intgetDay(). Write a method public boolean has3OnSameDay(Date[] birthdays) that returns true if at least three birthdays in the array fall on the same date. Your method should work in O(n) time, where n = birthdays.length.arrow_forwardWrite a class ArrayClass, where the main method asks the user to enter the four numbers. Create a method printArray that prints the array whenever required (use Array.toString method). Make the program run as shown in the Sample Run below. Use Array.sort, Arrach.bianrySearch, Array.equalsarrow_forwardSubmit the code (copy&paste) with a screen shot of the same sample run as below. 1. Write a class ArrayMethods, where the main method asks the user to enter the num ber of inputs and stores them in an array called myList. Create a method printArray that prints the array myList. Create another method copyArray that copies the array using System.arraycopy, and multiplies each element in the copied array by 2, then finally returns the array to the main method. Invoke the printarray again to print the array returned by copyArray. In summary, see below. main method does: asks user for inputs and stores in array. Invoke printArray. Invoke copyArray. Invoke printArray again. printArray: void method, parameters passed is an array, prints an array copyArray: array-returningmethod, parameters passedis an array, copies array, multiplies 2 to each element in the copied array, returnsthe copied arrayarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





