Question: *NEED HELP MAKING CHANGES TO JAVA CODE* SongUpgrade.java public class SongUpgrade { private String title; private int lengthInSeconds; public SongUpgrade(String title, int lengthInSeconds) { this.title
*NEED HELP MAKING CHANGES TO JAVA CODE*
SongUpgrade.java
public class SongUpgrade {
private String title;
private int lengthInSeconds;
public SongUpgrade(String title, int lengthInSeconds) {
this.title = title;
this.lengthInSeconds = lengthInSeconds;
}
public int getLengthInSeconds() {
return this.lengthInSeconds;
}
public String toString() {
return "SongUpgrade " +
"title=''" + title + '\'' +
", lengthInSeconds='" + lengthInSeconds + '\'' +
'}';
}// end string
}// end class
SmartPhone.java //SmartPhone Class:
public class SmartPhone {
private String brand;
private String capacity;
private SongUpgrade[] songLibrary;
public SmartPhone(String brand, String capacity) {
this.brand = brand;
this.capacity = capacity;
this.songLibrary = new SongUpgrade[4];
songLibrary[0] = new SongUpgrade("Song 1", 90);
songLibrary[1] = new SongUpgrade("Song 2", 60);
songLibrary[2] = new SongUpgrade("Song 3", 70);
songLibrary[3] = new SongUpgrade("Song 4", 85);
}// smartphone
public boolean totalPlayTime() {
int total = 0;
for (SongUpgrade song : songLibrary) {
total = total + song.getLengthInSeconds();
} // end for return true; }
void deleteAllSongs() {
this.songLibrary[0] = null;
this.songLibrary[1] = null;
this.songLibrary[2] = null;
this.songLibrary[3] = null;
}// end deleteAllSongs
public String toString() {
SongUpgrade song1 = this.songLibrary[0];
SongUpgrade song2 = this.songLibrary[1];
SongUpgrade song3 = this.songLibrary[2];
SongUpgrade song4 = this.songLibrary[3];
String stringData = "SmartPhone " + " Brand= " + brand;
stringData = stringData + ", Memory Capacity In GB= " + capacity;
stringData = stringData + ", Song Library= "; stringData = stringData + '{'; if (song1 != null) { stringData = stringData + " Song 1=" + song1.toString(); } if (song2 != null) { stringData = stringData + " Song 2=" + song2.toString(); } if (song3 != null) { stringData = stringData + " Song 3=" + song3.toString(); } if (song4 != null) { stringData = stringData + " Song 4=" + song4.toString(); }
stringData = stringData + "}";
return stringData;
}// end toString }// end class
Main.java //Driver Class:
public class Main {
public static void main(String[] args) {
SmartPhone phone = new SmartPhone("Sample", "40GB");
System.out.println("Total Playtime:" + phone.totalPlayTime());
System.out.println("To String Method: "+phone.toString());
System.out.println("To String Method after deleteALLSongs Method Invoked: ");
phone.deleteAllSongs();
System.out.println(phone.toString());
}// end class
}// end main
SongUpgrade.java
public class SongUpgrade {
private String title;
private int lengthInSeconds;
public SongUpgrade() {
}
public int totalPlayTime() {
return 1;
}
public SongUpgrade(String title, int lengthInSeconds) {
this.title = title;
this.lengthInSeconds = lengthInSeconds;
}
public int getLengthInSeconds() {
return this.lengthInSeconds;
}
public String toString() { { return "SongUpgrade " +
"title=''" + title + '\'' +
", lengthInSeconds='" + lengthInSeconds + '\'' +
'}'; }
}// end string
}// end class
SmartPhone.java
import java.util.Arrays;
public class SmartPhone {
private String brand;
private int capacity;
private SongUpgrade[] songLibrary;
//two-args constructor
public SmartPhone(String brand, int capacity) {
this.brand = brand;
this.capacity = capacity;
// add songs
//creates 4 different objects of SongUpgrade class.
SongUpgrade song1 = new SongUpgrade();
SongUpgrade song2 = new SongUpgrade();
SongUpgrade song3 = new SongUpgrade();
SongUpgrade song4 = new SongUpgrade();
// add these four objects into songLibrary array
songLibrary = new SongUpgrade[4];
songLibrary[0] = song1;
songLibrary[1] = song2;
songLibrary[2] = song3;
songLibrary[3] = song4;
}
// this is a method-- it will delete all songs from the songLibrary (line 24-28) public void deleteAllSongs() {
// iterate over songLibrary
for (int i = 0; i
// set songLibrary data to null.
songLibrary[i] = null;
} // end for
}// end deleteAllSongs
/* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "SmartPhone [brand=" + brand + ", capacity=" + capacity + ", songLibrary=" + Arrays.toString(songLibrary) + "]"; }
}
Main.java
//Driver Class: public class Main {
public static void main(String[] args) {
SmartPhone phone = new SmartPhone("Sample", 40); SongUpgrade songUpgrade=new SongUpgrade("Song 1",100);
System.out.println("Total Playtime:" + songUpgrade.totalPlayTime());
System.out.println("To String Method: "+phone.toString());
System.out.println("To String Method after deleteALLSongs Method Invoked: ");
phone.deleteAllSongs();
System.out.println(phone.toString());
}// end class
}// end main

Upgrade the Smart Phone to a Smart Phone2 to use an ArrayList instead of an array. Complete the following to complete the upgrade: a. Modify the two-argument constructor to create and populate the ArrayList songLibrary. b. Modify the totalPlayTime() method so that the method works correctly with the ArrayList songLibrary. c. Modify the deleteAllSongs() method so that the length of the ArrayList songLibrary is 0 after all the songs have been removed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
