Turn one of the Java projects into GUI, fully functioning. The program is finish
ID: 3806633 • Letter: T
Question
Turn one of the Java projects into GUI, fully functioning. The program is finished i just need it turned into a GUI.
package Midtermproject;
import java.util.ArrayList;
import java.util.Comparator;
public class Album implements Comparable<Album>, Comparator<Album>{
public String artistsName;
public String albumName;
ArrayList tracks = new ArrayList();
public Album(String artistName, String albumName, ArrayList tracks){
this.albumName = albumName;
this.artistsName = artistName;
this.tracks = tracks;
}
public Album(String artistname) {
this.artistsName = artistname;
}
Album() {
}
@Override
public String toString(){
String trckList="";
for (int x=0; x<this.tracks.size(); x++)
{
Track trc = (Track) tracks.get(x);
trckList +=trc.songName+" ";
}
String formated = this.artistsName+" "+this.albumName+" "+trckList;
return formated;
}
@Override
public boolean equals(Object x){
Album emp = (Album) x ;
return this.artistsName==emp.artistsName;
}
@Override
public int compareTo(Album o) {
return this.albumName.compareTo(o.albumName);
}
@Override
public int compare(Album o1, Album o2) {
if (o1.artistsName!=null && o2.artistsName!=null){
return o1.artistsName.compareToIgnoreCase(o2.artistsName);
}
else return 0;
}
}
package Midtermproject;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Catalog {
public static List getData(String filename) {
try (Scanner in = new Scanner(new File(filename))) {
List<Album> catalog = new ArrayList();
while (in.hasNextLine()) {
String line = in.nextLine();
String[] data = line.split(" ");
ArrayList trackList = new ArrayList();
for (int i = 2; i < data.length; i++) {
trackList.add(new Track(data[i]));
}
Album alb = new Album(data[0], data[1], trackList);
catalog.add(alb);
}
return catalog;
} catch (FileNotFoundException e) {
return null;
}
}
public static void main(String[] args) {
List listbyname = getData("catalog2.txt");
Collections.sort(listbyname);
for (Object objct : listbyname) {
Album ep = (Album) objct;
System.out.println("Album Name: " + ep.albumName + " Artist Name: " + ep.artistsName + " TRACKS:");
List trackList = ep.tracks;
Collections.sort(trackList);
for (Object trck : trackList) {
Track tr = (Track) trck;
System.out.print(tr.songName + ", ");
}
System.out.print(" ");
}
//Sort by artist name
System.out.print("*************************************************************************** ");
List listbyartist = getData("catalog2.txt");
Collections.sort(listbyartist, new Album());
for (Object objct : listbyartist) {
Album ep = (Album) objct;
System.out.println("Artist Name: " + ep.artistsName + " Album Name: " + ep.albumName + " TRACKS:");
List trackList = ep.tracks;
Collections.sort(trackList, new Track());
for (Object trck : trackList) {
Track tr = (Track) trck;
System.out.print(tr.songName + ", ");
}
System.out.print(" ");
}
System.out.print(" 1. Search by Album Title "
+ "2. Search by Artist "
+ "3. Add album to catalog "
+ "4. Quit ");
//get user input from the keyboard
int userInput;
String albumSearch, artistSearch;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a number: ");
userInput = keyboard.nextInt();
if (userInput == 1) {
System.out.println("Enter the album name: ");
Scanner keyboard2 = new Scanner(System.in);
albumSearch = keyboard2.nextLine();
int found = Collections.binarySearch(listbyname, new Album(albumSearch, albumSearch, null));
if (found > -1) {
System.out.println("Album found:");
Album sd = (Album) listbyname.get(found);
System.out.println(sd.albumName + " by " + sd.artistsName);
} else {
System.out.println("Album not found!");
}
}
if (userInput == 2) {
System.out.println("Enter the artist name: ");
Scanner keyboard2 = new Scanner(System.in);
artistSearch = keyboard2.nextLine();
int i, j = 0;
int found = Collections.binarySearch(listbyartist, new Album(artistSearch, artistSearch, null), new Album());
i = found;
j = found - 1;
while (j > 0) {
Album sd = (Album) listbyartist.get(j);
if (sd.artistsName.equals(artistSearch)) {
System.out.println(sd.albumName + " by " + sd.artistsName);
}
j -= 1;
}
while (i < listbyartist.size()) {
Album sd = (Album) listbyartist.get(i);
if (sd.artistsName.equals(artistSearch)) {
System.out.println(sd.albumName + " by " + sd.artistsName);
}
i += 1;
}
}
if (userInput == 3) {
System.out.println("Enter the Album name: ");
Scanner keyboard2 = new Scanner(System.in);
String AlbName = keyboard2.nextLine();
System.out.println("Enter the artist name: ");
String artistName = keyboard2.nextLine();
System.out.println("Enter the song names separated by spaces: ");
String trckName = keyboard2.nextLine();
System.out.println( "Enter catalog2.txt for the file input.");
String fileName = keyboard2.nextLine();
String line = artistName + " " + AlbName + " " + trckName;
ArrayList trackList = new ArrayList();
String[] data = line.split(" ");
for (int i = 0; i < data.length; i++) {
trackList.add(new Track(data[i]));
}
Album alb = new Album(artistName, AlbName, trackList);
listbyartist.add(alb);
try (FileWriter fw = new FileWriter(fileName, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
out.println(alb.toString());
} catch (IOException e) {
//exception handling
}
}
if (userInput == 4) {
System.exit(0);
}
}
}
package Midtermproject;
import java.util.Comparator;
public class Track implements Comparable<Track>, Comparator<Track>{
public String songName;
public Track(String sngName){
this.songName =sngName.toLowerCase();
}
Track() {
}
@Override
public int compareTo(Track o) {
return this.songName.compareTo(o.songName);
}
@Override
public int compare(Track o1, Track o2) {
if (o1.songName!= null && o2.songName!=null){
return o1.songName.compareToIgnoreCase(o2.songName);
}
return 0;
}
}
Explanation / Answer
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Catalog {
public static List getData(String filename) {
try (Scanner in = new Scanner(new File(filename))) {
List<Album> catalog = new ArrayList();
while (in.hasNextLine()) {
String line = in.nextLine();
String[] data = line.split(" ");
ArrayList trackList = new ArrayList();
for (int i = 2; i < data.length; i++) {
trackList.add(new Track(data[i]));
}
Album alb = new Album(data[0], data[1], trackList);
catalog.add(alb);
}
return catalog;
} catch (FileNotFoundException e) {
return null;
}
}
public static void main(String[] args) {
List listbyname = getData("catalog2.txt");
Collections.sort(listbyname);
for (Object objct : listbyname) {
Album ep = (Album) objct;
System.out.println("Album Name: " + ep.albumName + " Artist Name: " + ep.artistsName + " TRACKS:");
List trackList = ep.tracks;
Collections.sort(trackList);
for (Object trck : trackList) {
Track tr = (Track) trck;
System.out.print(tr.songName + ", ");
}
System.out.print(" ");
}
//Sort by artist name
System.out.print( );
List listbyartist = getData("catalog2.txt");
Collections.sort(listbyartist, new Album());
for (Object objct : listbyartist) {
Album ep = (Album) objct;
System.out.println("Artist Name: " + ep.artistsName + " Album Name: " + ep.albumName + " TRACKS:");
List trackList = ep.tracks;
Collections.sort(trackList, new Track());
for (Object trck : trackList) {
Track tr = (Track) trck;
System.out.print(tr.songName + ", ");
}
System.out.print(" ");
}
System.out.print(" 1. Search by Album Title "
+ "2. Search by Artist "
+ "3. Add album to catalog "
+ "4. Quit ");
//get user input from the keyboard
int userInput;
String albumSearch, artistSearch;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a number: ");
userInput = keyboard.nextInt();
if (userInput == 1) {
System.out.println("Enter the album name: ");
Scanner keyboard2 = new Scanner(System.in);
albumSearch = keyboard2.nextLine();
int found = Collections.binarySearch(listbyname, new Album(albumSearch, albumSearch, null));
if (found > -1) {
System.out.println("Album found:");
Album sd = (Album) listbyname.get(found);
System.out.println(sd.albumName + " by " + sd.artistsName);
} else {
System.out.println("Album not found!");
}
}
if (userInput == 2) {
System.out.println("Enter the artist name: ");
Scanner keyboard2 = new Scanner(System.in);
artistSearch = keyboard2.nextLine();
int i, j = 0;
int found = Collections.binarySearch(listbyartist, new Album(artistSearch, artistSearch, null), new Album());
i = found;
j = found - 1;
while (j > 0) {
Album sd = (Album) listbyartist.get(j);
if (sd.artistsName.equals(artistSearch)) {
System.out.println(sd.albumName + " by " + sd.artistsName);
}
j -= 1;
}
while (i < listbyartist.size()) {
Album sd = (Album) listbyartist.get(i);
if (sd.artistsName.equals(artistSearch)) {
System.out.println(sd.albumName + " by " + sd.artistsName);
}
i += 1;
}
}
if (userInput == 3) {
System.out.println("Enter the Album name: ");
Scanner keyboard2 = new Scanner(System.in);
String AlbName = keyboard2.nextLine();
System.out.println("Enter the artist name: ");
String artistName = keyboard2.nextLine();
System.out.println("Enter the song names separated by spaces: ");
String trckName = keyboard2.nextLine();
System.out.println( "Enter catalog2.txt for the file input.");
String fileName = keyboard2.nextLine();
String line = artistName + " " + AlbName + " " + trckName;
ArrayList trackList = new ArrayList();
String[] data = line.split(" ");
for (int i = 0; i < data.length; i++) {
trackList.add(new Track(data[i]));
}
Album alb = new Album(artistName, AlbName, trackList);
listbyartist.add(alb);
try (FileWriter fw = new FileWriter(fileName, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
out.println(alb.toString());
} catch (IOException e) {
//exception handling
}
}
if (userInput == 4) {
System.exit(0);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.