Graderpractice for programmers

254275 OOP - Mini Test 2 (Sec 3 & 4)

Awaiting submission
Write a class named Album with fields for "title", "artist" and "songs".

Test code:

class Task1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String title = sc.nextLine();
        String artist = sc.nextLine();
        int songs = Integer.parseInt(sc.nextLine());

        Album a1 = new Album(title, artist, songs);
        System.out.println(a1.getTitle() + " by " + a1.getArtist() + " is " + a1.getSongs() + " songs");
    }
}
Awaiting submission
Add a new method to the Album named toString that returns title - artist.

Test code:

class Task2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String title = sc.nextLine();
        String artist = sc.nextLine();
        int songs = Integer.parseInt(sc.nextLine());

        Album album1 = new Album(title, artist, songs);
        System.out.println(album1.toString());
    }
}
Awaiting submission
An EP is a short album with less than 8 songs. Add a method named isEP that returns true if the album is an EP.

Test code:

class Task3 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String title = sc.nextLine();
        String artist = sc.nextLine();
        int songs = Integer.parseInt(sc.nextLine());

        Album album1 = new Album(title, artist, songs);
        if (album1.isEP()) {
            System.out.println(album1.getTitle() + " is short");
        } else {
            System.out.println(album1.getTitle() + " is normal");
        }
    }
}
Awaiting submission
A soundtrack is an album with music from a movie. Write a class named Soundtrack that is a subclass of Album with an extra field for "movie".

Test code:

class Task4 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String movie = sc.nextLine();
        int songs = Integer.parseInt(sc.nextLine());
        
        Album st1 = new Soundtrack(movie + " Soundtrack", "Various Artists", songs, movie);
        System.out.println(st1.toString());
    }
}
Awaiting submission
Add a method called getMovie() to the Soundtrack class.

Test code:

class Task5 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String movie = sc.nextLine();
        int songs = Integer.parseInt(sc.nextLine());

        Soundtrack st1 = new Soundtrack(movie + " Soundtrack", "Various Artists", songs, movie);
        System.out.print("There are " + st1.getSongs());
        System.out.println(" songs in the movie " + st1.getMovie());
    }
}