lundi 23 mars 2015
ArrayList
Posted on 02:43 by verona
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
}
public Car getMostExpensiveCar(){ //To do:
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:
- public ArrayList<Car> carsInRange(int min, int max){
- ArrayList<Car> foundCars = new ArrayList<Car>();
- for(Car myCar : cars){
- if(myCar.getPrice() <= max && myCar.getPrice() >= min){
- foundCars.add(myCar);
- }
- }
- return foundCars;
- }
public Car getMostExpensiveCar(){ //To do:
Java Code:
- public Car getMostExpensiveCar(){
- int mostExpensive = 0;
- Car mostExpensiveCar = null;
- for(Car myCar : cars){
- if(myCar.getPrice() > mostExpensive){
- mostExpensive = myCar.getPrice();
- mostExpensiveCar = myCar;
- }
- }
- return mostExpensiveCar;
- }
ArrayList
Categories: ArrayList
Inscription à :
Publier les commentaires (Atom)
0 commentaires:
Enregistrer un commentaire