Question: n this part, you will use BlueJ to create an executable jar from one of your past labs, and run the jar at the command

n this part, you will use BlueJ to create an executable jar from one of your past labs, and run the jar at the command line.

If you haven't already, watch the Executable Jar Video. Pick one of your past projects from this class and complete the steps below. (Do not use the ticket-machine project shown in the video.)

  • Add a Main class with a main method. In the main method, create objects and call methods on the objects to demonstrate their behavior. Be sure to print something or include methods that print something.
    • For example, if you are using the Lab 9 Histogram Project, you could create a display object and call the displayData method to print the histogram.
    • If you are using the Lab 8 Playlist project, you could create a Playlist object and call printPlaylist and/or printPlaylistSummaryStats.
  • Use BlueJ to create an executable jar from your project.
  • Run your program at the command line using the executable jar. Take a screenshot of the terminal window showing the command you used and the output.

Code from my previous lab:

/** * * Song Project Part 2 * * *Modifications: * Changed rating = songRating; to setRating(songRating); * Added code so every that it knows every 60 seconds is one minute and shows this when telling song lenth. * Added an if statement that says if song rating is 0 then it is unrated instead of having a 0 rating * Added an if statment that says if the rating is not between 1-4, to show an error message. * Added an if statment that says if rating is between 1-3 and increace rating is called, it will add 1 to the rating. If the rating is already at 4, it does nothing * Added an if statement that says if rating is between 2-4 and decrence rating is called, it will lower by one. If already at 1, nothing happens * Changed print statements so that the length prints in minutes,seconds and prints not rated if the song has a rating of 0 * @author Cara Tang, Tom Durkin * @version 2021.01.28 * */ public class Song { private String title; private String artist; private int lengthInSeconds; private int rating; // valid ratings are 1-4 or 0 meaning not rated

/** * Create a song with the given title, artist, length, and rating * * @param songTitle the song title * @param songArtist the song artist * @param songLength the length of the song in seconds * @param songRating the song's rating */ public Song(String songTitle, String songArtist, int songLength, int songRating) { title = songTitle; artist = songArtist; lengthInSeconds = songLength; setRating(songRating); // Question: Why do you think we want to replace the assignment statement with a // call to setRating? // Your Answer: Because in case of rating their is condition that rating must be // in range 1 to 4 to check this we use setRating method }

/** * Create an unrated song with the given title, artist, and length * * @param songTitle the song title * @param songArtist the song artist * @param songLength the length of the song in seconds */ public Song(String songTitle, String songArtist, int songLength) { title = songTitle; artist = songArtist; lengthInSeconds = songLength; rating = 0; }

/** * @return the song title */ public String getTitle() { return title; }

/** * @return the song artist */ public String getArtist() { return artist; }

/** * @return the song length (in seconds) */ public int getLengthInSeconds() { return lengthInSeconds; }

/** * @return a string giving the song length in minutes (m) and seconds (s). * Example: If lengthInSeconds is 150, the string returned is "2m 30s" */ public String getLengthAsString() { int duration = getLengthInSeconds(); int minutes = duration / 60; int sec = duration % 60; String ret = minutes + "m " + sec + "s"; return ret; }

/** * Set the length of this song to the value given. The length must be greater * than 0. * * @param newLength new length (in seconds) for this song */ public void setLengthInSeconds(int newLength) { if (newLength > 0) { lengthInSeconds = newLength; } else { System.out.println("Error: Length must be greater than 0"); } }

/** * @return true if this song has not been rated, false otherwise */ public boolean isUnrated() { if (getRating() == 0) { return true; } return false; }

/** * @return the song rating */ public int getRating() { return rating; }

/** * Update this song's rating to the one given * * @param newRating new rating for this song */ public void setRating(int newRating) { if (newRating < 1 || newRating > 4) { System.out.println("Invalid rationg ... Valid range of rating is 1 - 4"); return; } rating = newRating; }

/** * Reset the rating of this song to not rated */ public void resetRating() { rating = 0; }

/** * Increase the rating of this song by 1 */ public void increaseRating() { if (getRating() == 4) { return; } rating = rating + 1; }

/** * Decrease the rating of this song by 1 */ public void decreaseRating() { if (getRating() == 1 || getRating() == 0) { return; }

rating = rating - 1; }

/** * Print information on this song */ public void printSongInfo() { System.out.println("---------------------------------"); System.out.println("Song Title: " + title); System.out.println("Artist: " + artist); System.out.println("Length: " + getLengthAsString()); if (isUnrated()) { System.out.println("Rating: not rated");

} else { System.out.println("Rating: " + rating); } System.out.println("---------------------------------"); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!