Write a method which reverses the order of items

Assignment Help JAVA Programming
Reference no: EM131219929

As we have discussed in class, section 4.1 of our text develops a List ADT and then offers two different implementations of it in the classes AList and LList.

The ADT is defined in a Java interface file List.java, and both AList and LList implement all the required methods of this interface. As a result, either implementation can be used, and while their internal methods and means of storing data differ, both give identical behavior.

During a recent class meeting, we wrote a class that created either an AList or LList object, used a few methods such as insert and remove, and printed it out. We saw that these features all worked correctly for both AList and LList objects; our code simply called the methods defined in the List interface and they worked.

For this assignment, you will write a new class and create three methods that take one (or two) List objects and perform operations on them using only the public List methods. Here are the three methods to write:

1 Write a method static void swap (List<Integer> l) which interchanges the current element in the list and the one following it. (First make it work in the normal case; then, if you still have time, make sure it handles special cases, such as: the list is empty; the list has only one element; current is at the end of the list

2 Write a method static void reverse (List<Integer> l) which reverses the order of items stored in the list. Again, make sure it works for any special cases you can think of.

3 Write a method static List mergeLists (List<Integer> l1, List<Integer> l2) which takes two sorted Lists as input, producing a new List containing all the elements of both lists, also sorted. The new list is the return value for the method.

In your test class's main method, write a series of statements to create several AList and/or LList objects (of type <Integer>) and put some data into them by calling the List append and/or insert methods. Use the lists you build as parameters to test each of your three methods and show that they work.

Test each of your three methods with a minimum of three different test inputs. Show that your methods work for various test cases such as the examples given above. Make sure your program prints the 'before' and 'after' lists for each of your tests.

Finally, copy the output of your program to a '.txt' or '.doc' file. Don't forget to put your name at the top of the document.

Attachment:- Assignment.rar

Reference no: EM131219929

Questions Cloud

How do nations differ in hrm : How do nations differ in HRM? What are the major national context characteristics that affect IHRM?
Identify the major business and financial risks : Identify the major business and financial risks such as interest rate risk, foreign exchange risk, credit, commodity, and operational risks. How do organizations measures risk and what global initiatives exist in financial risk management?
What data integrity and security issues do you foresee : The combined practice wants to implement wireless notepads for the physicians and staff to make changes directly to a patient's records. What data integrity and security issues do you foresee?
How much was new company net income or net loss : Assume that new Towne Company reported the following summarized data at September 30, 2016. Accounts appear in no particular order; dollar amounts are in millions.  Prepare the trial balance of New Towne at September 30, 2016. List the accounts in th..
Write a method which reverses the order of items : Write a method static void reverse (List l) which reverses the order of items stored in the list. Again, make sure it works for any special cases you can think of - write a series of statements to create several AList and/or LList objects (of typ..
Function of a particular set of circumstances : Almost all business situations are both complex a unique and are a function of a particular set of circumstances and individuals in which multiple realities exist that cannot be reduced to the sum of its parts (Saunders, Lewis and Thornhill 2012)...
Accounts payable-service revenue-cash-cost of goods sold : The Marchetti Soup Company entered into the following transactions during the month of June: (1) purchased inventory on account for $180,000 (assume Marchetti uses a perpetual inventory system); T-accounts: Accounts recievable, Accounts payable, Serv..
Complete slide presentation for the board of directors : Prepare a complete slide presentation for the Board of Directors (BOD) outlining the justification for implementing an improved Accounting and Control (AC) function describing activities, applications, justification and benefits of implementing an..
Are there conflicts of interest in the given deal : Are there conflicts of interest in this deal? If yes, will they help or hurt the deal? Are there real potential synergies in this merger? Will this deal create value for the shareholders of Tesla?Is the deal rightly priced?

Reviews

Write a Review

JAVA Programming Questions & Answers

  What type of output does the javadoc command

What type of output does the javadoc command generate and how do you view the output?

  Java application to carry out additions and subtractions

Design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number.

  Implement a program to reverse the digits

Write a method, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(12345) is 54321.

  Design a class named large integers

Design a class named largeIntegers such that an object of this class can store an integer of any number of digits.

  Create the look for two gui applications

Create the look for two GUI applications. You WILL NOT be getting the applications to do anything. We are only interested in seeing how well you can arrange the GUI components onto the window

  Write the classic arcade game of breakout

For each instance variable in your program, explain why you chose to make it an instance variable rather than a local variable - How did you test whether the game would end correctly in this second case? Did you make any changes to the code when test..

  Relationship between inheritance and subtyping

With this declaration of m in subclass B, any invocation of m on a B object will result in a special error indicating that the method should not be used. (a) What effect does this feature of Smalltalk have on the relationship between inherit..

  Design and implement recursive method findvalueunsortedarray

Design and implement a recursive method findValueUnsortedArray which takes two parameters: an unsorted array of integer values and an integer value which is looked for in the array.

  Write the java code for classes team and player

Write the Java code for classes Team and Player. Declare the classes in package com.myleague.reg. Provide an implementation of all methods according to the given method names. You can use the class Random fromjava.util to randomly pick a student

  A meanu driven program which maintain a list of car models

A meanu driven program which will maintain a list of a car models and their price

  Define two different physical representations for strings

Define an ADT for character strings. Your ADT should consist of typical functions that can be performed on strings, with each function defined in terms of its input and output. Then define two different physical representations for strings.

  A this adds storage of the maindata as an external random

a. this adds storage of the maindata as an external random access file with id as key to allow listall and query

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd