0

I've been working on this program recently and its been blowing up with errors, every time I work through a bug, more surface. Now I keep getting incompatible type errors at the spots I marked out. If someone could help me sort it out or point me in the right direction, that would be great. WARNING:HUGE AMOUNTS OF CODE TO FOLLOW.

import java.util.*;
public class SMOA {

    public static void main(String[] args) {
		System.out.println("Simple Music Organizer Application");
		System.out.println("1. Add Album");
		System.out.println("2. Remove Album");
		System.out.println("3. Display Albums");
		System.out.println("4. Number of Albums");
		AlbumCollection album = new AlbumCollection();
		Scanner keyboard = new Scanner(System.in);
		int userinput = keyboard.nextInt();
		switch(userinput){
			case 1: //add albums
				album.addAlbum();
				break;
			case 2: //remove albums
				album.removeAlbum();
				break;
			case 3: //display albums
				album.sorting(album);
				for(int i=0;i<album.length;i++){
					System.out.println(album[i]);
				}
				break;
			case 4: //number albums
				System.out.println(AlbumCollection.getAlbumNumber());
				break;
		} //end switch
    } //end main
} //end class
import java.io.*;
import java.util.*;
public class AlbumCollection{

	private int albumNum;
	private int count;
	private static MusicAlbum[] collection;
	private String artist;

    public AlbumCollection(String artist, String albumTitle, int releaseYr, String genre, int numberOfSongs, int songDuration, String fileName, String filePath) {
    	super();
    	count = 0;
    	this.artist = artist;
    }
    public void addAlbum(String artist, String albumTitle, int releaseYr, String genre, int numberOfSongs, int songDuration, String fileName, String filePath){
    	if(count == collection.length){
    		increaseSize();
    	}
    	Scanner keyboard = new Scanner(System.in);
    	System.out.println("Where is your data file?");
		String dataFilePath = keyboard.nextLine();
		FileInputStream in = new FileInputStream(dataFilePath);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		for(int i=0;i<collection.length;i++){
			collection[i] = br.readLine(); //incompatible types error
		}
    	count++;
    	in.close();
    }
    public static Comparable removeAlbum(Comparable[] data){
		Comparable[] result = null;
		int index = 0;
		System.out.println("Which album would you like to delete?");
		Scanner keyboard = new Scanner(System.in);
		String deleteTarget = keyboard.nextLine();
		while(index < data.length){
			if(data[index].compareTo(deleteTarget) == 0){
				result[index] = data[index];
			}
			index++;
		}
		System.out.println("Delete?");
		for(int i=0;i<result.length;i++){
			System.out.println(result[i]);
		}
		Comparable finalResult = null;
		int index2 = 0;
		while(finalResult == null && index2 < result.length){
			if(result[index2].compareTo(deleteTarget) > 0){
				result[index2] = "";
			}
			index2++;
		}
		System.out.println(deleteTarget + " has been removed.");
    }
    public static void sorting(Comparable[] data){
    	int min;
    	for(int i=0;i<data.length-1;i++){
    		min = i;
    		for(int s=i+1;s<data.length;s++){
    			if(data[i].compareTo(data[min]) < 0){
    				min = s;
    			}
    		}
    		swap(data,min,i);
    	}
    }
    private static void swap(Comparable[] data, int i1, int i2){
    	Comparable temp = data[i1];
    	data[i1] = data[i2];
    	data[i2] = temp;
    }
    private void increaseSize(){
    	Album[] temp1 = new Album[collection.length * 2];

    	for(int i = 0; i < collection.length; i++){
    		temp1[i] = collection[i]; //incompatible type error again!
    	}
    	collection = temp1; //incompatible type error!
    }
	public static int getAlbumNumber(){
		return collection.length;
	}
}
public class MusicAlbum {

	String albumtitle;
	String singer;
	int year;
	String genre;
	int number;
	String title;
	int duration;
	String name;
	String path;

    public MusicAlbum(String artist ,String albumTitle, int releaseYr, String genre, int numberOfSongs, String songTitle, int songDuration, String fileName, String filePath) {
    	albumtitle = albumTitle;
    	singer = artist;
    	year = releaseYr;
    	genre = genre;
    	number = numberOfSongs;
    	title = songTitle;
    	duration = songDuration;
    	name = fileName;
    	path = filePath;
    }

	public String toString(){
		String returntitle = "Album Title: " + albumtitle;
		return returntitle;
	}

}

Cheers,

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Slimmy
0

Line 25: collection is a MusicAlbum object that you are trying to assign a String (br.readLine() returns a String). You need to convert the String into a MusicAlbum object.

Line 77/79: Same thing here. You have temp1 set as a Album[] while collection is a MusicAlbum[].

Also, you might want to have a look at System.arraycopy if you are doing a lot of array manipulation. And you dont have to write your own sort method, look at Arrays.sort for that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.