Question
JUnit Testing an ArrayList [STEP 6 ] PLEASE ONLY DO STEP 6 THE REST OF THE CODE IS FINISHED! Please i've been working on this
JUnit Testing an ArrayList [STEP 6]
PLEASE ONLY DO STEP 6 THE REST OF THE CODE IS FINISHED!
Please i've been working on this for hours. It simply will not work. I do not know what to do.
All the code below:
CompactDiskDemo.java (main method)
package mru.lab3.application;
import mru.lab3.controller.CompactDisk;
public class CompactDiskDemo {
public static void main(String[] args) throws Exception { //Task #5 - Create an object from CompactDisk class CompactDisk obj = new CompactDisk(); } }
CompactDisk.java
package mru.lab3.controller;
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList;
import mru.lab3.model.Song; import mru.lab3.view.AppMenu;
/** * This program creates a list of songs for a CD by reading from a file. */
public class CompactDisk { AppMenu appMen = new AppMenu(); // Declaring an arrayList of Song objects, called cd, ArrayList
public CompactDisk() throws Exception { // Task #3 instantiate (new ...) the arrayList here cd = new ArrayList
private void loadSongs() throws IOException {
FileReader file = new FileReader("res/Classics.txt"); BufferedReader input = new BufferedReader(file);
String line; String[] currentSong;
// BufferReader is another package that you use to read a file it is faster than previous method! while ((line = input.readLine())!= null) { currentSong = line.trim().split(",");
// ADD LINES FOR TASK #3 HERE // Fill the arraylist by creating a new song object with // the title and artist Song song = new Song(currentSong[0], currentSong[1]); cd.add(song); } // Calling printContents methods from AppMenu to print out the song on the console appMen.printContents(cd);
} }
Song.java (create the test using this class!!!)
package mru.lab3.model;
/* This class stores data about a song. */
public class Song { private String title; // The song's title private String artist; // The song's artist
/** * Constructor * * @param title A reference to a String object containing the song's title. * @param artist A reference to a String object containing the song's artist. */
public Song(String title, String artist) { this.title = title; this.artist = artist; } // Task #2 - add setter and getters for title and artist here public String getArtist() { return artist; } public String getTitle() { return title; } public void setArtist(String a) { artist = a; } public void setTitle(String t) { this.title = t; } /** * The toString method * * @return A String object containing the name of the song and the artist. */
public String toString() { return title + " by " + artist + " "; } }
appmenu.java
package mru.lab3.view;
import java.util.ArrayList;
import mru.lab3.model.Song;
public class AppMenu { public void printContents(ArrayList } } } TestSong.java package mru.lab3.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import mru.lab3.model.Song; class TestSong { // Task #5 Write 3 tests here! @Test void test() { } }
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