Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import animal.type.app.Animal;
import animal.type.app.Dog;
import animal.type.app.Fish;
import org.arrayutil.app.ArrayUtil;

import java.util.ArrayList;
import java.util.Arrays;

record GroceryItem(String name, String type, int count) {
public GroceryItem(String name) {
this(name, "Dairy", 1);
}
}

public class Main {
public static void main(String[] args) {
int[] arr = ArrayUtil.getRandomArray(10);
/*int[] arr = ArrayUtil.getRandomArray(100);
ArrayUtil.printArray(arr);
int secondMax = ArrayUtil.secondMax(arr);
System.out.println("SecondMax: " + secondMax);
System.out.println(ArrayUtil.binarySearch(arr, 15));
ArrayUtil.bubbleSort(arr);
ArrayUtil.printArray(arr);
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
System.out.println(ArrayUtil.binarySearch(arr, 15));*/
ArrayList<Animal> animals = new ArrayList<>();
Dog dog = new Dog("Golden", "small", 20);
Fish fish = new Fish("Brown", "medium", 5);

animals.add(dog);
}
/*public static void GroceryItemTest() {
Object[] groceryItems = new Object[5];
groceryItems[0] = new GroceryItem("milk");
groceryItems[1] = new GroceryItem("Dairy", "Dairy", 2);
}*/
public static void printAnimals(ArrayList<Animal> animals) {
for (Animal animal : animals) {
animal.eat();
animal.move("fast");
animal.sleep();
animal.move("slow");
}
}
}
19 changes: 19 additions & 0 deletions src/animal/type/app/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package animal.type.app;

public abstract class Animal {
private String type;
private String size;
private int weight;
public Animal(String type, String size, int weight) {
this.type = type;
this.size = size;
this.weight = weight;
}
public abstract void eat();
public abstract void sleep();
public abstract void move(String speed);

public String getExplicitType() {
return getClass().getSimpleName() + " (" + type + ")";
}
}
30 changes: 30 additions & 0 deletions src/animal/type/app/Crocodile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package animal.type.app;

public class Crocodile extends Animal {
public Crocodile(String type, String size, int weight) {
super(type, size, weight);
}

@Override
public void eat() {
System.out.println(getExplicitType() + " eats crocodile");
}

@Override
public void sleep() {
System.out.println(getExplicitType() + " sleeps crocodile");
}

@Override
public void move(String speed) {
if (speed.equals("miles")) {
System.out.println(getExplicitType() + " moves miles crocodile");
}
else if (speed.equals("kilometers")) {
System.out.println(getExplicitType() + " moves kilometers crocodile");
}
else {
System.out.println(getExplicitType() + " moves feet crocodile");
}
}
}
28 changes: 28 additions & 0 deletions src/animal/type/app/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package animal.type.app;

public class Dog extends Animal{

public Dog(String type, String size, int weight) {
super(type, size, weight);
}

@Override
public void eat() {
System.out.println(getExplicitType() + " eats the dog");
}

@Override
public void sleep() {
System.out.println(getExplicitType() + " sleeps the dog");
}

@Override
public void move(String speed) {
if (speed.equals("slow")) {
System.out.println(getExplicitType() + "Walking");
}
else {
System.out.println(getExplicitType() + "Running");
}
}
}
28 changes: 28 additions & 0 deletions src/animal/type/app/Fish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package animal.type.app;

public class Fish extends Animal {

public Fish(String type, String size, int weight) {
super(type, size, weight);
}

@Override
public void eat() {
System.out.println(getExplicitType() + " eats fish");
}

@Override
public void sleep() {
System.out.println(getExplicitType() + " sleeps fish");
}

@Override
public void move(String speed) {
if (speed.equals("slow")) {
System.out.println(getExplicitType() + " lazily swimming");
}
else {
System.out.println(getExplicitType() + " darting frantically");
}
}
}