Write a Java application CountryList. In the main method, do the following: 1. Create an array list of Strings called countries. 2. Add "Canada", "India", "Mexico", "Peru" in that order. 3. Use the enhanced for loop to print all countries in the array list, one per line. 4. Add "Spain" at index 1 5. Replace the element at index 2 with "Vietnam". You must use the set method. 6. Replace the next to the last element with "Brazil". You must use the set method. You lose one point if you use 3 in the set method. Do this in a manner that would replace next to the last element, no matter the size of the array list. 7. Remove the object "Canada" Do not remove at an index. Your code should work if "Canada" was at a different location. There is a version of remove method that will

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
Important: not using an array list • not using an enhanced for loop • using index to remove “Canada” RUN OUT LIKE THE EXPECTED PICTURE
Problem B
Write a Java application CountryList. In the main method, do the following:
1. Create an array list of Strings called countries.
2. Add "Canada", "India", "Mexico", "Peru" in that order.
3. Use the enhanced for loop to print all countries in the array list, one per line.
4. Add "Spain" at index 1
5. Replace the element at index 2 with "Vietnam". You must use the set method.
6. Replace the next to the last element with "Brazil". You must use the set method. You will
lose one point if you use 3 in the set method. Do this in a manner that would replace the
next to the last element, no matter the size of the
7. Remove the object "Canada" Do not remove at an index. Your code should work if
"Canada" was at a different location. There is a version of remove method that will
array list.
remove a specific object.
8. Get and print the first element followed by "****
9. Call method toString() on countries to print all elements on one line.
10. Use the enhanced for loop to print all countries in the array list, one per line.
Note: You must use an array list and its methods. Do not fake it by just printing the correct
strings.
Transcribed Image Text:Problem B Write a Java application CountryList. In the main method, do the following: 1. Create an array list of Strings called countries. 2. Add "Canada", "India", "Mexico", "Peru" in that order. 3. Use the enhanced for loop to print all countries in the array list, one per line. 4. Add "Spain" at index 1 5. Replace the element at index 2 with "Vietnam". You must use the set method. 6. Replace the next to the last element with "Brazil". You must use the set method. You will lose one point if you use 3 in the set method. Do this in a manner that would replace the next to the last element, no matter the size of the 7. Remove the object "Canada" Do not remove at an index. Your code should work if "Canada" was at a different location. There is a version of remove method that will array list. remove a specific object. 8. Get and print the first element followed by "**** 9. Call method toString() on countries to print all elements on one line. 10. Use the enhanced for loop to print all countries in the array list, one per line. Note: You must use an array list and its methods. Do not fake it by just printing the correct strings.
9 }
deCheck
Reset
Download
ng CountryList.java
al
Expected
da Canada
La India
-со Мехico
Peru
Spain l*
[Spain, Vietnam, Brazil, Peru]
Spain
Vietnam
Brazil
Peru
re
1
Transcribed Image Text:9 } deCheck Reset Download ng CountryList.java al Expected da Canada La India -со Мехico Peru Spain l* [Spain, Vietnam, Brazil, Peru] Spain Vietnam Brazil Peru re 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT