Skip to content
Open
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
2 changes: 1 addition & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions HW_Java1.iml

This file was deleted.

44 changes: 18 additions & 26 deletions src/main/java/Lesson1/HomeWorkApp.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package Lesson1;

import java.util.Scanner;

public class HomeWorkApp {

public static void main(String[] args) {
printThreeWords();
checkSumSign();
printColor();
compareNumbers();
checkSumSign(3, 6);
checkSumSign(-1, 1);
checkSumSign(-2, 1);
printColor(-7);
printColor(0);
printColor(7);
printColor(100);
printColor(101);
compareNumbers(9, 9);
compareNumbers(9, 5);
compareNumbers(3, 9);
}

public static void printThreeWords() {
Expand All @@ -16,42 +23,27 @@ public static void printThreeWords() {
System.out.println("Apple");
}

public static void checkSumSign() {
Scanner in = new Scanner(System.in);
System.out.println("Введите первое число");
int a = in.nextInt();
System.out.println("Введите второе число");
int b = in.nextInt();
public static void checkSumSign(int a, int b) {
int sum = a + b;
if (sum >= 0) { // если сумма меньше или равна нулю
if (sum >= 0) { // если сумма больше или равна нулю
System.out.println("Сумма положительная");
} else {
System.out.println("Сумма отрицательная");
}
}

public static void printColor() {
Scanner in = new Scanner(System.in);
System.out.println("Введите число");
int value = in.nextInt();
public static void printColor(int value) {
if (value <= 0) {
System.out.println("Красный");
}
if (value <= 100){
} else if (value <= 100) {
System.out.println("Желтый");
}
if (value > 100){
} else if (value > 100) {
System.out.println("Зеленый");
}

}

public static void compareNumbers() {
Scanner in = new Scanner(System.in);
System.out.println("Введите первое число");
int a = in.nextInt();
System.out.println("Введите второе число");
int b = in.nextInt();
public static void compareNumbers(int a, int b) {
if (a >= b) {
System.out.println(a + " >= " + b);
} else {
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/Lesson2/HomeWorkApp2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package Lesson2;

public class HomeWorkApp2 {

public static void main(String[] args) {
checkSum(7, 5);
checkSum(3, -2);
checkSum(10, 11);
printChekInt(10);
printChekInt(-1);
printChekInt(0);
checkInt(-1);
checkInt(0);
checkInt(2);
printStringNTimes("Число равно ", 6);
checkYear(200);
checkYear(400);
checkYear(600);
checkYear(2020);
checkYear(2022);
}

public static boolean checkSum(int a, int b) {
int sum = a + b;
if (sum > 9 & sum < 21) {
return true;
}
return false;
}

public static void printChekInt(int n) {
if (n >= 0) {
System.out.println("Число " + n + " положительное");
} else {
System.out.println("Число " + n + " отрицательное");
}
}

public static boolean checkInt(int i) {
if (i == 0) {
System.out.println("Число равно нулю");
} else if (i < 0) {
return true;
}
return false;
}

public static void printStringNTimes(String text, int n) {
for (int i = 0; i < n; i++) {
System.out.println(text + (i + 1));
}
}

public static boolean checkYear(int year) {
if (year % 4 == 0 & year % 100 != 0 || year % 400 == 0) {
return true;
}
return false;
}

}
28 changes: 28 additions & 0 deletions src/main/java/Lesson6/Animal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Lesson6;

public abstract class Animal {
private static int counterAnimal = 0;
private final int MAX_RUN_LENGTH = 0;
private final int MAX_SWIM_LENGTH = 0;
private final double MAX_JUMP_HEIGTH = 0;
private String name;

public Animal(String name) {
this.name = name;
counterAnimal++;
}

public static int getCountAnimal() {
return counterAnimal;
}

abstract void run(int length);

abstract void swim(int length);

abstract void jump(double height);

public String getName() {
return name;
}
}
35 changes: 35 additions & 0 deletions src/main/java/Lesson6/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Lesson6;

public class Cat extends Animal {
private final int MAX_RUN_LENGTH = 200;
private final double MAX_JUMP_HEIGTH = 2;
private static int countCat = 0;

public Cat(String name) {
super(name);
countCat++;
}

public static int getCountCat() {
return countCat;
}

@Override
void run(int length) {
if ((length >= 0) && (length <= MAX_RUN_LENGTH))
System.out.println("Кошка " + getName() + " пробежала " + length + " м");
else System.out.println("Кошка " + getName() + " может пробежать максимум " + MAX_RUN_LENGTH + " м");
}

@Override
void swim(int length) {
System.out.println("Кошка " + getName() + " не умеет плавать");
}

@Override
void jump(double height) {
if ((height >= 0) && (height <= MAX_JUMP_HEIGTH))
System.out.println("Кошка " + getName() + " прыгнула на " + height + " м");
else System.out.println("Кошка " + getName() + " может прыгнуть максимум " + MAX_JUMP_HEIGTH + " м");
}
}
38 changes: 38 additions & 0 deletions src/main/java/Lesson6/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package Lesson6;

public class Dog extends Animal {
private final int MAX_RUN_LENGTH = 500;
private final int MAX_SWIM_LENGTH = 10;
private final double MAX_JUMP_HEIGTH = 0.5;
private static int countDog = 0;

public Dog(String name) {
super(name);
countDog++;
}

public static int getCountDog() {
return countDog;
}

@Override
void run(int length) {
if ((length >= 0) && (length <= MAX_RUN_LENGTH))
System.out.println("Собака " + getName() + " пробежала " + length + " м");
else System.out.println("Собака " + getName() + " может пробежать максимум " + MAX_RUN_LENGTH + " м");
}

@Override
void swim(int length) {
if ((length >= 0) && (length <= MAX_SWIM_LENGTH))
System.out.println("Собака " + getName() + " проплыла " + length + " м");
else System.out.println("Собака " + getName() + " может проплыть максимум " + MAX_SWIM_LENGTH + " м");
}

@Override
void jump(double height) {
if ((height >= 0) && (height <= MAX_JUMP_HEIGTH))
System.out.println("Собака " + getName() + " прыгнула на " + height + " м");
else System.out.println("Собака " + getName() + " может прыгнуть максимум " + MAX_JUMP_HEIGTH + " м");
}
}
25 changes: 25 additions & 0 deletions src/main/java/Lesson6/homeWorkApp6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Lesson6;

public class homeWorkApp6 {
public static void main(String[] args) {
Cat cat = new Cat("Котюля");
cat.run(201);
cat.swim(1);
cat.jump(1.9);


Dog dog = new Dog("Собачюля");
dog.run(500);
dog.swim(10);
dog.jump(0.4);

Dog dog1 = new Dog("Собакевич");
dog1.run(501);
dog1.swim(50);
dog1.jump(2);

System.out.println("Животных в итоге " + Animal.getCountAnimal() + " шт.");
System.out.println("Кошачьих в итоге " + Cat.getCountCat() + " шт.");
System.out.println("Собачек в итоге " + Dog.getCountDog() + " шт.");
}
}
Loading