
Concept explainers
(Intro to Java)
- Open a new Java file called ArrayMethods.java.
- Read the Javadoc comment for each method below and write the method according to the description in the comment
- Once you are getting the correct output for all tests inside of main, upload your source file to Canvas
public class ArrayMethods {
/**
* Displays the contents of an array on the console
* with each element separated by a blank space
* Prints a new line character last
* @param nums the array to print to the console
*/
public static void printArray(int[] nums) {
return;
}
/**
* Assuming an array of integers, return true if 1
* is the first element or 1 is the last element
* Note: you may assume that you will be given an array
* of at least length 1
* is1FirstLast([1, 2, 10]) → true
* is1FirstLast([10, 1, 2, 1]) → true
* is1FirstLast([13, 10, 1, 2, 3]) → false
* @param numbers the array of int numbers
* @return whether or not 1 is the first or last element
*/
public static boolean is1FirstLast(int numbers[]) {
return false;
}
/**
* Given an array of int numbers, return true
* if the array is size 1 or more,
* AND the first element and the last element are the same.
* sameFirstLast([1, 2, 3]) → false
* sameFirstLast([1, 2, 3, 1]) → true
* sameFirstLast([1, 2, 1]) → true
* @param numbers the array of integers
* @return whether the first and last element are the same
*/
public static boolean sameFirstLast(int[] numbers){
return false;
}
/**
* Given an array of int numbers, add 10 to each element in the array
* return nothing.
* arrayAdd10([1,2,3]) -> [11, 12, 13]
* arrayAdd10([10, 30, 50, 79, 85]) -> [20, 40, 60, 89, 95]
* arrayAdd10([5]) -> [15]
* @param array the array of integer values
*/
public static void arrayAdd10(int array[]) {
return;
}
/**
* Given an array of ints numbers, multiply each element in the array by itself
* arraySquared([1,2,3]) -> [1, 4, 9]
* arraySquared([9, 10, 11, 12]) -> [81, 100, 121, 144]
* arraySquared([151]) -> [22801]
* @param array the array of integer values
*/
public static void arraySquared(int[] array){
return;
}
public static void main(String[] args)
{
boolean answer;
System.out.println("***Testing is1FirstLast***\n");
int array1[] = {1, 2, 10};
answer = is1FirstLast(array1);
System.out.println("Should print true: " + answer);
int array2[] = {10, 1, 2, 1};
answer = is1FirstLast(array2);
System.out.println("Should print true: " + answer);
int array3[] = {13, 10, 1, 2, 3};
answer = is1FirstLast(array3);
System.out.println("Should print false: " + answer);
System.out.println();
System.out.println("***Testing sameFirstLast***\n");
int array4[] = {1, 2, 3};
answer = sameFirstLast(array4);
System.out.println("Should print false: " + answer);
int array5[] = {10, 20, 50, 60, 80, 90, 10};
answer = sameFirstLast(array5);
System.out.println("Should print true: " + answer);
int array6[] = {1};
answer = sameFirstLast(array6);
System.out.println("Should print true: " + answer);
System.out.println();
System.out.println("***Testing arrayAdd10***\n");
int array7[] = {1, 2, 3};
arrayAdd10(array7);
System.out.println("Should print 11 12 13: ");
printArray(array7);
System.out.println();
int array8[] = {10, 30, 50, 79, 85};
arrayAdd10(array8);
System.out.println("Should print 20 40 60 89 95: ");
printArray(array8);
System.out.println();
int array9[] = {5};
arrayAdd10(array9);
System.out.println("Should print 15: ");
printArray(array9);
System.out.println("\n");
System.out.println("***arraySquared***\n");
int array10[] = {1, 2, 3};
arraySquared(array10);
System.out.println("Should print 1 4 9: ");
printArray(array10);
System.out.println();
int array11[] = {9, 10, 11, 12};
arraySquared(array11);
System.out.println("Should print 81 100 121 144: ");
printArray(array11);
System.out.println();
int array12[] = {151};
arraySquared(array12);
System.out.println("Should print 22801: ");
printArray(array12);
System.out.println("\n");
System.out.println("***End of Tests***");
}
}

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

