1. Engineering
  2. Computer Science
  3. write java a class named sameends write a sameendstester to...

Question: write java a class named sameends write a sameendstester to...

Question details

Write JAVA a class named SameEnds. Write a SameEndsTester to test your class. SameEnds determines whether an array list has the same sequence of numbers at the left and at the end, and if so, how long that sequence is.

You will not prompt the user for data. Enter your test data via a SameEnds constructor from SameEndsTester. You may assume that all of the elements in the array list are integers.

For example, the array list

1 4 9 10 11 12 1 4 9

has the same sequence 1 4 9 at the left and the right, and it has length 3. Therefore, your SameEndsTester would print out “The longest sequence is 1 4 9, and the sequence length is 3”.

If the arraylist doesn't have a common sequence at the left and the right, such as

1 4 9 16 25

SameEndsTester should print out “There are no common sequences”.

The two sequences cannot overlap. For example, in the array

1 1 1 1      

    

the sequence 1 1 occurs at the left and the right, and your method should return “The longest sequence is 1 1, and the sequence length is 2”.

Turn in your 2 .java classes, SameEnds and SameEndsTester.

Please write like or from my code.

import java.util.ArrayList; import java.util.Scanner; public class SameEnds Scanner scan new Scanner(System.in); private ArrayList<Integer nums; // for list of names public SameEnds (ArrayList<Integer> nums) { this.nums nums; public void testEnds() String data for (int i- e; i <nums.size); i++) if (nums.get(i)nums.get(nums.size()- (i + 1))) data nums.get(i) + ; System.out.println(The longest sequence is +data): @Override public String toString) return SameEnds [numsnums ];

import java.util.ArrayList; public class SameEndsTester { public static void main(String[] args)t /I at [] iata-11,2,3,4,1,2) ArrayList<Integer alinew ArrayList<Integer>O: ali.add (ali); ali.add (2); ali.add (3); ali.add (4); ali.add(1) li.add(2); SameEnds typeNumnew SameEnds (ali); typeNum.testEnds ); System.out.print (typeNum);

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution