Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java 4- Write a generic method that takes an array of some class type as an argument and returns the last element of the array.

image text in transcribed
java
4- Write a generic method that takes an array of some class type as an argument and returns the last element of the array. The method should limit the base type of the array to those classes that implement the Comparable interface (i.e., define a bound for the type parameter). 5- Write a code fragment that creates an ArrayList of Integer called 'myList and initializes it with the first 10 multiples of 5 (0,5,10,15,20,25,30,35,40,45). Traverse 'myList' to find the sum of all the even numbers and then display the sum. 6-Write a code fragment that deletes one of the values, say 35, from the ArrayList defined in problem 5. Ask the user to type in that value at the keyboard. 7- Write a static method that takes a singly linked list of type Integer as an argument, and returns the sum of the values in the last two nodes. The method will return-1 if the list has less than two nodes (see the Single-Linked List class given in the textbook). 8- Add a method called 'removeSecond' to the class DoublyLinked List given in the textbook. This method will remove the second node from the doubly linked list if the list has at least two nodes. Otherwise it will throw an Exception of type IllegalState Exception. 9- Use a stack to convert the following infix expression to its equivalent postfix expression. Show the contents of the stack prior to each pop operation. 5+38/2-7 10- Write a client method named 'reverse that takes a Stack of Integers as an argument and reverses the order of elements on the Stack. Do this using just the stack operations defined in the stack interface (see page 149 of your textbook). You can define additional stacks inside your method in order to accomplish this task

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

Students also viewed these Databases questions

Question

How Prolog satisfies goals? How will you write rules in Prolog?

Answered: 1 week ago