- (Intro to Java) Explain the answers to the below questions. include a written answer to the question using step-by-step explanation 1. Write a method called arrayTimesFive The method takes one array of doubles as a parameter It multiplies each element in the array by 5 and stores the result It returns nothingarrow_forward(Flattening arrays with flatten vs. ravel) Create a 2-by-3 array containing the first six powers of 2 beginning with 2^0. Flatten the array first with method flatten, then with ravel. In each case, display the result then display the original array to show that it was unmodified. Please use Python and keep it simple.arrow_forward(Java in Eclipse) Write a method that returns the sum of all the elements in a specified column in a 2-D array using the following header: public static int sumCol(int[][] m, int colIdx) Included is a test class and a sample runarrow_forward
- 1)Examine the above code that creates the array: a)How is the base type of the array specified? b)How is the length of the array specified? c)How many Strings are actually stored in the array after the array has been created? d)How is the base type of the ArrayList specified? e)How is the capacity of the ArrayList specified? f)What is the capacity of the ArrayList? g)What is the size of the ArrayList?arrow_forward(True/False): The ArraySum procedure (Section 5.2.5) receives a pointer to any array ofdoublewords.arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 3. Define a class which stores up to 10 integer values in an array. The class should also define the following 4 public methods: setNumber – accepts an integer value to store in the array. The value is stored in the next available element of the array (first call to the method stores the value in element 0 with the second call storing the value in element 1.) The method returns true if there is room in the array and the integer was successfully stored. Returns false otherwise. clear – removes all values from the array so that the array can be reused. displayNumbers – displays the values currently stored in the array. getStats – determines the largest, smallest, and average of the values currently stored in the array. These values are returned to the caller via reference parameters. All methods should produce correct results regardless of the order in which…arrow_forward
- (Data exploration and Mining Method Proposal): Here you will explore your data both visually and/or statistically then propose methods for mining it. I- Present a simple statistical exploration of your data (correlations, standard deviations, means, medians). Also explore your data visually using methods such as histograms, scatterplots ,heat maps, box and whisker plots...) II- Propose a data mining method covered in the class to apply on your data.arrow_forward(Querying an Array of Invoice Objects) Use the class Invoice provided in the lab assignment to create an array of Invoice objects.Class Invoice includes four properties—a PartNumber (type int), a PartDescription (type string), a Quantity of the item being purchased (type int) and a Price (type decimal).Write a console application that performs the following queries on the array of Invoice objects and displays the results:a) Use LINQ to sort the Invoice objects by PartDescription.b) Use LINQ to sort the Invoice objects by Price.c) Use LINQ to select the PartDescription and Quantity and sort the results by Quantity.d) Use LINQ to select from each Invoice the PartDescription and the value of the Invoice(i.e., Quantity * Price). Name the calculated column InvoiceTotal. Order the results by Invoice value. [Hint: Use let to store the result of Quantity * Price in a new range variable total.]e) Using the results of the LINQ query in Part d, select the InvoiceTotals in the range$200 to…arrow_forward(In Java language) Create a class Called NetflixDemo Create two objects “user1” and “user2” of the Netflix class pictured below) Set various class variables for the Netflix class using these two objects. Call various methods of Netflix class using these two objects. public class Netflix {public String movies [] = new String[10];public String trendingTop5 [] = new String[5];public String continueWatching [] = new String[5];public String username;public String password;private boolean isAuthenticated;public double balance;public int subscriberSinceYear;public static void logininfo() {Scanner input = new Scanner(System.in);System.out.println("Enter the username");String username = input.nextLine();System.out.println("Enter the password");String password = input.nextLine();boolean isAuthenticated = true;System.out.println(isAuthenticated + " , You have successfully logged in ");System.out.println();}public static void trendingList(){Scanner input = new…arrow_forward
- (Java) Open up Eclipse and create a new class called ArrayListPractice.java Next, copy and paste the below program into your file and run the code. Your job is to take the given code, remove all the arrays and replace them with the identical ArrayLists. There should be no arrays in your program. You will need to call the ArrayList methods as defined in the lesson notes above. Note that you will not be able to do method overloading with ArrayLists so you should assign different names to your methods. Once you have made the changes, you should get identical output as the given version of the program. Submit your program when you are finished. /** * @author * CIS 36B * Activity 5.2 */ import java.util.ArrayList; import java.util.Scanner; public class ArrayListPractice { public static void main(String[] args) { int scores[] = {95, 96, 97, 98, 99}; System.out.println("Integer test scores:"); print(scores); System.out.println();…arrow_forward(Tic-Tac-Toe) Write a program that allows two players to play the tictac-toe game. Your program must contain the class ticTacToe to implement a ticTacToe object. Include a 3-by-3 two-dimensional array, as a private member variable, to create the board. If needed, include additional member variables. Some of the operations on a ticTacToe object are printing the current board, getting a move, checking if a move is valid, and determining the winner after each move. Add additional operations as needed.arrow_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





