How do I create a method header that takes a string as an argument and returns the characters in the argument as a set. Please only reply if you know the answer. Thanks.

public class Food
{
  private TreeSet<String> myList = new TreeSet<String>();  

  public Food()
   {
     super();
     myList = new TreeSet<String>();
   }

  public String shoppingList(String aFood)
  {
     return //   
  }
}

Recommended Answers

Forum rules say I can't write your code for you, but here are some hints:
the method header says you will return an object of type Set
So somewhere in your method you need to declare one, populate it with zero or more Food objects, then return it in the …

Jump to Post

All 4 Replies

Thank you JamesCherrill - Where do I put this. I have done this so far

public Set<Food> toLetterSet(String aFood)
 {
   return;  // error message is missing return value tried to put arg but got further error msg? 
 }

Forum rules say I can't write your code for you, but here are some hints:
the method header says you will return an object of type Set<Food>
So somewhere in your method you need to declare one, populate it with zero or more Food objects, then return it in the return staement.
I have no idea how we got from characters to Food - what's your REAL question?

appericate your time, thanks.

Be a part of the DaniWeb community

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