Consider the following "SequenceList" class: import java.util.ArrayList; public class SequenceList { //constant and instance variables private final static int maxSize = 20; //To control list size private ArrayList myList; // hold a list of unknown number of integer values %3! ... public void displayList ( ) {..} // assume this method is given and it displays elements of myList }//end Sequencelist 1) Complete "SequenceList" class by adding: A. [5 points] Constructor method that receives an array list of initial integer values; accept number of integers no more than maxSize. If listA has more than maxSize elements, the first maxSize elements are assigned to myList. public Seguancel ist(Arrayl ist listA) {..}

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question
Question 21
Complete the missing parts as indicated below:
Not yet
Consider the following "SequenceList" class:
import java.util.ArrayList;
public class Sequencelist {
answered
Marked out of
20.00
//constant and instance variables
private final static int maxSize = 20; //To control list size
private ArrayList<Integer> myList; // hold a list of unknown number of integer values
P Flag question
public void displayList () {...} // assume this method is given and it displays elements of myList
}//end Sequencelist
1) Complete "SequenceList" class by adding:
A. [5 points] Constructor method that receives an array list of initial integer values; accept
number of integers no more than maxSize. If listA has more than maxSize elements, the first
maxSize elements are assigned to myList.
public Sequancelist(ArrayList<Integer> listA) {..}
B. [5 points] checkSortedAsc method returns true if the elements of the array list myList are
currently sorted in ascending order (from smallest to largest); otherwise return false.
For example:
If you call the method with the array list 1 -4 9-16-7 9; returns false
If you call the method with the array list -18 -169 12; returns true
C. [5 points] removeNegative method that removes any negative integers from myList.
For example:
If you call the method with the array list 1-4-9 16-1 13 9; then it modifies array list to: 1 16 72 9
Transcribed Image Text:Question 21 Complete the missing parts as indicated below: Not yet Consider the following "SequenceList" class: import java.util.ArrayList; public class Sequencelist { answered Marked out of 20.00 //constant and instance variables private final static int maxSize = 20; //To control list size private ArrayList<Integer> myList; // hold a list of unknown number of integer values P Flag question public void displayList () {...} // assume this method is given and it displays elements of myList }//end Sequencelist 1) Complete "SequenceList" class by adding: A. [5 points] Constructor method that receives an array list of initial integer values; accept number of integers no more than maxSize. If listA has more than maxSize elements, the first maxSize elements are assigned to myList. public Sequancelist(ArrayList<Integer> listA) {..} B. [5 points] checkSortedAsc method returns true if the elements of the array list myList are currently sorted in ascending order (from smallest to largest); otherwise return false. For example: If you call the method with the array list 1 -4 9-16-7 9; returns false If you call the method with the array list -18 -169 12; returns true C. [5 points] removeNegative method that removes any negative integers from myList. For example: If you call the method with the array list 1-4-9 16-1 13 9; then it modifies array list to: 1 16 72 9
e Chrome
mic)
2) [5 points] Complete java main class "SeqListTester" that tests "SequenceList" class:
import java.util.ArrayList;
import java.util.Random;
public class SeqList Tester {
public static void main (String [] args) {
//declare an array list named seqValues to hold integer values
ArrayList<Integer> seqValues = new ArrayList<Integer>();
lluse random class to generate 10 random integer values within range [-20, 20]
Il and store them into array list seqValues
Il construct a sequence object called "newList" by passing seqValues to it.
Il check if elements of "newList" are sorted in ascending order
System.out.print("ls list sorted in ascending:");
Il remove all negative values (if any) from "newList"
J//end main
Transcribed Image Text:e Chrome mic) 2) [5 points] Complete java main class "SeqListTester" that tests "SequenceList" class: import java.util.ArrayList; import java.util.Random; public class SeqList Tester { public static void main (String [] args) { //declare an array list named seqValues to hold integer values ArrayList<Integer> seqValues = new ArrayList<Integer>(); lluse random class to generate 10 random integer values within range [-20, 20] Il and store them into array list seqValues Il construct a sequence object called "newList" by passing seqValues to it. Il check if elements of "newList" are sorted in ascending order System.out.print("ls list sorted in ascending:"); Il remove all negative values (if any) from "newList" J//end main
Expert Solution
Step 1

1. a) listA obj=new listA();

     obj.displaylist();

b) bool a,b;

int b=new int[-18,-1,6,9,12];

return true;

int a=[1,-4,9,-16,-7,9];

return false;

c)public class newlist{
   public static void main(String[] args) {
      List<Integer> objArray = new ArrayList<Integer>();
      objArray.clear();
      objArray.add(2);
      objArray.add(-3);
      objArray.add(4);
      System.out.println("Array before removing an element "+objArray);
      Iterator<Integer> iterator = objArray.iterator();
     
         while(iterator.hasNext()) {
         Integer next = iterator.next();
         if(next < 0) {
            iterator.remove();
         }
      }
      System.out.println("Array after removing an element"+objArray);
   }
}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT