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
89 changes: 89 additions & 0 deletions src/java/lesson1/MyHomeWork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package lesson1;

public class MyHomeWork {
//1. Создать пустой проект в IntelliJ IDEA и прописать метод main().
public static void main(String[] args) {
System.out.println(calculate(12.23f, 10.11f, 3.23f, 11.05f));
System.out.println(task10and20(10,5));
System.out.println(task10and20(30,5));
isPositiveOrNegative(-5);
isPositiveOrNegative(7);
System.out.println(isNegative(8));
System.out.println(isNegative(-7));
greetings("Maks");
leapyear(2012);
leapyear(1993);

}
//2. Создать переменные всех пройденных типов данных и инициализировать их значения.

byte by = -120;
short sh = 12442;
int in = 1000;
long lo = 200000L;
float fl = 12.23f;
double doub = -123.123;
char ch = '*';
boolean bool = false;

//3. Написать метод вычисляющий выражение a * (b + (c / d)) и возвращающий результат,
//где a, b, c, d – аргументы этого метода, имеющие тип float.

public static float calculate(float a, float b, float c, float d) {
return a * (b + (c / d));
}
//4. Написать метод, принимающий на вход два целых числа и проверяющий, что их сумма лежит в пределах
// от 10 до 20 (включительно), если да – вернуть true, в противном случае – false.

public static boolean task10and20(int x1, int x2){
int summ = x1 + x2;
return (summ >= 10) && (summ <= 20);

}
//5. Написать метод, которому в качестве параметра передается целое число, метод должен напечатать в консоль,
// положительное ли число передали или отрицательное. Замечание: ноль считаем положительным числом.

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


//6. Написать метод, которому в качестве параметра передается целое число.
//Метод должен вернуть true, если число отрицательное.

public static boolean isNegative(int x) {
return x < 0;
}


//7. Написать метод, которому в качестве параметра передается строка, обозначающая имя.
//Метод должен вывести в консоль сообщение «Привет, указанное_имя!».

public static void greetings(String name) {
System.out.println("Привет, " + name + "!");
}


//8. *Написать метод, который определяет, является ли год высокосным, и выводит сообщение в консоль.
//Каждый 4-й год является високосным, кроме каждого 100-го, при этом каждый 400-й – высокосный.

public static void leapyear(int year) {
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
System.out.println("Год " + year + " являеться высокосным");
} else {
System.out.println("Год " + year + " не являеться высокосным");
}


}
}






185 changes: 185 additions & 0 deletions src/java/lesson4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package lesson4;

import java.util.Random;
import java.util.Scanner;
import java.util.Arrays;

public class Main {

static char[][] createEmptyTable(int len) {
char[][] table = new char[len][len];
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
table[i][j] = '_';
}
}
return table;
}

static void show(char[][] table) {
int len = table.length;
System.out.print(" ");
for (int i = 0; i < len; i++) {
System.out.print((i + 1) + " ");
}
System.out.println();
for (int i = 0; i < len; i++) {
System.out.print((i + 1) + " ");
for (int j = 0; j < len; j++) {
System.out.print("|" + table[i][j]);
}
System.out.println("|");
}
}

private static boolean isValid(int x, int y, char[][] table) {
int l = table.length - 1;
if (x < 0 || x > l) return false;
if (y < 0 || y > l) return false;
return table[x][y] == '_';
}

private static boolean isVictory(char[][] table, char x) {
int len = table.length;
for (int i = 0; i < table.length; i++) {
int sX = 0, sY = 0, d1 = 0, d2 = 0;
for (int j = 0; j < table.length; j++) {
sX += table[i][j] == x ? 1 : 0;
sY += table[j][i] == x ? 1 : 0;
d1 += table[j][j] == x ? 1 : 0;
d2 += table[j][len - j - 1] == x ? 1 : 0;
}
if (sX == len || sY == len
|| d1 == len || d2 == len) return true;
}
return false;
}

