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

Commit 761d309

Browse files
authored
Merge pull request #75 from AndrewSkrypov/features/lab4
Features/lab4
2 parents fc83695 + 1d6a4f5 commit 761d309

Some content is hidden

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

67 files changed

+2097
-0
lines changed

students/23K0368/23K0368-p03/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>23K0368</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0368-p03</artifactId>
12+
<description>Третье задание</description>
13+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Arrays;
4+
import java.util.Random;
5+
6+
public abstract class First {
7+
public static void main(String[] args) {
8+
Float[] array1 = new Float[10];
9+
Random random = new Random();
10+
11+
for (int i = 0; i < 10; i++) {
12+
array1[i] = random.nextFloat();
13+
}
14+
System.out.println("1 Массив, созданный с помощью класса Random(): ");
15+
System.out.println(Arrays.toString(array1));
16+
array1 = Arrays.stream(array1).sorted().toArray(Float[]::new);
17+
System.out.println(Arrays.toString(array1));
18+
19+
System.out.println();
20+
Float[] array2 = new Float[10];
21+
22+
for (int i = 0; i < 10; i++) {
23+
array2[i] = (float) Math.random();
24+
}
25+
System.out.println("2 Массив, созданный с помощью метода random(): ");
26+
System.out.println(Arrays.toString(array2));
27+
array2 = Arrays.stream(array2).sorted().toArray(Float[]::new);
28+
System.out.println(Arrays.toString(array2));
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Random;
6+
import java.util.Scanner;
7+
8+
public abstract class Fourth {
9+
public static void main(String[] args) {
10+
try (Scanner sc = new Scanner(System.in)) {
11+
int n = 0;
12+
System.out.println("Введите число: ");
13+
while (n == 0) {
14+
if (sc.hasNextInt()) {
15+
n = sc.nextInt();
16+
} else {
17+
System.out.println("Введите число!");
18+
}
19+
}
20+
21+
Integer[] array = new Integer[n];
22+
Random random = new Random();
23+
for (int i = 0; i < n; i++) {
24+
array[i] = random.nextInt(n);
25+
}
26+
System.out.println(Arrays.toString(array));
27+
28+
ArrayList<Integer> list = new ArrayList<>();
29+
for (int i = 0; i < n; i++) {
30+
if (array[i] % 2 == 0) {
31+
list.add(array[i]);
32+
}
33+
}
34+
System.out.println(list);
35+
}
36+
}
37+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Formatter;
4+
5+
public abstract class Test {
6+
public static void main(String[] args) {
7+
double x = 1000.0 / 3.0;
8+
System.out.println("Строка без форматирования: " + x);
9+
try (Formatter formatter = new Formatter()) {
10+
formatter.format("Строка c форматированием: %.2f%n", x);
11+
formatter.format("Строка c форматированием: %8.2f%n", x);
12+
formatter.format("Строка c форматированием: %16.2f%n", x);
13+
System.out.println(formatter);
14+
}
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Arrays;
4+
import java.util.Random;
5+
6+
public abstract class Third {
7+
public static void main(String[] args) {
8+
Integer[] array = new Integer[4];
9+
Random random = new Random();
10+
11+
for (int i = 0; i < array.length; i++) {
12+
array[i] = random.nextInt(100);
13+
}
14+
System.out.println(Arrays.toString(array));
15+
16+
int cmt = 0;
17+
for (int i = 1; i < array.length; i++) {
18+
if (array[i] > array[i - 1]) {
19+
cmt++;
20+
}
21+
}
22+
if (cmt == array.length) {
23+
System.out.println("Последовательность строго возрастающая");
24+
} else {
25+
System.out.println("Последовательность не строго возрастающая");
26+
}
27+
28+
}
29+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package ru.mirea.practice.s0000001.zadanie1;
2+
3+
public abstract class Obolochki1 {
4+
public static void main(String[] args) {
5+
System.out.println("Задание 1:");
6+
//Задание 1
7+
Double doubleFromstr = Double.valueOf("3.14");
8+
System.out.println(doubleFromstr);
9+
10+
double doubleFromprimetive = 2.182818284590452354;
11+
Double doubleFromdouble = Double.valueOf(String.valueOf(doubleFromprimetive));
12+
System.out.println(doubleFromdouble);
13+
14+
15+
System.out.println();
16+
System.out.println("Задание 2:");
17+
//Задание 2
18+
String str = "10011";
19+
Double d = Double.parseDouble(str);
20+
System.out.println(d);
21+
22+
23+
System.out.println();
24+
System.out.println("Задание 3:");
25+
//Задание 3
26+
Double doubleValue = 123.456;
27+
28+
// Преобразование Double к примитивным типам
29+
byte byteValue = doubleValue.byteValue();
30+
short shortValue = doubleValue.shortValue();
31+
int intValue = doubleValue.intValue();
32+
long longValue = doubleValue.longValue();
33+
float floatValue = doubleValue.floatValue();
34+
double doublePrimitive = doubleValue;
35+
36+
// Вывод результатов
37+
System.out.println("Double: " + doubleValue);
38+
System.out.println("Byte: " + byteValue);
39+
System.out.println("Short: " + shortValue);
40+
System.out.println("Int: " + intValue);
41+
System.out.println("Long: " + longValue);
42+
System.out.println("Float: " + floatValue);
43+
System.out.println("Double (primitive): " + doublePrimitive);
44+
45+
46+
System.out.println();
47+
System.out.println("Задание 5:");
48+
//Задание 5
49+
double pi = 3.14;
50+
String nm5 = Double.toString(pi);
51+
System.out.println(nm5);
52+
}
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.mirea.practice.s0000001.zadanie2;
2+
3+
public class Employe {
4+
String fullname;
5+
double salary;
6+
7+
public Employe(String fullname, double salary) {
8+
this.fullname = fullname;
9+
this.salary = salary;
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s0000001.zadanie2;
2+
3+
public abstract class Employee {
4+
public static void main(String[] args) {
5+
Employe[] employees = {new Employe("Иванов Иван Иванович", 50000.00),
6+
new Employe("Петров Петр Петрович", 65000.50),
7+
new Employe("Сидорова Мария Сергеевна", 48000.75)
8+
};
9+
10+
Report.generateReport(employees);
11+
}
12+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package ru.mirea.practice.s0000001.zadanie2;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Scanner;
6+
7+
public class Main {
8+
9+
private final Map<String, Double> table;
10+
11+
public Main() {
12+
table = new HashMap<>();
13+
table.put("RUS", 1.0);
14+
table.put("USD", 90.93);
15+
table.put("EUR", 100.8);
16+
table.put("GBP", 118.93);
17+
}
18+
19+
public double convert(Double summ, String tmpCurrency, String newCurrency) {
20+
if (!table.containsKey(tmpCurrency) || !table.containsKey(newCurrency)) {
21+
throw new IllegalArgumentException("Неверные коды валют.");
22+
}
23+
24+
return (summ * table.get(tmpCurrency)) / table.get(newCurrency);
25+
}
26+
27+
public static void main(String[] args) {
28+
Main table1 = new Main();
29+
System.out.println("Валюты на выбор: " + table1.table);
30+
try (Scanner sc = new Scanner(System.in)) {
31+
32+
System.out.println("Введите сумму");
33+
double summ = sc.nextDouble();
34+
System.out.println("Введите исходную валюту");
35+
String tmpCurrency = sc.next();
36+
System.out.println("Введите конечную валюту");
37+
String newCurrency = sc.next();
38+
39+
40+
double newSumm = table1.convert(summ, tmpCurrency, newCurrency);
41+
System.out.println(summ + " " + tmpCurrency + " = " + newSumm + " " + newCurrency);
42+
}
43+
}
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ru.mirea.practice.s0000001.zadanie2;
2+
3+
public abstract class Report {
4+
public static void generateReport(Employe[] employees) {
5+
System.out.println("------------------------------------");
6+
System.out.println("Отчет о зарплате сотрудников:");
7+
System.out.println("------------------------------------");
8+
System.out.println("\t\tФИО\t\t\t\tЗарплата");
9+
System.out.println("------------------------------------");
10+
for (Employe employee : employees) {
11+
System.out.printf("%-20s %10.2f\n", employee.fullname, employee.salary);
12+
}
13+
System.out.println("------------------------------------");
14+
}
15+
}

0 commit comments

Comments
 (0)