Question

(1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2)...

(1) Create two files to submit:

  • Song.java - Class definition
  • MainClass.java - Contains main() method

(2) Build the Song class in Song.java with the following specifications:

  • Private fields

    String songTitle

    String songArtist

    int secDuration

  • Initialize String fields to "Not defined" and numeric to 0.

  • Create overloaded constructor to allow passing of 1 argument (title), 2 (title, artist) and 3 arguments (title, artist, duration).

  • Create public member method printSongInfo () with output formatted as below:

    Title: Born in the USA

    Artist: Bruce Springsteen

    Duration: 300 sec

(3) In MainClass.java create main() and program logic as below:

  • Declare an ArrayList (e.g. Playlist) whose elements are objects of class Song

  • Create 5 objects of class Song using overloaded constructor, as below:

    Song 1: pass only title "Hey Jude"

    Song 2: pass title and artist: "Jumping Jack Flash" and "Rolling Stones"

    Song 3,4 and 5: pass title, artist and duration:

    "Before I cry", "Lady Gaga", 300

    "Only the lonely", "Roy Orbison", 180

    ""Born in the USA" , "Bruce Springsteen", 300

  • Add 5 songs to the list, as below (using ArrayList methods):

  • Print the contests of the ArrayList (Playlist). Use printSongInfo () extractor method in a loop.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class MainClass { ULUI // Song class 7e static class Song { private String songTitle; private String songArtist; priva

import java.util.ArrayList;

class Song {
        private String songTitle;
        private String songArtist;
        private int secDuration;

        public Song(String songTitle, String songArtist, int secDuration) {
                this.songTitle = songTitle;
                this.songArtist = songArtist;
                this.secDuration = secDuration;
        }

        public Song(String songTitle) {
                this(songTitle, "Not defined", 0);
        }

        public Song(String songTitle, String songArtist) {
                this(songTitle, songArtist, 0);
        }
        
        public void printSongInfo () {
                System.out.println("Title: " +songTitle);
                System.out.println("Artist: " +songArtist);
                System.out.println("Duration: " +secDuration + " sec");
        }
}

public class MainClass {

        public static void main(String[] args) {
                
                ArrayList<Song> playlist = new ArrayList<>();
                playlist.add(new Song("Hey jude"));
                playlist.add(new Song("Jumping Jack Flash", "Rolling Stones"));
                playlist.add(new Song("Before I cry", "Lady Gaga", 300));
                playlist.add(new Song("Only the lonely", "Roy Orbison", 180));
                playlist.add(new Song("Born in the USA", "Bruce Springsteen", 300));
                
                for(Song s: playlist) {
                        s.printSongInfo();
                }
        }

}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
(1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • Create two classes. Song. Should include the name of the song and the artist Playlist. Should...

    Create two classes. Song. Should include the name of the song and the artist Playlist. Should include a list of song objects from the above class, a title for the list and a description of the list. Specific method requirements below. Functionality You should be able to print both a song and a playlist. Formatting should follow the below examples EXACTLY. I should be able to print a so11ng or a playlist by calling the standard python print function. Format...

  • Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...

    Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...

  • I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...

    I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...

  • JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the...

    JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...

  • Look at this partial class definition, and then answer questions a - b below: Class Book...

    Look at this partial class definition, and then answer questions a - b below: Class Book    Private String title    Private String author    Private String publisher    Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant    Public Module message()       Display "I'm a plant."    End Module...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • You will be building a linked list. Make sure to keep track of both the head and tail nodes.

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

  • public class Song { private String title; private String artist; private int duration; public Song() {...

    public class Song { private String title; private String artist; private int duration; public Song() { this("", "", 0, 0); } public Song(String t, String a, int m, int s) { title = t; artist = a; duration = m * 60 + s; } public String getTitle() { return title; } public String getArtist() { return artist; } public int getDuration() { return duration; } public int getMinutes() { return duration / 60; } public int getSeconds() { return...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT