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
31 changes: 31 additions & 0 deletions src/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Animal {
private String name;
private int maxDistSwim;
private int maxDistRun;

public void run(int dist){
if (dist <= maxDistRun){
System.out.println(name + " runs " + dist + "m.");
}
else {
System.out.println(name + " can`t run " + dist + "m.");
}
}

public void swim(int dist){
if (maxDistSwim == 0 )
System.out.println(name + " can`t swim");

else if (dist <= maxDistSwim)
System.out.println(name + " swims " + dist + "m.");

else
System.out.println(name + " can`t swim " + dist + "m.");
}

public Animal(String name, int maxDistRun, int maxDistSwim){
this.name = name;
this.maxDistRun = maxDistRun;
this.maxDistSwim = maxDistSwim;
}
}
7 changes: 7 additions & 0 deletions src/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Cat extends Animal {
public static int catCount = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad var name

public Cat(String name) {
super(name, 200, 0);
catCount++;
}
}
7 changes: 7 additions & 0 deletions src/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Dog extends Animal{
public static int dogCount = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad var name

public Dog(String name) {
super(name, 500,10);
dogCount++;
}
}
21 changes: 13 additions & 8 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
String name = "Alex";
int age = 21;
System.out.println("My name is " + name + " and I`m " + age + " years old");
int[] numbers = {1, 2, 3, 4, 5};
for(int i = 0; i < numbers.length;i++){
System.out.println("Number " + i + ": " + numbers[i]);
}
Cat catVasia = new Cat("Vasia cat");
Dog dogVasia = new Dog("Vasia dog");
Dog dogCasia = new Dog("Casia dog");
Dog dogAnton = new Dog("Anton dog");
System.out.println("Dogs amount: " + Dog.dogCount);
System.out.println("Cats amount: " + Cat.catCount);
catVasia.run(120);
catVasia.run(420);
dogVasia.run(599);
catVasia.swim(10);
dogVasia.swim(10);
dogAnton.run(20);
dogCasia.swim(250);
}
}