First, launch NetBeans and close any previous projects that may be open (at the
ID: 3914684 • Letter: F
Question
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
Then create a new Java application called "StringSlicer" (without the quotation marks) that uses methods to:
Create a comma separated list of your own 10 favorite movies (i.e. "Rushmore,Mall Rats,Gangs of New York" etc.)
Populate an ArrayList of String data, with each movie in the String represented as a separate String element in the ArrayList
Output each Movie to the command line, each on a separate line
*** You must use an ArrayList and methods from Lesson 23 working with Array Lists
*** You must use your own list of movies
*** You must have comments in your code
*** You must have proper indenting in your code
*** Your code must run
Explanation / Answer
Java code:
import java.util.Arrays;
import java.util.List;
//class StringSlicer STARTS
public class StringSlicer
{
//main method or driver method
static public void main(String...s)
{
//Creating comma separated list of 10 fav movies
List<String> movies=Arrays.asList("Rushmore","Mall Rats","Titanic","The Room",
"The Shape of water","Dankirk","The king's speech",
"Avthar","Lord of rings","King kong");
//Populate an ArrayList of String data, with each movie
for(int i=0;i<movies.size();i++)
{
//Output each Movie to the command line, each on a separate line
System.out.println(movies.get(i));
}
//you could use this as well-for each loop
for(String name:movies)
{
//Output each Movie to the command line, each on a separate line
System.out.println(name);
}
}
}
//class StringSlicer ENDS
Output:
Rushmore
Mall Rats
Titanic
The Room
The Shape of water
Dankirk
The king's speech
Avthar
Lord of rings
King kong
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.