From 3a1312c8434f1dead916c9c4a2b8e49b128ef407 Mon Sep 17 00:00:00 2001 From: Vyaceslav Sv Date: Sun, 26 Apr 2020 19:32:29 +0300 Subject: [PATCH] first commit --- level3.iml | 12 ++++++ src/Geekbrains/Main.java | 79 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 level3.iml create mode 100644 src/Geekbrains/Main.java diff --git a/level3.iml b/level3.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/level3.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/Geekbrains/Main.java b/src/Geekbrains/Main.java new file mode 100644 index 0000000..28f4c6d --- /dev/null +++ b/src/Geekbrains/Main.java @@ -0,0 +1,79 @@ +package Geekbrains; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Main { + public static void main(String[] args) { + } +} +class ArrayTask { + //1 + public static void arrToSwap(Object[] array, int a, int b) { + Object tmp = array[a]; + array[a] = array[b]; + array[a] = tmp; + } + //2 + public ArrayList convert(T[] array) { + return new ArrayList<>(Arrays.asList(array)); + } +} + // 3 + class Fruit { + private float weight; + + public Fruit(float weight) { + this.weight = weight; + } + + float getWeight() { + return weight; + } + } + class Apple extends Fruit { + public Apple(float weight) { + super(weight); + } + + } + class Orange extends Fruit { + public Orange(float weight) { + super(weight); + } + } + + class Box { + // Складываем фрукты одного типа + private ArrayList arrayList; + // конструктор на один или несколько фрутов + public Box() { + this.arrayList = new ArrayList<>(); + } + public Box(T... fruits) { + this.arrayList = new ArrayList<>(Arrays.asList(fruits)); + } + // вес + public float getWeight() { + float weight = 0.0f; + for (T o : arrayList) { + weight += o.getWeight(); + } + return weight; + } + // сравнить + public boolean compare(Box box){ + return (this.getWeight()-box.getWeight() < 0.0001); + } + // добавить + public void add(T fruit) { + arrayList.add(fruit); + } + // перемещение + public void sprinkle(Box another) { + another.arrayList.addAll(arrayList); + arrayList.clear(); + } +} + +