Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could you please help me with an optional challenge as well ? Problem 1 (20 points) Create a Java Main Class file titled Compare (15
Could you please help me with an optional challenge as well ?
Problem 1 (20 points) Create a Java Main Class file titled "Compare" (15 points) Write a public method (static method) arrayEqual(int[] a,int[] b) that takes two arrays and returns a boolean. If the two arrays have the same numbers in the same order, then the method returns true. Otherwise, it returns false. (5 points) In your main method, get user input for filling the two arrays. Then call the arrayEqual method. When the method returns true, print a message saying that the two arrays are equal. When the method returns false, print a message saying that the two arrays are not equal. Problem 2 (20 points) (20 points) Use a Java Main Class file titled "BoardGame" In the following problem, a board is an ArrayList with numbers. Each number in the list represents an empty position that can be filled. The list can have N number of items where N is a class variable (static final). Assign N to 10. 1. (4 points) Define a method (static method) create_board() that takes no arguments and creates the board with N number of positions (use a for loop and the add method of arrayLists). This method returns the board created (an ArrayList with numbers). 2. (4 points) Define a method (static method) print_board(ArrayList > board) that takes the board and prints it (that is, prints the items in the ArrayList). This method does not have a return value and hence is a void method. Your method should work for any values of N>1. Here's how the board with 10 positions should look when you print it: 12345678910 Note: You will need to convert the integers into strings before printing. Remember index starts from 0. 3. (6 points) Define a method (static method)_oick_position_to_fill(ArrayList board) that takes a board. Ask the user for a number input between 1 and 10 . Based on user choice the method will fill one of the board positions with a 0 if it is not already filled. For example, if user chooses position 2 (which is index 1 in the arrayList), the board should look like: 10345678910 If it is already filled with a 0 , print an appropriate message. 4. ( 6 points) In the main method, add the following code to test your methods and add comments to explain each line of the code. Be specific and provide detailed explanation. For example, first line- the method create_board() that takes no arguments is called, which creates an array list with N numbers and returns that list. If it is already filled with a 0, print an appropriate message. 4. (6 points) In the main method, add the following code to test your methods and add comments to explain each line of the code. Be specific and provide detailed explanation. For example, first line- the method create_board() that takes no arguments is called, which creates an array list with N numbers and returns that list. The returned list is assigned to the ArrayList variable board. ArrayList board = create_board(); print_board(board); for (int i=0;iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started