Question: Due No Due Date Points 650 Submitting a file upload Please write the 'MAIN' for our Music/Song Test Java Code: The purpose of this lab
Due No Due Date
Points 650
Submitting a file upload
Please write the 'MAIN' for our Music/Song Test Java Code:
The purpose of this lab is to create a reusable class and a driver that will use the reusable class. Also, the instructor has provided a tester that you will use to test the class.
Although a main method could exist inside of the class you create, by having the main method in a second driver program, you are verifying that the IDE you are using allows multiple files for a program which will also be a requirement for later labs, starting with Programming Lab 3 (or 4).
The class described below could be written differently than described, but there are some aspects of Java that are being reviewed in this lab.
Song
Using the following UML for Song, write the Song class
| Song |
| -songTitle : String -artist : String -lengthInSeconds : int |
| +Song (initialSongTitle : String, initialArtist : String, initialLengthInSeconds : int) +getSongTitle ( ) : String +getArtist ( ) : String +getLengthInSeconds ( ) : int +setSongTitle (newSongTitle : String ) : void +setArtist ( initialArtist : String ) : void +setLengthInSeconds ( initialLengthInSeconds : int ) : void |
^^ note: because the instructor is providing a tester, make sure you use the same name for the class(Song), the same parameters for the constructor(3), and the methods are named the same and expect the same number/type of variables.
For this lab, your Song class does not need error checking. You can assume that the lengthInSeconds will be a positive int >= 1. And your driver can assume the user will enter a valid integer and it will be >= 1
Driver
Prompt the user for song title, artist, and length.
Instantiate a Song Object by passing the values entered by the user. Similar to:
Song mySong = new Song(songTitleEntered, artistEntered, lengthEntered);
Use the getters to display the values for Song, similar to:
System.out.println("Length(seconds): " + mySong.getLengthInSeconds());
Your driver will not use the setters, but the tester provided by the instructor tests the setters.
This is the test driver for Song class
package proglab01testsong; import javax.swing.JOptionPane;
public class ProgLab01TestSong {
public static void main(String[] args) { //declare/initialize variables //for debugging to display output boolean verbose = true; int passFailValue = 0; //initial values String initialSongName = "Life goes on"; String initialArtist = "The beetles"; int intitialLengthInSeconds = 18; //updated values String updatedSongName = "Ob-La-Di, Ob-La-Da"; String updatedArtist = "The Beetles"; int updatedLengthInSeconds = 165; //instantiate mySong object as instance of Song class Song mySong = new Song(initialSongName,intialArtist,initialLengthInSeconds); if(verbose) System.out.println("verbose mode "); if(verbose)//if debugging, print uding getters { System.out.println("verbose mode "); System.out.println("Artist: " + mySong.getArtist()); System.out.println("Length(seconds):" + mySong.getLengthInSeconds()); } } //test 1 if(verbose) System.out.print(" Instantiation/Getters = "); if (initialSongName.equals(mySong.getSongTitle()))&& initial Artist.equals(mySong.getArtist()) && initialLengthInSeconds == mySong.getLengthInSeconds()) { if(verbose) System.out.println("pass"); } else { passFailValue +=1; if(verbose) System.out.println("fail); } //update object mySong.setSongTitle(updatedSongName); mySong.setArtist(updatedArtist); mySong.setLengthInSeconds(updatedLengthInSeconds); if(verbose)// if debugging, print using getters static { System.out.println(" After update: Song: " + mySong.getSongTitle()); System.out.println("Artist:" + mySong.getArtist()); System.out.println("Length(seconds): " + mySong.getLengthInSeconds()); } } }
//test 2
if(verbose) System.out.print(" Setters/Getters = ")); if(updatedSongName.equals(mySong.getSongTitle()) && updatedArtist.equals(mySong.getArtist()) && updatedLengthInSeconds == mySong.getLengthInSeconds())
{
if(verbose) System.out.println("pass ");
}
else
{
passFailValue += 1; if(verbose) System.out.println("fail "); }
if(passFailValue == 0) System.out.println("Song class - all tests:pass");
else
System.out.println("Song class - tests: fail");
System.exit(passFailValue);
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
