lundi 23 mars 2015

ArrayList

Hallo,

Ich wollte wissen was genau hier in diesen Methoden passiert..

hatte Aufgaben:



public ... carsInRange( int min, int max ){

//To do: search all the cars with a price between min and max //and return these cars as an ArrayList

}




Java Code:






  1. public ArrayList<Car> carsInRange(int min, int max){



  2. ArrayList<Car> foundCars = new ArrayList<Car>();



  3. for(Car myCar : cars){



  4. if(myCar.getPrice() <= max && myCar.getPrice() >= min){



  5. foundCars.add(myCar);



  6. }



  7. }



  8. return foundCars;



  9. }











public Car getMostExpensiveCar(){ //To do:




Java Code:






  1. public Car getMostExpensiveCar(){



  2. int mostExpensive = 0;



  3. Car mostExpensiveCar = null;



  4. for(Car myCar : cars){



  5. if(myCar.getPrice() > mostExpensive){



  6. mostExpensive = myCar.getPrice();



  7. mostExpensiveCar = myCar;



  8. }



  9. }



  10. return mostExpensiveCar;



  11. }










ArrayList

0 commentaires:

Enregistrer un commentaire