Hi all,

Im fairly new to java and any assistance would be appreciated.

The following should output string values, but if i use text within the creation of the new CD object i get an error, unless i change the content to numbers.

I know the driver class is fine, and i know the variables in the CD class are currently as INT, but if i change them to String it wont compile.

I know its something stupid i have dont/not done/missed.

class CDDriver
{
	public static void main(String args[])
	{
                CD cd1 = new CD(1,8,9);
		CD cd2 = new CD(1,2,3);
		CD cd3 = new CD(4,5,6);

		System.out.println("Artist \t\tTitle\t\tCost");
		System.out.println("====================================");
		System.out.println(cd1.toString());
		System.out.println(cd2.toString());
		System.out.println(cd3.toString());
	}
}
public class CD {

     int Artist;
     int Title;
     double Cost;


     public CD(){
    	Cost = 0;
    	Artist = 0;
        Title = 0;
    }

     public CD(int Artist, int Title, double Cost)
    {
    	this.Artist = Artist;
    	this.Title = Title;
    	this.Cost = Cost;
    }

    
    public String toString()
    {
    	return "CD details: " + Title +" By: " + Artist + "Price:" + Cost;
    }
}

ive found the issue. Id used CD ttwice.

tested and works.

thanks for loooking

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.