Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- ArrayList<Сar> cars=new ArrayList<>();
- сars.add(new Сar("жигули", 200,3000,1200));
- сars.add(new Сar("mercedes", 250, 4500, 3000));
- totalSpeed(ArrayList<Car>);
- }
- static int totalSpeed(ArrayList<Car> cars){
- int counter =0;
- for(int i= 0; i<2; i++){
- counter += cars.get(i).getSpeed();
- }
- return counter;
- }
- }
- class Car{
- private final String name;
- private final int speed;
- private final int size;
- private final int weight;
- public Car (String name, int speed,int size,int weight){
- this.speed=speed;
- this.size=size;
- this.weight=weight;
- this.name=name;
- }
- public int getSpeed() {
- return speed;
- }
- public int getSize() {
- return size;
- }
- public int getWeight() {
- return weight;
- }
- }
Add Comment
Please, Sign In to add comment