Advertisement
porteno

AllCars

Dec 7th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public class AllCars {
  2. private Car[] cars;
  3. private int num;
  4.  
  5. public AllCars(int max) {
  6. this.cars = new Car[max];
  7. this.num = 0;
  8. }
  9.  
  10. public boolean addCar(Car car){
  11. if(this.num == this.cars.length)
  12. return false;
  13. else{
  14. cars[num] = car;
  15. num++;
  16. return true;
  17. }
  18. }
  19.  
  20. public void print(int min, int max){
  21. for (int i = 0; i < this.cars.length; i++) {
  22. Car car = this.cars[i];
  23. if(!car.hadAccident() && car.range(min, max))
  24. System.out.println("car license:"+car.getLicenseNum());
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement