Question
Create an interface called edu.udc.cs2.Song. Song must have 2 methods defined like: public String getSongName(); public int getSeconds(); //returns the number of SECONDS the song
Create an interface called edu.udc.cs2.Song. Song must have 2 methods defined like:
public String getSongName();
public int getSeconds(); //returns the number of SECONDS the song lasts
Create a class named edu.udc.cs2.Md. Create the following method:
in java
public static void showSong(List
The method must iterate the passed in List of Song and will output according to the following:
If the song is outside of the range of 2 seconds and 20 minutes, inclusive, throw a RuntimeException at which point the program will automatically end unless you include a try catch in your call.
If the getSeconds() method returns the number of seconds for at least 5 minutes, output:
song name is a long song.
if less than 5 minutes, output:
song name is a short song.
Where song name is the name returned from getSongName() method.
Turn in TWO classes Song.java and Md.java.
Extra Credit
Create a class named edu.udc.cs2.Tune that will implement Song. You must be able to only instantiate as below:
Song s1 = new Tune("What You Did", 300);
Hopefully, you can figure out that in the example "What You Did" is the name of the Song and 300 is the number of seconds. These values must be properly returned from the interface methods.
Create a main method in the Md class and do the following in that main:
Create a List
Properly call the showSong method created above to test your code, passing the List above into the method.
Wrap the call in a try/catch block to output "Invalid song" if an exception is thrown.
Include Tune.java in your submission for a total of 3 files submitted.
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