ColonelNV

214аыф

Apr 2nd, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6. ArrayList<Сar> cars=new ArrayList<>();
  7.         сars.add(new Сar("жигули", 200,3000,1200));
  8.         сars.add(new Сar("mercedes", 250, 4500, 3000));
  9.         totalSpeed(ArrayList<Car>);
  10.     }
  11.     static int totalSpeed(ArrayList<Car> cars){
  12.         int counter =0;
  13.         for(int i= 0; i<2; i++){
  14.             counter += cars.get(i).getSpeed();
  15.         }
  16.         return counter;
  17.     }
  18. }
  19. class Car{
  20.      private final String name;
  21.      private final int speed;
  22.      private final int size;
  23.      private final int weight;
  24.     public Car (String name, int speed,int size,int weight){
  25. this.speed=speed;
  26. this.size=size;
  27. this.weight=weight;
  28. this.name=name;
  29.     }
  30.  
  31.     public int getSpeed() {
  32.         return speed;
  33.     }
  34.  
  35.     public int getSize() {
  36.         return size;
  37.     }
  38.  
  39.     public int getWeight() {
  40.         return weight;
  41.     }
  42.  
  43. }
Add Comment
Please, Sign In to add comment