0% found this document useful (0 votes)
9 views2 pages

Exercise ArrayList - Movie

Uploaded by

ameeraroslan550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Exercise ArrayList - Movie

Uploaded by

ameeraroslan550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LAB EXERCISE: ARRAY LIST

1. Copy the following files from the attachment:


a) Movie.java
b) MovieApp.java
c) movieList.txt
2. Complete the main() method in MovieApp.java application class to do the following tasks:
a) Read the records from movieList.txt text file (as in Table 1). For each record retrieved from
movieList.txt, instantiate object of the Movie class to store the record. Note that each record
consists of two data values for the attributes which are ‘movie title’ and ‘year published’.
b) For each instance of Movie, store it into a sequential list (ArrayList) named movieList.
c) Display all the movie data from the list (as in Table 2).
d) By utilizing the Bubble Sort algorithm, sort the list of movies in ascending order according to
the ‘year published’.
e) Display all the movie data from the sorted list (as in Table 3).
f) Search movie named ‘Adik Manja’ from the list.
If the record exists, return the index and display the following:
“The movie Adik Manja is in the list at index 0”.
Otherwise display the following:
“The movie Adik Manja is not in the list”.

P.S. You should not change or add anything on the definition of Movie ADT. The definition of the ADT
is enough and perfect for you to work on the application class. Good luck and mind your time!

Table 1: movieList.txt
Lagi-Lagi Senario;2001
Sembilu 2;1995
Adik Manja;1980
KL Gangster;2011
Munafik 2;2018
Pemburu Bayang;1993
The Journey;2014
Maria Mariana;1996
Polis EVO;2015
Abang Long Fadil 2;2017

Table 2: List of Movie in Original Position in ArrayList


List of Movies (10 record(s))
#1: Lagi-Lagi Senario, 2001
#2: Sembilu 2, 1995
#3: Adik Manja, 1980
#4: KL Gangster, 2011
#5: Munafik 2, 2018
#6: Pemburu Bayang, 1993
#7: The Journey, 2014
#8: Maria Mariana, 1996
#9: Polis EVO, 2015
#10: Abang Long Fadil 2, 2017
Table 3: List of Movie After Sorted by Year
Sort in ascending order by year
List of Movies (10 record(s))
#1: Adik Manja, 1980
#2: Pemburu Bayang, 1993
#3: Sembilu 2, 1995
#4: Maria Mariana, 1996
#5: Lagi-Lagi Senario, 2001
#6: KL Gangster, 2011
#7: The Journey, 2014
#8: Polis EVO, 2015
#9: Abang Long Fadil 2, 2017
#10: Munafik 2, 2018

Search for Adik Manja


The movie Adik Manja is in the list at index 0

Table 4: MovieApp.java
/***==================================================
Application Class
==================================================***/
import java.util.Scanner;
import java.io.*;

public class MovieApp {


public static void main(String[] args) throws Exception {

/***
You are to write the solutions for Question 2(a), 2(b), 2(c),
2(d), 2(e) and 2(f) here!
***/

}/***End of main() Method***/


}/***End of Application Class***/

/***==================================================
Definition of Movie Class
==================================================***/
public class Movie{
private String title;
private int year;

public Movie(String title, int year) {


this.title = title;
this.year = year;
}

public String getTitle() { return this.title;}


public int getYear() { return this.year;}

public String toString() {


return this.getTitle() + ", " + this.getYear();
}
} /***End of Movie Class Definition***/

You might also like