1 2 3 4 5 6 4 7 import java.io.File; 8 import java.io.FileNotFoundException; 9 import java.util.Scanner;...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1 2 3 4 5 6 4 7 import java.io.File; 8 import java.io.FileNotFoundException; 9 import java.util.Scanner; import java.util.NoSuchElementException; 5 6 8 9 0 8 19 0 :7 8 3 -4 -5 4 i0 51 2 3 4 6 "4 * CSC 225 - Assignment 3 * Name: #6 * Student number: */ public class ArrayMatch { * match * Purpose: Determine if the two given arrays 'match' * Parameters: int[] a, int[] b - the two arrays * Returns: boolean - true if arrays 'match', false otherwise * Preconditions: a and b have the same number of elements */ public static boolean match(int[] a, int[] b) { // TODO complete the implementation return false; // change this set to false so it compiles } * fillArray * Purpose: Fills arrays with contents read from Scanner * Parameters: int[] x, Scanner fileReader * Returns: nothing */ public static void fillArray (int[] x, Scanner fileReader) throws NoSuchElementException { Scanner f = new Scanner (fileReader.nextLine()); for (int i = 0; i < x.length; i++) { x[i] = f.nextInt(); } } * a3Setup * Purpose: Initializes the input arrays for Assignment 3 match detection by reading data from the text file named fname * Parameters: String fname - name of the file containig input data * Returns: nothing */ public static void a3Setup (String fname) { Scanner fileReader = null; int[] A = null; int[] B = null; } try { fileReader = new Scanner(new File(fname)); } catch (FileNotFoundException e) { System.out.println("Error finding input file"); e.printStackTrace(); return; } try { int size= Integer.parseInt(fileReader.nextLine()); A = new int[size]; B = new int[size]; fillArray (A, fileReader); fillArray (B, fileReader); } catch (NoSuchElementException e) { System.out.println("Error reading input file data"); e.printStackTrace(); } } if (match (A,B)) { System.out.println("match found"); } else { System.out.println("no matches"); public static void main(String[] args) { if (args.length < 1) { System.out.println("Incorrect usage, should be:"); System.out.println("java MysteryArray filename.txt"); return; } a3Setup (args[0]); 3. Complete the implementation of the match method in ArrayMatch.java. This method determines if a match (something we are defining for this particular problem) can be found when examining two arrays, A and B. B. and B are arrays of size n, containing the same number of integer elements. Two arrays, A and B, are defined to be matches of one another if at least one of the following two conditions is satisfied: I. A=B (the arrays have the same elements at each index) II. If n is divisible by 2, A and B are divided into two sub-arrays of equal size (A is divided into A and A, B into B and B). Then, at least one of the following conditions is satisfied: a) (A matches B)^(Amatches B) b) (A matches B)^(Amatches B) c) (Amatches B)^(Amatches B) Note: if n is not divisible by 2, condition II is not satisfied. Additional Information: You cannot change the method signature for match at all (two integer arrays as parameters, and returns a boolean) or you will receive a score of 0. If your submission fails to compile, you will receive a score of 0. You are welcome to create additional methods to aid in your implementation, but again, the match method must return a boolean when given two integer arrays. The methods provided for you will handle file I/O. When executed, the program reads from input files, and outputs whether a match is found based on the array data found in the file. The program is executed in the following way: java ArrayMatch filename.txt Input files must be three lines, formatted in the following way: You have been provided with some sample files. It is strongly recommended you add further tests. File name test01.txt test02.txt test03.txt test04.txt Expected output match found no matches match found match found Reasoning A=B AB, and no conditions from II are satisfied: when the arrays are split, AB, A B A #B, and A B, and the size (n) is not divisible by 2 for these arrays, so no further splits are made. II b) is satisfied, (A matches B)^(Amatches B) II a) is satisfied: (A matches B) trivially. Eventually we will also see A matches B after a number of sub-arrays are created and determined to be matches of one another. I recommend drawing a picture! 1 2 3 4 5 6 4 7 import java.io.File; 8 import java.io.FileNotFoundException; 9 import java.util.Scanner; import java.util.NoSuchElementException; 5 6 8 9 0 8 19 0 :7 8 3 -4 -5 4 i0 51 2 3 4 6 "4 * CSC 225 - Assignment 3 * Name: #6 * Student number: */ public class ArrayMatch { * match * Purpose: Determine if the two given arrays 'match' * Parameters: int[] a, int[] b - the two arrays * Returns: boolean - true if arrays 'match', false otherwise * Preconditions: a and b have the same number of elements */ public static boolean match(int[] a, int[] b) { // TODO complete the implementation return false; // change this set to false so it compiles } * fillArray * Purpose: Fills arrays with contents read from Scanner * Parameters: int[] x, Scanner fileReader * Returns: nothing */ public static void fillArray (int[] x, Scanner fileReader) throws NoSuchElementException { Scanner f = new Scanner (fileReader.nextLine()); for (int i = 0; i < x.length; i++) { x[i] = f.nextInt(); } } * a3Setup * Purpose: Initializes the input arrays for Assignment 3 match detection by reading data from the text file named fname * Parameters: String fname - name of the file containig input data * Returns: nothing */ public static void a3Setup (String fname) { Scanner fileReader = null; int[] A = null; int[] B = null; } try { fileReader = new Scanner(new File(fname)); } catch (FileNotFoundException e) { System.out.println("Error finding input file"); e.printStackTrace(); return; } try { int size= Integer.parseInt(fileReader.nextLine()); A = new int[size]; B = new int[size]; fillArray (A, fileReader); fillArray (B, fileReader); } catch (NoSuchElementException e) { System.out.println("Error reading input file data"); e.printStackTrace(); } } if (match (A,B)) { System.out.println("match found"); } else { System.out.println("no matches"); public static void main(String[] args) { if (args.length < 1) { System.out.println("Incorrect usage, should be:"); System.out.println("java MysteryArray filename.txt"); return; } a3Setup (args[0]); 3. Complete the implementation of the match method in ArrayMatch.java. This method determines if a match (something we are defining for this particular problem) can be found when examining two arrays, A and B. B. and B are arrays of size n, containing the same number of integer elements. Two arrays, A and B, are defined to be matches of one another if at least one of the following two conditions is satisfied: I. A=B (the arrays have the same elements at each index) II. If n is divisible by 2, A and B are divided into two sub-arrays of equal size (A is divided into A and A, B into B and B). Then, at least one of the following conditions is satisfied: a) (A matches B)^(Amatches B) b) (A matches B)^(Amatches B) c) (Amatches B)^(Amatches B) Note: if n is not divisible by 2, condition II is not satisfied. Additional Information: You cannot change the method signature for match at all (two integer arrays as parameters, and returns a boolean) or you will receive a score of 0. If your submission fails to compile, you will receive a score of 0. You are welcome to create additional methods to aid in your implementation, but again, the match method must return a boolean when given two integer arrays. The methods provided for you will handle file I/O. When executed, the program reads from input files, and outputs whether a match is found based on the array data found in the file. The program is executed in the following way: java ArrayMatch filename.txt Input files must be three lines, formatted in the following way: You have been provided with some sample files. It is strongly recommended you add further tests. File name test01.txt test02.txt test03.txt test04.txt Expected output match found no matches match found match found Reasoning A=B AB, and no conditions from II are satisfied: when the arrays are split, AB, A B A #B, and A B, and the size (n) is not divisible by 2 for these arrays, so no further splits are made. II b) is satisfied, (A matches B)^(Amatches B) II a) is satisfied: (A matches B) trivially. Eventually we will also see A matches B after a number of sub-arrays are created and determined to be matches of one another. I recommend drawing a picture!
Expert Answer:
Related Book For
An Introduction To Statistical Methods And Data Analysis
ISBN: 9781305465527
7th Edition
Authors: R. Lyman Ott, Micheal T. Longnecker
Posted Date:
Students also viewed these programming questions
-
answer all questions as instructed below. attend all questions. 4 Computer Vision (a) Explain why such a tiny number of 2D Gabor wavelets as shown in this sequence are so efficient at representing...
-
If you could choose, which type of school would you want your imaginary child(ren) to attend?
-
Waterhouse Company plans to issue bonds with a face value of $500,000 and a coupon rate of 10 percent. The bonds will mature in 10 years and pay interest semiannually every June 30 and December 31....
-
How do financial institutions manage interest rate risk arising from mismatches in the repricing profiles of their assets and liabilities, and what hedging strategies, such as duration matching,...
-
What is critical natural capital? Provide examples. For a company, who determines whether natural capital is a critical ecological resource? Is there a difference between other natural capital and...
-
Queensland Electronics Company manufactures two large-screen television models, the Novelle, which has been produced for 10 years and sells for $910, and the Zodiac, a new model introduced in early...
-
The company currently has outstanding a bond with a 5.5 percent coupon rate and another bond with a 3.5 percent coupon rate. The firm has been informed by its investment banker that bonds of equal...
-
7.32. An asteroid is at a distance of 2 106 km from Earth and is moving with a speed of 10 km/s. With- out gravitational pull, the asteroid would miss Earth by a perpendicular distance of 25,000 km...
-
5. a) Briefly explain the working principle of link state routing. Consider the network shown in Figure 1, and assume that each node initially knows the costs to each of its neighbors. Consider the...
-
Campbell Ski Company manufactures snow skis. During the most recent accounting period, the company's finishing department transferred 4,150 sets of skis to finished goods. At the end of the...
-
How do i display the Track details? - The web app will work for "get all" tracks and "get one" track. Example images are shown on the next page. My code: Manager.cs public IEnumerable...
-
Marvel Parts, Incorporated, manufactures auto accessories. One of the company s products is a set of seat covers that can be adjusted to fit nearly any small car. The company has a standard cost...
-
1. Part of a security fence is built 2.5 m from a cylindrical storage tank whose diameter is 11.2 m. What is the area between the tank and this part of the fence if the central angle of the fence is...
-
Belden, Incorporated, acquires 30 percent of the outstanding voting shares of Sheffield, Incorporated, on January 1, 2023, for $322,000, which gives Belden the ability to significantly influence...
-
13. The sides of a small rectangular box are measured to be 1.88 0.02 cm, 2.27 +0.02 cm, and 3.06 0.09 cm. Calculate the box's volume and the percent uncertainty of this volume.
-
Write a declaration for each of the following: a. A line that extends from point (60, 100) to point (30, 90) b. A rectangle that is 20 pixels wide, 100 pixels high, and has its upper-left corner at...
-
Refer to Exercise 10.70. Provide a description of the relationship between the sport the athlete was participating in and whether the athlete had sustained a previously unreported concussion. In...
-
A nuclear power plant has double redundancy on the feed water pumps used to remove heat from the reactor core. A safely operating plant requires only one of the three pumps to be functional. Define...
-
A study was designed to evaluate whether the population of interest has a mean greater than 9. A random sample of n = 17 units was selected from a population, and the data yield x-bar = 10.1 and s =...
-
The equation of motion of a rocket, of mass \(m\), traveling vertically under a thrust \(F\) and air resistance or drag \(D\) is given by \[m \dot{u}=F-D-m g\] If \(m=1000 \mathrm{~kg}, F=50,000...
-
Find the natural frequency of the system shown in Fig. 2.54. Figure 2.54:- Rotating machine B Isolator (Helical springs) FIGURE 2.54 Isolated rotating machine. Foundation block
-
Use Rayleigh's method to solve Problem 2.93. Data From Problem 2.93:- A uniform slender rod of mass \(m\) and length \(l\) is hinged at point \(A\) and is attached to four linear springs and one...
Study smarter with the SolutionInn App