EBK BUILDING JAVA PROGRAMS
EBK BUILDING JAVA PROGRAMS
4th Edition
ISBN: 9780134323718
Author: Stepp
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
Expert Solution & Answer
Book Icon
Chapter 15, Problem 1E

Explanation of Solution

Adding the “lastIndexOf” methods in “ArrayIntList” class:

//definition of "ArrayIntList" class

public class ArrayIntList

{

    //declare the required variables

    private int[] elementData;

    private int size;

    //refer the remaining methods in the textbook

    //definition of "lastIndexOf" method

    public int lastIndexOf(int value)

    {

/*iterate "i" until it reaches the size of an array*/

        for (int i = size - 1; i >= 0; i--)

        {

            //check the condition

            if (elementData[i] == value)

            {

                //return the "i" value

                return i;

            }

        }

        //return the value

        return -1;

    }

}

Explanation:

In the above program, the “ArrayIntList” is the class name,

  • Inside the “ArrayIntList” class, declare the “elementData”, and “size” variables as a private integer datatype.
    • The “lastIndexOf” method is defined inside the “ArrayIntList” class with the integer value as the parameter.
      • The “for” loop is used to iterate the value until it reaches size of an array.
        • The “if” loop is used to check whether the array of element value is equal to passed value.
          • The “ith” position of an array value is returned.
      • If the value is not in an array return the -1 value.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Write a method called replaceAll that accepts two integer values as parameters and replaces all occurrences of the first value in the list with the second value. For example, if a variable called list stores [11, –7, 3, 42, 3, 0, 14, 3], the call of list.replaceAll(3, 999); should change the list to store [11, –7, 999, 42, 999, 0, 14, 999].
in Jave create a method work() with the follow instructions: If the work() method is passed a non-null then it must return a new List that contains some or all of the elements in data. The elements of the new List must be aliases for (not copies of) the objects in the List it is passed.   If there are no sign attributes (i.e., the array is null or has 0 elements) then the work() method must return an empty List.   If any of the conditions represented by the sign attribute holds for a particular element that that element must be included in the result (i.e., the conditions must be combined using a logical OR).   The elements in the returned List must be in the same order they appeared in the original List (though not all elements must be in the result).   public List<T> work(List<T> g){
Create a program that removes duplicate integer values from a list. For example if a list has these valuesList = [5, 7, 8, 10, 8, 5, 12, 15, 12]. After applying the removal function, you should have List = [5, 7, 8,10, 12, 15]. In your case you will get the numbers of list from the user.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education