0

I want to write the method listCopies() that returns in an ArrayList all copies of a written work in a given language(eg : english); if no language is given (empty string), all copies of the library will be returned (in all languages) . This is the code i have developed but it doesnt work cause in the main(String[] args) {...} it calls 2 times this method , one with the argument passed and in the second without an argument :

public ArrayList<Exemplary> listCopies(String l){
    ArrayList <Exemplary> tmp = new ArrayList<Exemplary>();
    for( int i = 0 ; i < copies.size(); i++){  
                 if(copies.get(i).getWrittenWork().getLanguage().equals(language)){ 
                tmp.add(Ex);
             }
    }
    return (tmp);}

I want to rewrite this code in a way that with or without argument (String lang) > it returns the array tmp .

12
  • What is your question? Commented Apr 7, 2014 at 21:42
  • Side note, you have String lang passed to the method, but referenced an language in the code of the method. Commented Apr 7, 2014 at 21:43
  • if no language is given (empty string), all copies of the library will be returned (in all languages): you haven't implemented this rule. Just do it. Commented Apr 7, 2014 at 21:45
  • if(language.equals("")) put a check in this way. Commented Apr 7, 2014 at 21:45
  • 1
    Are having problem compiling your code? If yes, then what's the problem? Commented Apr 7, 2014 at 21:49

1 Answer 1

1

There's a multitude of problems with your code:

Sign up to request clarification or add additional context in comments.

2 Comments

public ArrayList<Exemplaire> listerExemplaires(String l){ ArrayList <Exemplaire> tmp = new ArrayList<Exemplaire>(); for( int i = 0 ; i < exemplaires.size(); i++){ if(exemplaires.get(i).getOeuvre().getLangue().equals(langue)){ tmp.add(Ex); } } return (tmp); }
please take a look again to my question above , i gave more explanations to my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.