Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We have written the following StarWars Movies class below, and we want to be able to iterate over the movies using a for-each loop. However,
We have written the following StarWars Movies class below, and we want to be able to iterate over the movies using a for-each loop. However, our code doesn't work, and we have no idea why. TASK: Fix the bug(s) in our code. EXAMPLE: After running the following lines of code: StarWarsMovies movies = new StarWarsMovies(): for(String m: movies) { System.out.println(m): We will print the following: A New Hope The Empire Strikes Back Return of the Jedi The Phantom Menace Attack of the Clones Revenge of the Sith The Force Awakens The Last Jedi The Rise of Skywalker HINT: We asked a tutor for help by submitting a ticket to the lab queue, and the tutor suggested we look into how to properly implement the Iterable interface. Tutors are so helpful and kind Write a program, test using stdin stdout Time limit: 8 seconds Memory limit: 256 MB 1 class Star WarsMovies { final private ArrayList movies; public Star Wars Movies() { this.movies = new ArrayList(); this.movies.add("A New Hope"); this.movies.add("The Empire Strikes Back"); this.movies.add("Return of the Jedi"); this.movies.add("The Phantom Menace"); this.movies.add("Attack of the Clones"); this.movies.add("Revenge of the Sith"); this.movies.add("The Force Awakens"); this.movies.add("The Last Jedi"); this.movies.add("The Rise of Skywalker")
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