public static void main(String[] args) {
// XO 3 * 3
int counter = 0;
Scanner in = new Scanner(System.in);
System.out.println("Игра: крестики нолики");
System.out.println("Введите размер игрового поля");
int n = in.nextInt();
System.out.printf("Игровое поле %d X %d\n", n, n);
char[][] table = createEmptyTable(n);
show(table);
while (true) {
System.out.println("Для того, чтобы совершить ход:" +
" введите номер строки и номер столбца игрового поля");
int x = in.nextInt(), y = in.nextInt();
x--;
y--;
//alt + enter
if (isValid(x, y, table)) {
table[x][y] = 'X';
counter++;
show(table);
} else {
System.out.println("Введены некорректные данные");
continue;
}
if (isVictory(table, 'X')) {
System.out.println("Вы победили!");
break;
//new game ?
}
if (counter == 9) {
System.out.println("Ничья!");
break;
}
System.out.println("Компьютер думает над ходом");
for (int i = 0; i < 9; i++) {
System.out.print(" * ");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println();
movePCHard(table);
counter++;
show(table);
if (isVictory(table, 'O')) {
System.out.println("Вы проиграли!");
break;
}
}
}

private static void movePCRandom(char[][] table) {
Random rnd = new Random();
int len = table.length;
while (true) {
int x = rnd.nextInt(len), y = rnd.nextInt(len);
if (isValid(x, y, table)) {
table[x][y] = 'O';
return;
}
}
}

private static void movePCEasy(char[][] table) {
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < table.length; j++) {
if (table[i][j] == '_') {
table[i][j] = 'O';
return;
}
}
}
}

private static void movePCHard(char[][] table) {
// TODO: 13.02.2020
int i = 0;
int j = 0;
int x = 0;
int y = 0;
int z = 1;
for (z = 0; z <=2 ; z++) {
if (z == 1){
x = i;
y = j;
}
else {
x = j;
y = i;
}
for (j = 0; j <= table.length; j++) {

for (i = 0; i <= table.length; i++) {
int counterX = 0;
int counterY = 0;

if (!isValid(x, y, table) & z == 1) {
counterX++;
}
if (!isValid(x, y, table) & z == 2) {
counterY++;
}
if (counterX >= 2 || counterY >= 2) {
Random rnd = new Random();
int len = table.length;
while (true) {
if (z == 1) y = rnd.nextInt(len);
else x = rnd.nextInt(len);
if (isValid(x, y, table)) {
table[x][y] = 'O';
return;
}
}
}
}

}
}
if (isValid(1, 1, table)) {
table[1][1] = 'O';
return;
}
movePCRandom(table);
}
}
23 changes: 23 additions & 0 deletions src/java/lesson5/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package lesson5.homework;


public class Employee {
private String fullName, position, email;
private int age, tel, salary;

public Employee(String fullName, String position, String email, int age, int tel, int salary) {
this.fullName = fullName;
this.position = position;
this.email = email;
this.age = age;
this.tel = tel;
this.salary = salary;
}
public int getAge() {
return age;
}

public void show() {
System.out.println(fullName + " " + position + " " + email + " " + age + " " + tel + " " + salary);
}
}
24 changes: 24 additions & 0 deletions src/java/lesson5/HomeWork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lesson5.homework;

import java.util.ArrayList;
import lesson5.homework.Employee;
public class HomeWork {

public static void main(String[] args) {
Employee[] persArray = new Employee[5];
persArray[0] = new Employee("Ivanov Petr Sergeevich", "director", "direct@mail.com", 45, 34565, 300000);
persArray[1] = new Employee("Sergeev Ivan Sergeevich", "manager", "man@mail.com", 30, 34765, 150000);
persArray[2] = new Employee("Ivanov Den Sergeevich", "junior manager", "ids@mail.com", 26, 34485, 110000);
persArray[3] = new Employee("Sokol Alex Petrovich", "junior manager", "sap@mail.com", 24, 34539, 100000);
persArray[4] = new Employee("Ivanova Elena Alexandrovna", "office manager", "iea@mail.com", 44, 34549, 90000);

for (int i = 0; i <= 4; i++) {
if (persArray[i].getAge() >= 40) persArray[i].show();
}

}



}

1 change: 1 addition & 0 deletions src/java/lesson5/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@