Question
submit 1 .java file In the following, alistmeans just a sequence of positive integers. The input to thisproblem consists of two non-empty listsL1,L2(not necessarily sorted),
submit 1 .java file
In the following, alistmeans just a sequence of positive integers. The input to thisproblem consists of two non-empty listsL1,L2(not necessarily sorted), each containingnpositive integers; assume thatn1. Every integer inL1has afriendinteger inL2. Thefriendship is pretty simple. Assume thatL1,L2aresorted. Then for every 1in, theith item in the sortedL1and theith item in the sortedL2are friends.1
Here is an example for you. LetL1=(48,10,5,266,97) andL2=(100,2,5,46,20).After sorting them separately we obtain,L1=(5,10,48,97,266) andL2=(2,5,20,46,100).The friends can now be found using a simple 1-1 correspondence between these twosorted lists:(5,2),(10,5),(48,20),(97,46),(266,100).The objective is to keep the two given lists in correct order maintaining the friendshiprelationship, but in the input Antman has probably shuffled the listL1. Thor must restoreL2in the same order as the first list, according to the friendship relationship, as describedabove. For example, given the two above lists,L2must be reordered as (20,5,2,100,46) tobe in order with the listL1.Write a program in Java to help out Thor. The input is taken from a text file. Thisfile contains three lines. The first line containsn, the common length of the two lists.The second line contains the integers fromL1, separated by single spaces. Similarly, thethird line contains the integers fromL2. No list contains duplicates. The output shouldbe sent to a text file. This file should contain a line containing all the integers fromL2,arranged with respect toL1. For more details, refer to the code outlines provided withthis homework.For this assignment, you are not required to know how to read and/or write from filesin Java. This is already done for you in the partial code given to you. Just knowing theformat of the file, as described above, should be sufficient to solve this assignment.Your only task is to complete the method namedgenerateSolutiondefined inside theclassThorHelper.You cannot use any data structure other than arrays. For sorting (if you need) you may useArrays.sort()if you know how to use it otherwise you may use any basic sorting algorithmintroduced in your previous programming courses such as Bubble Sort/Selection Sort/InsertionSort.2 Sample tests1. Input (given in a .txt file):112Output (written to a .txt file): 22
2. Input (given in a .txt file):548 10 5 266 97100 2 5 46 20Output (written to a .txt file): 20 5 2 100 463. Input (given in a .txt file):101 2 3 4 5 6 7 8 9 1010 9 8 7 6 5 4 3 2 1Output (written to a .txt file): 1 2 3 4 5 6 7 8 9 10Please think about more test cases, possibly with more integers and use them to find bugsin your code. A good programmer must also be good tester in this case. Your code may begraded with a different set of test cases.3 What to deliver?Upload just the fileThorHelper.javato Canvas. Feel free to define additional helpermethods wherever needed. No need to upload anything else.Commenting is highly encouraged. Please test thoroughly before submission. Youwill be given zero if your program does not compile or gives unnecessary warnin
The mighty Thanos was finally defeated by the Avengers. The Antman, now feeling pretty bored, decided to make fun of Thor, who still doubts if he is still worthy! The Antman has thus decided to give the following number-ordering problem to Thor since the Antman thinks that Thor still cannot keep everything in correct order. In the following, a list means just a sequence of positive integers. The input to this problem consists of two non-empty lists L1,L2 (not necessarily sorted), each containing n positive integers; assume that n > 1. Every integer in L has a friend integer in L2. The friendship is pretty simple. Assume that L, L, are sorted. Then for every 1 sisn, the ith item in the sorted L, and the ith item in the sorted L, are friends. 1 Here is an example for you. Let L = (48,10,5,266,97) and L2 = (100,2,5,46,20). After sorting them separately we obtain, L1 = (5,10,48,97,266) and L2 = (2,5,20,46, 100). The friends can now be found using a simple 1-1 correspondence between these two sorted lists: (5,2), (10,5), (48,20), (97,46), (266,100). The objective is to keep the two given lists in correct order maintaining the friendship relationship, but in the input Antman has probably shuffled the list Lj. Thor must restore L2 in the same order as the first list, according to the friendship relationship, as described above. For example, given the two above lists, L2 must be reordered as (20,5, 2, 100, 46) to be in order with the list L. Write a program in Java to help out Thor. The input is taken from a text file. This file contains three lines. The first line contains n, the common length of the two lists. The second line contains the integers from Ly, separated by single spaces. Similarly, the third line contains the integers from L2. No list contains duplicates. The output should be sent to a text file. This file should contain a line containing all the integers from L, arranged with respect to 11. For more details, refer to the code outlines provided with this homework. For this assignment, you are not required to know how to read and/or write from files in Java. This is already done for you in the partial code given to you. Just knowing the format of the file, as described above, should be sufficient to solve this assignment. Your only task is to complete the method named generate Solution defined inside the class ThorHelper. You cannot use any data structure other than arrays. For sorting (if you need) you may use Arrays. sort if you know how to use it otherwise you may use any basic sorting algorithm introduced in your previous programming courses such as Bubble Sort/Selection Sort/Insertion Sort. 2 Sample tests 1. Input (given in a .txt file): 1 1 2 Output (written to a .txt file): 2 2 2 2. Input (given in a .txt file): 5 48 10 5 266 97 100 2 5 46 20 Output (written to a .txt file): 2052 100 46 3. Input (given in a .txt file): 10 12345678910 10987654321 Output (written to a .txt file): 12345678910 Please think about more test cases, possibly with more integers and use them to find bugs in your code. A good programmer must also be good tester in this case. Your code may be graded with a different set of test cases. 3 What to deliver? Upload just the file ThorHelper.java to Canvas. Feel free to define additional helper methods wherever needed. No need to upload anything else. Commenting is highly encouraged. Please test thoroughly before submission. You will be given zero if your program does not compile or gives unnecessary warningsStep 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