Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package assignment3; //22W Assignment 3 Solution: CarBrandsList.java // Insert your solution code into this file as instructed in the information document. Hints have been provided
package assignment3; //22W Assignment 3 Solution: CarBrandsList.java // Insert your solution code into this file as instructed in the information document. Hints have been provided on yur tasks. // Insert your javadoc style comments to clearly and thoroughly explain your work. // Ensure that you retain the names of all methods specifically mentioned in the instructions. // Note that there are code inbetween the print statements (see assignment information). // YOUR TASK 1: Add the necessary import statements here. import java.util.*; import java.util.LinkedList; public class CarBrandsList { public static void main(String[] args) { // add rides to list1 String[] rides = {"cardillac", "toyota", "suzuki", "chevrolet", "hyundai", "mercedies", "keke"}; // YOUR TASK 2 //create linked lists LinkedList list1; LinkedList list2; // add rides2 to list2 String[] rides2 = {"volvo", "subaru", "volkswagen", "nissan", "cardillac", "toyota", "honda"}; // YOUR TASK 3, 4 //Add the content of rides to list1 and then rides2 to list2. List list = Arrays.asList(rides); list1 = new LinkedList<>(list); list = Arrays.asList(rides2); list2 = new LinkedList<>(list); // YOUR TASK 5 //Add the elements in list2 to list1 using the addAll method. list1.addAll(list2); // YOUR TASK 6 // print out the updated content of list1 printList(list1); //release list2 resource. list2.clear(); // YOUR TASK 7 convertToUpper(list1); System.out.printf("%nDisplaying names of car brands in uppercase letters... "); printList(list1); //YOUR TASK 8 System.out.printf("%nDeleting car brands 5 to 7..."); deleteSublist(list1, 4, 7); System.out.printf("%nHere is the current list of car brands... "); printList(list1); //YOUR TASK 9 //print the current list in reverse order using a printReversedList method System.out.printf("%nReversed list.. "); printReversedList(list1); // TO DO: YOUR TASK 10 System.out.printf("%nSorted car brands in alphabetical order... "); Collections.sort(list1); printList(list1); // TO DO: YOUR TASK 11 System.out.printf("%nRemoving duplicate car brands... "); printNonDuplicates(list1); } // HINT: MORE TO DO: Insert all your methods in this section which includes: // Create a method named printList() and use it to print out the content of list. public static void printList(LinkedList list) { System.out.println(list); } // locate String objects and convert to uppercase public static void convertToUpper(LinkedList list) { list.replaceAll(String::toUpperCase); } // obtain sublist and use clear method to delete sublist items public static void deleteSublist(LinkedList list, int startPos, int endPos) { list.subList(startPos, endPos).clear(); } // print the list in reverse order public static void printReversedList(LinkedList list) { Collections.reverse(list); printList(list); } //locate String objects and eliminate duplicates public static void printNonDuplicates(LinkedList list) { for (int i = 0; i < list.size() - 1; i++) { if (list.get(i).equals(list.get(i + 1))) { list.remove(i + 1); i--; } } printList(list); } }
I need thorough explanations about each task or line for this code file. Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started