Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is an exercise about -ArrayList- Please solve it in a simple way Assignment 18 - ArrayList 1. Create an ArrayList of Integers, list, including

This is an exercise about -ArrayList-
Please solve it in a simple way
image text in transcribed
image text in transcribed
image text in transcribed
Assignment 18 - ArrayList 1. Create an ArrayList of Integers, list, including the Integers 23,7, 18, 5. a. Print the elements of the ArrayList list. b. Add a 99 at position 1 (or index 1) of the ArrayList and print its element. c. Add 44 without specifying a position and print the elements of list. d. Remove a number from position 3 and print the ArrayList. e. Try to insert or delete from an index out of the range of indices, -1 and 6. What type of error has occurred? // Write the statement and type of error as a comment 2. Create an ArrayList descending. c. Use a for loop to add the elements of the ArrayList numbers to the ArrayList descending in a reversed order. d. Display the two ArrayLists. e. Use the for loop to convert every element in descending to its Double value and save it in an ArrayList des Double Display the elements of the array list and check if the elements has been changed 3. Create an ArrayList, books, of type String that contains a list of the titles of your favorite 3 books. a. Insert the book title "Tom and Jerry" into location 1 and print the ArrayList. b. Remove the 3rd item in the ArrayList, books. c. Use the method set to change the 1st element of the ArrayList books to "Bugs Bunny". d. Ask the user to input a title and add it in the books. e. Ask the user to input a title and check if it is in the books. Print a message indicating if the title has been found in the list or not. 4. A class Student has two attributes, a string name and double spa. The class has a constructor which sets the two attributes. It has an accessor method for the name and gpa and a mutator method for the goa. a. Write a static method that given an ArrayList of students, displays the names of the honor roll students, those who earned above 3.5 kpa. public static void displayHonor Roll (ArrayList list) b. Write a static method that, given an ArrayList of students, returns an ArrayList including all the passing students, those who have earned 2.0 gpa and above. public static ArrayList passingStudents (ArrayList list) Assignment 18 - ArrayList c. Write a static method that, given an ArrayList of students, deletes from that ArrayList those who did not pass (gpa deleteFailingStudents (ArrayList list) d. Write a static method that, given the name of a student and an ArrayList of students will return the object representing that student from the list. If the student is not in the list, then the method will return null. public static Student find (String s, ArrayList list) e. Create a StudentTest class, test the 4 methods, and use the following data to your program: Student Name Gpa Omer 2.2 Khaldah 3.7 Tariq 1.9 Zoe 1.8 3.5 Mai Ahmed 3.6 5. Write a method markLength4 that takes an ArrayList of Strings as a parameter and that places a string of four asterisks "****" in front of every string of length 4. For example, suppose that a variable called list contains the following values: ["this", "is", "lots", "of", "fun", "for", "every", "Java", programmer"] And you make the following call: markLength4(list); then list should store the following values after the call: ("****", "this", "is", "****", "lots", "of", "fun", "for", "every", "****" "Java", "programmer") Notice that you leave the original strings in the list,"this", "lots", "Java", but include the four-asterisk string in front of each to mark it. public static void markLength4 (ArrayList list) Note that this method modifies the ArrayList that has been passed to it as an argument. Assignment 18 - ArrayList 6. Write a method switchPairs that switches the order of values in an ArrayList of Strings in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on. For example, if the list initially stores these values: ["four", "score", "and", "seven", "years", "ago"] your method should switch the first pair, "four","score", the second pair, "and", "seven", and the third pair,"years", "ago", to yield this list: ("score", "four", "seven", "and", "ago", "years") If there are an odd number of values in the list, the final element is not moved. For example, if the original list had been: ["to", "be", "or", "not", "to", "be", "hamlet"] It would again switch pairs of values, but the final value, "hamlet" would not be moved, yielding this ["be", "to", "not", "or", "be", "to", "hamlet"] public static ArrayList switchpairs (ArrayList list) list

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions