Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following class: public class Sequence { private ArrayList values; public Sequence() { values = new ArrayList(); } public void add(int n) { values.add(n);

Consider the following class:

public class Sequence

{

   private ArrayList values;

   public Sequence() { values = new ArrayList(); }

   public void add(int n) { values.add(n); }

   public String toString() { return values.toString(); } }

Add a method

public Sequence append(Sequence other)

that creates a new sequence, appending this and the other sequence, without modify- ing either sequence.

For example, if a is

1 4 9 16

and b is the sequence

9 7 4 9 11

then the call a.append(b) returns the sequence

1 4 9 16 9 7 4 9 11

without modifying a or b. 

 

------------------

Add a method

public Sequence merge(Sequence other)

to the Sequence class of above exervise that merges two sequences, alternating ele- ments from both sequences. If one sequence is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer sequence. For example,

if a is

1 4 9 16

and b is

9 7 4 9 11

then a.merge(b) returns the sequence

1 9 4 7 9 4 16 9 11

without modifying a or b. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

package vijay import javautilArrayList import javautilIterator public class Sequence private ArrayLi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
635f7c6f26e78_232388.pdf

180 KBs PDF File

Word file Icon
635f7c6f26e78_232388.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting for Governmental and Nonprofit Entities

Authors: Jacqueline L. Reck, James E. Rooks, Suzanne Lowensohn, Daniel Neely

18th edition

1260190080, 1260190083, 978-1259917059

More Books

Students also viewed these Accounting questions

Question

What is quality of work life ?

Answered: 1 week ago

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago