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:
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:
public Car getMostExpensiveCar(){
int mostExpensive = 0;
Car mostExpensiveCar = null;
for(Car myCar : cars){
if(myCar.getPrice() > mostExpensive){
mostExpensive = myCar.getPrice();
mostExpensiveCar = myCar;
}
}
return mostExpensiveCar;
}
Zuletzt bearbeitet: