7 Replies - 1408 Views - Last Post: 19 March 2009 - 05:29 PM Rate Topic: -----

#1 Bredge   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Book list print

Posted 18 March 2009 - 04:23 PM

Basically I have to write a simple readingbook list. A reading list is a set of book titles that a course tutor recommends students on a course to read.

First thing I had to do was write a method to add a book to this list..Done

Then to print the list which Im stuck on .... Heres what I have

public void printBooks()
{	   
System.out.println(courseBooks);
	}


Supposed to print my list but doesn't
myReadingList.printBooks(myReadingList.getCourseBooks());




Keep getting the error message

Semantic error: Message printBooks( java.util.HashSet ) not understood by class'ReadingList'

This post has been edited by leegt5: 18 March 2009 - 05:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Book list print

#2 Bredge   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Re: Book list print

Posted 18 March 2009 - 04:51 PM

Solved it thanks
Was This Post Helpful? 0
  • +
  • -

#3 Bredge   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Re: Book list print

Posted 18 March 2009 - 05:19 PM

How would I print each element of the CourseBooks list on a new line. At the minute it prints to screen like so.

[Crypto, Using UML, Weaving the
Web, Prey]
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Book list print

Posted 18 March 2009 - 05:40 PM

You posted a question on Enigma machine without showing us the method that shuffles the message and you expected an answer.
Now you show us code for a println() that does not work and you dont tell us what courseBooks is ?
We can't do miracle.
"Mechanic please fix my car... but don't open the hood :) "
Was This Post Helpful? 0
  • +
  • -

#5 Bredge   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Re: Book list print

Posted 19 March 2009 - 01:26 PM

Sorry pbl, Im trying not to post too much of my work on the internet as Uni don't like it, well on their forums anyway...

/**
 * Print titles from courseBooks List
 */
public void printBooks(Collection aCol)
{
System.out.println(courseBooks);
} 
}

This post has been edited by leegt5: 19 March 2009 - 03:39 PM

Was This Post Helpful? 0
  • +
  • -

#6 BigAnt   User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 102
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Book list print

Posted 19 March 2009 - 02:34 PM

Quote

public void printBooks(Collection aCol)
{
System.out.println(courseBooks);
}


Do you want to print out the internal collection's or the one passed into the message?

To get each element on different line you will have to loop and print it out, as the default toString in JCF is to print the Collection like [ o1, o2, ...., on]

where on is the toString method on whatever is in the Collection
Was This Post Helpful? 0
  • +
  • -

#7 Bredge   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Re: Book list print

Posted 19 March 2009 - 03:31 PM

Solved it using

public void printBooks(Collection aCol)
{
for (Object ReadingList : courseBooks) 
	System.out.println(ReadingList);
}

This post has been edited by leegt5: 19 March 2009 - 03:38 PM

Was This Post Helpful? 0
  • +
  • -

#8 BigAnt   User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 102
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Book list print

Posted 19 March 2009 - 05:29 PM

Quote

public void printBooks(Collection aCol)
{
for (Object ReadingList : courseBooks)
System.out.println(ReadingList);
}



But why pass in the collection if you are using the internal collection to print out and never do anything with aCol
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1