Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 6711fd8

Browse files
authored
Merge pull request #66 from nazarovad/features/lab4
Features/lab4
2 parents 8cf3f9f + 9040532 commit 6711fd8

Some content is hidden

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

46 files changed

+1071
-2
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?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"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>ru.mirea.practice</groupId>
@@ -33,6 +33,7 @@
3333
<module>students/23K0143</module>
3434
<module>students/23K0365</module>
3535
<module>students/23K0368</module>
36+
<module>students/23K0754</module>
3637
<module>students/24K0458</module>
3738
<module>students/23K0350</module>
3839
<module>students/23K1302</module>
@@ -176,4 +177,4 @@
176177
</plugin>
177178
</plugins>
178179
</build>
179-
</project>
180+
</project>

students/23K0754/23K0754-p01/pom.xml

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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0754</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0754-p01</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package ru.mirea.practice.s230k754.lab1;
2+
3+
4+
import java.util.Scanner;
5+
6+
public final class Tasks {
7+
8+
private Tasks() {}
9+
10+
public static void task3() {
11+
12+
try (Scanner scanner = new Scanner(System.in)) {
13+
int[] numbers = new int[10]; // Массив 10 чисел
14+
int sum = 0;
15+
System.out.println("Введите 10 чисел:");
16+
17+
for (int i = 0; i < 10; i++) {
18+
numbers[i] = scanner.nextInt(); // Считываем число и добавляем в массив
19+
sum += numbers[i];
20+
}
21+
float middleSum = (float) sum / 10;
22+
23+
24+
System.out.println("Сумма: " + sum);
25+
System.out.println("Среднее арифметич: " + middleSum);
26+
}
27+
}
28+
29+
public static void task4P5() {
30+
try (Scanner scanner = new Scanner(System.in)) {
31+
System.out.println("Введите кол-во числе в массиве: ");
32+
int n = scanner.nextInt();
33+
int[] numbers = new int[n]; // Массив n чисел
34+
int sum = 0;
35+
System.out.println("Введите " + n + " чисел:");
36+
int i = 0;
37+
int max = -99999;
38+
int min = 99999;
39+
while (i < n) {
40+
numbers[i] = scanner.nextInt(); // Считываем число и добавляем в массив
41+
sum += numbers[i];
42+
if (numbers[i] >= max) {
43+
max = numbers[i];
44+
}
45+
if (numbers[i] <= min) {
46+
min = numbers[i];
47+
}
48+
i++;
49+
}
50+
51+
System.out.println("Сумма:" + sum);
52+
System.out.println("Максимальное числоа: " + max);
53+
System.out.println("Минимальное число: " + min);
54+
55+
System.out.println("Числа из массива:");
56+
for (int number : numbers) {
57+
System.out.print(number + " ");
58+
}
59+
}
60+
}
61+
62+
public static void task6() {
63+
for (int i = 1; i < 11; i++) {
64+
System.out.print(1.0 / i + "\t");
65+
}
66+
}
67+
68+
public static long factorial(int number) {
69+
if (number < 0) {
70+
System.out.println("Число должно быть не отрицательное");
71+
return -1;
72+
} else if (number == 0) {
73+
return 1;
74+
} else {
75+
long factorial = 1;
76+
for (int i = 1; i <= number; i++) {
77+
factorial *= i;
78+
}
79+
return factorial;
80+
}
81+
}
82+
83+
public static void task7() {
84+
System.out.println("\n Введите число: ");
85+
try (Scanner scanner = new Scanner(System.in)) {
86+
long result = factorial(scanner.nextInt());
87+
if (result != -1) {
88+
System.out.println("Факториал числа равен: " + result);
89+
}
90+
}
91+
}
92+
93+
public static void main(String[] args) {
94+
task3();
95+
task4P5();
96+
task6();
97+
task7();
98+
}
99+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s230k754.lab2.task1;
2+
3+
public class Author {
4+
private String name;
5+
private String email;
6+
private char gender;
7+
8+
public Author(String name, String email, char gender) {
9+
this.name = name;
10+
this.email = email;
11+
this.gender = gender;
12+
}
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public String getEmail() {
19+
return email;
20+
}
21+
22+
public char getGender() {
23+
return gender;
24+
}
25+
26+
public void setEmail(String email) {
27+
this.email = email;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return "name = " + this.name + "\temail = " + this.email + "\tgender = " + this.gender;
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.mirea.practice.s230k754.lab2.task1;
2+
3+
public final class TestAuthor {
4+
private TestAuthor() {}
5+
6+
public static void main(String[] args) {
7+
System.out.println("Task completed");
8+
}
9+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.mirea.practice.s230k754.lab2.task2;
2+
3+
public class Ball {
4+
private double x = 0.0;
5+
private double y = 0.0;
6+
7+
public Ball(double x, double y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
public Ball() {
13+
this.x = 0.0;
14+
this.y = 0.0;
15+
}
16+
17+
public double getX() {
18+
return x;
19+
}
20+
21+
public void setX(double x) {
22+
this.x = x;
23+
}
24+
25+
public double getY() {
26+
return y;
27+
}
28+
29+
public void setY(double y) {
30+
this.y = y;
31+
}
32+
33+
public void setXY(double x, double y) {
34+
this.x = x;
35+
this.y = y;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "x = " + this.x + "\ty = " + this.y;
41+
}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s230k754.lab2.task2;
2+
3+
public final class TestBall {
4+
private TestBall() {}
5+
6+
public static void main(String[] args) {
7+
Ball b1 = new Ball(0.0, 0.0);
8+
Ball b2 = new Ball();
9+
System.out.println(b1.toString());
10+
11+
b2.setXY(23.23, 345.34);
12+
System.out.println(b2.toString());
13+
14+
b1.setX(1.1);
15+
b1.setY(2.2);
16+
System.out.println(b1.toString());
17+
18+
System.out.println(b1.toString());
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.mirea.practice.s230k754.lab2.task3;
2+
3+
public class Circle {
4+
private double radius;
5+
private double x;
6+
private double y;
7+
8+
public Circle(double radius, double x, double y) {
9+
this.radius = radius;
10+
this.x = x;
11+
this.y = y;
12+
}
13+
14+
public double getX() {
15+
return x;
16+
}
17+
18+
public double getY() {
19+
return y;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "x = " + x + "\ty = " + y + "\tradius = " + radius;
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s230k754.lab2.task3;
2+
3+
public class Point {
4+
private double x;
5+
private double y;
6+
7+
public Point(double x, double y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
public double getX() {
13+
return x;
14+
}
15+
16+
public double getY() {
17+
return y;
18+
}
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ru.mirea.practice.s230k754.lab2.task3;
2+
3+
import java.util.Objects;
4+
5+
public class Tester {
6+
private Circle[] arr;
7+
private int count;
8+
9+
public Tester(int count) {
10+
this.arr = new Circle[count];
11+
this.count = 0;
12+
}
13+
14+
public void append(double r, double x, double y) {
15+
if (count == arr.length) {
16+
System.out.println("Массив заполнен");
17+
return;
18+
}
19+
this.arr[this.count] = new Circle(r, x, y);
20+
this.count += 1;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
String str = "";
26+
for (int i = 0; i < this.count; i++) {
27+
str += "Circle " + Objects.toString(i + 1) + ": " + arr[i].toString() + "\n";
28+
}
29+
return str;
30+
}
31+
}

0 commit comments

Comments
 (0)