Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Create an ArrayList of strings to store the names of celebrities or athletes. Add five names to the list. Process the list with a for loop and the get() method to display the names, one name per line. Pass the list to a void method. Inside the method, Insert another name at index 2 and remove the name at index 4. Use a foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the arraylist and use it to display the list one more time.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Similar questions
- Add a new method to ArrayTools with filter. Make this method accept a String array. Change all the Strings that are longer than 5 characters to uppercase. Write in Java and use test cases 1 & 2 as a result.arrow_forwardThe input to this method is supposedly an ArrayList of integers that ranges from 1 to 100, however this is not exactly the case. Sometimes, there will be gaps in the range for example, the range could be: [1 2 ... 7 8 ... 99 100], with missing ranges in between. Find all the missing numbers from the range, add them to an ArrayList, return the ArrayList.------------------------ Below is my code that is failing. It is returning the correct missing numbers but is not going passed the last number from the array. so [4,5,14,16,23,76,89] It is placing all of the missing numbers up to 88 when it should be going to 100 The solution should only return the missing numbers from 1-100. The original numbers from the given array should not be included in the return. How can I only return the missing numbers? ------------------------ public ArrayList<Integer> solution(ArrayList<Integer> nums) {ArrayList<Integer> result = new ArrayList<Integer>();int count =…arrow_forwardAdd a while loop to the BMI prcoedure below. def BMIImperial(height, weight, bmiList, Category): BMI = (weight * 703) / (height * height)print ("Your BMI is " + str(BMI))if (BMI <= bmiList[0]):print(BMI)print('you are:', Category[0])elif (BMI <= bmiList[1]):print('you are:', Category[1])elif (BMI <= bmiList[2]):print('you are:', Category[2])else:print('you are:', Category[3])arrow_forward
- Execute the following statements over initially empty ArrayList myList one after another (cascade). Explain what was changed after each statement (what did it do?) myList.add("z"); ArrayList content: Your explanation (where this output came from): myList.add(0, "a"); ArrayList content: Your explanation (where this output came from): myList.add("t"); ArrayList content: Your explanation (where this output came from): myList.add(2,"w"); ArrayList content: Your explanation (where this output came from): myList.set(0,"b"); ArrayList content: Your explanation (where this output came from):arrow_forwardof range. 3. Use the method swap that you wrote in Exercise 2 to write a method that reverses the order of the items in a list alist.arrow_forwardJava this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…arrow_forward
- Which of the following statements about ArrayLists is false? A running program can determine the size of an ArrayList. O You can get an item from a specified index in an ArrayList. O You can add a new item to the end of an ArrayList. O Once an ArrayList is created, its size cannot be changed.arrow_forwardin Java, please. Please add comments. Thank youarrow_forward4. Now examine the ArrayList methods in the above table, a) Which method retrieves elements from the ArrayList? b) Which method replaces the value of an element that already exists in the ArrayList? c) Which two methods initializes the value of an element? d) How do the two methods in (c) differ? Which method(s) would be appropriate in the above Java program (after we convert it to work with ArrayLists)?arrow_forward
- Create a class called StudentBirthYear. It should only have two members, both of them arrays. One of type string called Names. The second of type int called BirthYears. Now in your main class create a StudentBirthYear object. Make sure both arrays are of the size 13. Add thirteen different names and thirteen different birth years. Then display each name with its birth year using only 1 for loop. Only use a for loop, no other kind of loop.arrow_forward3.)Declare variables a. The images variable containing an HTML collection of all elements with the tag name "img". b. The photoBucket variable referencing the element with the id "photo_bucket". c. The photoList variable referencing the element with the id "photo_list". 4.) Create a for loop that iterates through all of the items in the images collection. 5.) Within the for loop insert an onclick event handler that runs an anonymous function when an image is clicked. 6.) When an image is clicked it is either moved from the photo bucket to the photo list or from the photo list back to the photo bucket. To determine which action to perform, add the following if else statement to the anonymous function: a. If the parent element of the clicked image has an id equal to "photo_bucket" then do the following: (i) Create an element node named newltem for the li element, (ii) append newltem to the photoList object, and (i) append the image to the newltem object using the appendChild() method.…arrow_forwardWhen I run this code it says there is an error. Can anyone help point out why I am getting an error for this code? from Artist import *from Artwork import *if __name__ == "__main__":mylist = input().split(" ")user_artist_name = str(mylist[0]+" "+mylist[1])user_birth_year = int(mylist[2])user_death_year = int(mylist[3])#mylist1 = mylist(4:-1)user_title = ""for i in mylist[4:-1]:user_title+=i+" "#user_title = str(mylist[4:-1])user_year_created = int(mylist[-1])user_artist = Artist(user_artist_name,user_birth_year,user_death_year)new_artwork = Artwork(user_title, user_year_created, user_artist)new_artwork.print_info() Here is the error message: Traceback (most recent call last): File "main.py", line 7, in <module> user_birth_year = int(mylist[2]) IndexError: list index out of rangearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY