So, when I tried to compile this code it had one error which I thought I found (a missing bracket) but now it shows I have 65 errors. Can you take a look and let me know if I have put things in the correct order or if my code is just incorrect? Here's the code: import java.util.*; class RecordSort extends Record { public static void main(String[]args) { Recording[]recordings = new Recording[5]; int x; String songTitle, artist, order, message = ""; int playTime; for(x=0;x0) { temp = array[b]; array[b] = array[b+1]; array[b+1] = temp; } } } public static void sortBySongTitle(Recording[] array) { int a, b; Recording temp; String stringB, stringBPlus; int highSubscript = array.length -1; for(a=0; a< highsubscript; ++a) for(b=0; b< highSubscript; ++b) { stringB = array[b].getSongTitle(); stringBPlus = array[b+1].getSongTitle(); if(stringB.compareTo(stringBPlus)>0) { temp = array[b]; int highSubscript = array.length -1; for(a=0; a < highSubscript; ++a) for(b=0; b < highSubscript; ++b) { stringB = array[b].getSongTitle(); stringBPlus = array[b+1].getSongTitle(); if(stringB.compareTo(stringBPlus)>0) { temp = array[b]; array[b] = array[b+1]; array[b+1] = temp; } } } public static void sortByTime(Recording[] array) { int a, b; Recording temp; int highSubscript = array.length -1; for(a=0; a < highsubscript; ++a) for(b=0; b < highSubscript; ++b) { if(array[b].getPlayTime().array[b+1].getPlayTime()) { temp = array[b]; array[b]= array[b+1]; array[b+1] = temp; } } } } ______________________ public class Record { private String songTitle; private String artist; private int playTime; public void setSongTitle(String title) { songTitle = title; } public void setArtist(String name) { artist = name; } public void setPlayTime(int time) { playTime = time; } public String getSongTitle() { return songTitle; } public String getArtist() { return artist; } public int getPlayTime() { return playTime; } }
So, when I tried to compile this code it had one error which I thought I found (a missing bracket) but now it shows I have 65 errors.
Can you take a look and let me know if I have put things in the correct order or if my code is just incorrect?
Here's the code:
import java.util.*;
class RecordSort extends Record
{
public static void main(String[]args)
{
Recording[]recordings = new Recording[5];
int x;
String songTitle, artist, order, message = "";
int playTime;
for(x=0;x<recordings.length;++x)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the song title: " + (x+1));
SongTitleEntry=input.nextLine();
}
System.out.print("Enter artist of the song: " +(x+1));
ArtistEntry=input.nextLine();
System.out.print("Enter the song playtime in seconds: " +(x+1));
PlayTimeEntry=input.nextInt();
time = Integer.parseInt(timeString);
Recording temp = new Recording();
temp.setArtist(name);
temp.setSongTitle(title);
temp.setPlayTime(time);
recordings[x] = temp;
}
Scanner input = new Scanner(System.in);
System.out.print("Which field should recordings be sorted by- \n" +
"(S)ong Title, (A)rtist, or (T)ime?");
if(order.charAt(0) == 'S')
sortBySongTitle(recordings);
else
if(order.charAt(0) == 'A')
sortByArtist(recordings);
else
sortByTime(recordings);
for(x = 0; x<recording.length; ++x)
System.out.println(message=message + "\nartist: " +recordings[x].getArtist() +
" song: " +recordings[x].getSongTitle() + " time: " + recordings[x].getPlayTime());
}
public static void sortByArtist(Recording[] array)
{
int a, b;
Recording temp;
String stringB, stringBPlus;
int highSubscript = array.length -1;
for(a=0; a < highSubscript; ++a)
for(b=0; b < highSubscript; ++b)
{
stringB = array[b].getArtist();
stringBPlus = array[b+1].getArtist();
if(stringB.compareTo(stringBPlus)>0)
{
temp = array[b];
array[b] = array[b+1];
array[b+1] = temp;
}
}
}
public static void sortBySongTitle(Recording[] array)
{
int a, b;
Recording temp;
String stringB, stringBPlus;
int highSubscript = array.length -1;
for(a=0; a< highsubscript; ++a)
for(b=0; b< highSubscript; ++b)
{
stringB = array[b].getSongTitle();
stringBPlus = array[b+1].getSongTitle();
if(stringB.compareTo(stringBPlus)>0)
{
temp = array[b];
int highSubscript = array.length -1;
for(a=0; a < highSubscript; ++a)
for(b=0; b < highSubscript; ++b)
{
stringB = array[b].getSongTitle();
stringBPlus = array[b+1].getSongTitle();
if(stringB.compareTo(stringBPlus)>0)
{
temp = array[b];
array[b] = array[b+1];
array[b+1] = temp;
}
}
}
public static void sortByTime(Recording[] array)
{
int a, b;
Recording temp;
int highSubscript = array.length -1;
for(a=0; a < highsubscript; ++a)
for(b=0; b < highSubscript; ++b)
{
if(array[b].getPlayTime().array[b+1].getPlayTime())
{
temp = array[b];
array[b]= array[b+1];
array[b+1] = temp;
}
}
}
}
______________________
public class Record
{
private String songTitle;
private String artist;
private int playTime;
public void setSongTitle(String title)
{
songTitle = title;
}
public void setArtist(String name)
{
artist = name;
}
public void setPlayTime(int time)
{
playTime = time;
}
public String getSongTitle()
{
return songTitle;
}
public String getArtist()
{
return artist;
}
public int getPlayTime()
{
return playTime;
}
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 5 images









