Skip to content

Commit 6ad5ee9

Browse files
authored
Merge pull request BasePractice#135 from MeowWewLord/main
Лабораторные 1-1.4 (исправлена лабораторная 2)
2 parents 13bf52b + ccd662c commit 6ad5ee9

File tree

49 files changed

+1265
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1265
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<module>students/23K0364</module>
4545
<module>students/23K0155</module>
4646
<module>students/23K0114</module>
47+
<module>students/23K0823</module>
4748
<module>students/23K0087</module>
4849
<module>students/23K0112</module>
4950
<module>students/23K0351</module>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0823</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0823-p01</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package ru.mirea.practice.s23k0823;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
public abstract class Exemple {
7+
public static void main(String[] args) {
8+
// Task 1
9+
int sum = 0;
10+
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
11+
for (int i = 0; i < 10; i++) {
12+
sum += array[i];
13+
}
14+
int avg = sum / 10;
15+
System.out.println("Сумма: " + sum + " Среднее: " + avg);
16+
// Task 1 final
17+
// Task 2
18+
try (Scanner scanner = new Scanner(System.in);) {
19+
System.out.print("Введите размерность массива: ");
20+
int sizeArray = scanner.nextInt();
21+
int[] array2 = new int[sizeArray];
22+
int i = 0;
23+
do {
24+
System.out.print("Введите элемент массива №: " + (i + 1) + " его значение: ");
25+
array2[i] = scanner.nextInt();
26+
i++;
27+
} while (i < sizeArray);
28+
int max = Arrays.stream(array2).max().getAsInt();
29+
int min = Arrays.stream(array2).min().getAsInt();
30+
System.out.println("MAX: " + max + " MIN: " + min);
31+
System.out.print("Введите размерность массива: ");
32+
int sizeArray2 = scanner.nextInt();
33+
int[] array3 = new int[sizeArray2];
34+
i = 0;
35+
while (i < sizeArray2) {
36+
System.out.print("Введите элемент массива №: " + (i + 1) + " его значение: ");
37+
array3[i] = scanner.nextInt();
38+
i++;
39+
}
40+
int max2 = Arrays.stream(array3).max().getAsInt();
41+
int min2 = Arrays.stream(array3).min().getAsInt();
42+
System.out.println("MAX 2: " + max2 + " MIN 2: " + min2);
43+
// Task 2 final
44+
// Task 3
45+
System.out.println("Аргументы:" + Arrays.toString(args));
46+
// Task 3 final
47+
// Task 4
48+
double[] harmonicArray = new double[10];
49+
for (i = 0; i < 10; i++) {
50+
harmonicArray[i] = (double) 1 / (i + 1);
51+
}
52+
System.out.print("Гармоничесикй массив:");
53+
for (i = 0; i < 10; i++) {
54+
String str = String.format(" %1.3f", harmonicArray[i]);
55+
System.out.print(str);
56+
}
57+
// Task 4
58+
// Task 5
59+
System.out.print("\nВведите число для вычисления факториала: ");
60+
int number = scanner.nextInt();
61+
62+
long factorial = calculateFactorial(number);
63+
System.out.println("Факториал числа " + number + " равен " + factorial);
64+
}
65+
66+
}
67+
68+
public static long calculateFactorial(int number) {
69+
long factorial = 1;
70+
for (int i = 1; i <= number; i++) {
71+
factorial *= i;
72+
}
73+
return factorial;
74+
}
75+
// Task 5 final
76+
77+
}
78+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package ru.mirea.practice.s23k0823;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
public abstract class Main {
7+
public static void main(String[] args) {
8+
// Task 1
9+
int sum = 0;
10+
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
11+
for (int i = 0; i < 10; i++) {
12+
sum += array[i];
13+
}
14+
int avg = sum / 10;
15+
System.out.println("Сумма: " + sum + " Среднее: " + avg);
16+
// Task 1 final
17+
// Task 2
18+
try (Scanner scanner = new Scanner(System.in);) {
19+
System.out.print("Введите размерность массива: ");
20+
int sizeArray = scanner.nextInt();
21+
int[] array2 = new int[sizeArray];
22+
int i = 0;
23+
do {
24+
System.out.print("Введите элемент массива №: " + (i + 1) + " его значение: ");
25+
array2[i] = scanner.nextInt();
26+
i++;
27+
} while (i < sizeArray);
28+
int max = Arrays.stream(array2).max().getAsInt();
29+
int min = Arrays.stream(array2).min().getAsInt();
30+
System.out.println("MAX: " + max + " MIN: " + min);
31+
System.out.print("Введите размерность массива: ");
32+
int sizeArray2 = scanner.nextInt();
33+
int[] array3 = new int[sizeArray2];
34+
i = 0;
35+
while (i < sizeArray2) {
36+
System.out.print("Введите элемент массива №: " + (i + 1) + " его значение: ");
37+
array3[i] = scanner.nextInt();
38+
i++;
39+
}
40+
int max2 = Arrays.stream(array3).max().getAsInt();
41+
int min2 = Arrays.stream(array3).min().getAsInt();
42+
System.out.println("MAX 2: " + max2 + " MIN 2: " + min2);
43+
// Task 2 final
44+
// Task 3
45+
System.out.println("Аргументы:" + Arrays.toString(args));
46+
// Task 3 final
47+
// Task 4
48+
double[] harmonicArray = new double[10];
49+
for (i = 0; i < 10; i++) {
50+
harmonicArray[i] = (double) 1 / i + 1;
51+
}
52+
System.out.print("Гармоничесикй массив:");
53+
for (i = 0; i < 10; i++) {
54+
String str = String.format(" %1.3f", harmonicArray[i]);
55+
System.out.print(str);
56+
}
57+
// Task 4
58+
// Task 5
59+
System.out.print("\nВведите число для вычисления факториала: ");
60+
int number = scanner.nextInt();
61+
62+
long factorial = calculateFactorial(number);
63+
System.out.println("Факториал числа " + number + " равен " + factorial);
64+
}
65+
}
66+
67+
public static long calculateFactorial(int number) {
68+
long factorial = 1;
69+
for (int i = 1; i <= number; i++) {
70+
factorial *= i;
71+
}
72+
return factorial;
73+
}
74+
// Task 5 final
75+
}
76+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0823</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0823-p02</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ru.mirea.practice.s23k0823.task7;
2+
3+
public class Book {
4+
private String author;
5+
private String title;
6+
private int publicationYear;
7+
8+
public Book(String author, String title, int publicationYear) {
9+
this.author = author;
10+
this.title = title;
11+
this.publicationYear = publicationYear;
12+
}
13+
14+
public String getAuthor() {
15+
return author;
16+
}
17+
18+
public void setAuthor(String author) {
19+
this.author = author;
20+
}
21+
22+
public String getTitle() {
23+
return title;
24+
}
25+
26+
public void setTitle(String title) {
27+
this.title = title;
28+
}
29+
30+
public int getPublicationYear() {
31+
return publicationYear;
32+
}
33+
34+
public void setPublicationYear(int publicationYear) {
35+
this.publicationYear = publicationYear;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "Book {"
41+
+
42+
"author='" + author + '\''
43+
+
44+
", title='" + title + '\''
45+
+
46+
", publicationYear=" + publicationYear
47+
+
48+
'}';
49+
}
50+
51+
52+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s23k0823.task7;
2+
3+
public abstract class BookTest {
4+
public static void main(String[] args) {
5+
Book book1 = new Book("Айзек Азимов", "Я робот", 1950);
6+
Book book2 = new Book("Рей Бредбери", "451 по фаренгейту", 1953);
7+
Book book3 = new Book("Рей Бредбери", "Вино из одуванчиков", 1957);
8+
9+
System.out.println("Книга 1: " + book1.toString());
10+
System.out.println("Книга 2: " + book2.toString());
11+
System.out.println("Книга 3: " + book3.toString());
12+
}
13+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package ru.mirea.practice.s23k0823.task7;
2+
3+
import java.util.Arrays;
4+
5+
public class Bookshelf {
6+
private Book[] books;
7+
private int numBooks;
8+
9+
public Bookshelf(int capacity) {
10+
this.books = new Book[capacity];
11+
this.numBooks = 0;
12+
}
13+
14+
public void addBook(Book book) {
15+
if (numBooks < books.length) {
16+
books[numBooks] = book;
17+
numBooks++;
18+
} else {
19+
System.out.println("Шкаф полон");
20+
}
21+
}
22+
23+
public Book getLatestBook() {
24+
Book latestBook = books[0];
25+
for (int i = 1; i < numBooks; i++) {
26+
if (books[i].getPublicationYear() > latestBook.getPublicationYear()) {
27+
latestBook = books[i];
28+
}
29+
}
30+
return latestBook;
31+
}
32+
33+
public Book getEarliestBook() {
34+
Book earliestBook = books[0];
35+
for (int i = 1; i < numBooks; i++) {
36+
if (books[i].getPublicationYear() < earliestBook.getPublicationYear()) {
37+
earliestBook = books[i];
38+
}
39+
}
40+
return earliestBook;
41+
}
42+
43+
public void sortBooksByPublicationYear() {
44+
Arrays.sort(books, 0, numBooks, (book1, book2) -> book1.getPublicationYear() - book2.getPublicationYear());
45+
}
46+
47+
public void printBooks() {
48+
for (int i = 0; i < numBooks; i++) {
49+
System.out.println(books[i].toString());
50+
}
51+
}
52+
53+
public static void main(String[] args) {
54+
Bookshelf bookshelf = new Bookshelf(5);
55+
56+
Book book1 = new Book("Рей Бредбери", "451 по фаренгейту", 1953);
57+
Book book2 = new Book("Рей Бредбери", "Вино из одуванчиков", 1957);
58+
Book book3 = new Book("Айзек Азимов", "Я робот", 1950);
59+
60+
bookshelf.addBook(book1);
61+
bookshelf.addBook(book2);
62+
bookshelf.addBook(book3);
63+
64+
System.out.println("Последняя книга: " + bookshelf.getLatestBook().toString());
65+
System.out.println("Самая ранняя книга: " + bookshelf.getEarliestBook().toString());
66+
67+
bookshelf.sortBooksByPublicationYear();
68+
System.out.println("Книги отсортированы по году издания: ");
69+
bookshelf.printBooks();
70+
}
71+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ru.mirea.practice.s23k0823.task9;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.Scanner;
7+
8+
public abstract class Poker {
9+
public static void main(String[] args) {
10+
try (Scanner scanner = new Scanner(System.in);) {
11+
System.out.print("Введите количество игроков: ");
12+
int n = scanner.nextInt();
13+
14+
List<String> deck = createDeck();
15+
Collections.shuffle(deck);
16+
17+
for (int i = 0; i < n; i++) {
18+
System.out.println("Игрок " + (i + 1) + ":");
19+
for (int j = 0; j < 5; j++) {
20+
System.out.println(deck.remove(deck.size() - 1));
21+
}
22+
System.out.println();
23+
}
24+
}
25+
}
26+
27+
private static List<String> createDeck() {
28+
List<String> deck = new ArrayList<>();
29+
String[] suits = {"Пики", "Черви", "Бубны", "Трефы"};
30+
String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Валет", "Дама", "Король", "Туз"};
31+
32+
for (String suit : suits) {
33+
for (String rank : ranks) {
34+
deck.add(rank + " от " + suit);
35+
}
36+
}
37+
38+
return deck;
39+
}
40+
}
41+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0823</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0823-p03</artifactId>
12+
<description>Массивы</description>
13+
</project>

0 commit comments

Comments
 (0)