Skip to content

Commit

Permalink
Practics 11,13,14,18-20 com1
Browse files Browse the repository at this point in the history
  • Loading branch information
egork committed Nov 2, 2024
1 parent d9aeb9e commit 20322d0
Show file tree
Hide file tree
Showing 29 changed files with 543 additions and 0 deletions.
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p11/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p11</artifactId>
<description>11</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mirea.lab11;

/* Написать программу, выводящую фамилию разработчика, дату и время
получения задания, а также дату и время сдачи задания. Для получения
последней даты и времени использовать класс Date из пакета java.util.*
(Объявление Dated=newDate() или метод System.currentTimeMillis(). */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public abstract class Prac11p1 {
public static void main(String[] args) {
SimpleDateFormat f = new SimpleDateFormat("EEEE, dd.MM.yyyy в HH:mm:ss");
Calendar rec = new GregorianCalendar(2024, Calendar.SEPTEMBER, 4, 9, 0, 0);
Calendar out = Calendar.getInstance();
System.out.println("Разработчик: Сидоров");
System.out.println("Дата получения работы: " + f.format(rec.getTime()));
System.out.println("Дата сдачи работы: " + f.format(out.getTime()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mirea.lab11;

/* Приложение, сравнивающее текущую дату и дату, введенную
пользователем c текущим системным временем */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public abstract class Prac11p2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy");
System.out.print("\nВведите дату(dd.mm.yyyy): ");
String inp = sc.nextLine();
Calendar user = Calendar.getInstance();
if (inp.length() == 10) {
user.set(Calendar.DAY_OF_MONTH, Integer.parseInt(inp.substring(0, 2)));
user.set(Calendar.MONTH, Integer.parseInt(inp.substring(3, 5)) - 1);
user.set(Calendar.YEAR, Integer.parseInt(inp.substring(6)));
Calendar now = Calendar.getInstance();
long u = user.getTimeInMillis();
long n = now.getTimeInMillis();
System.out.println("Разница между " + f.format(user.getTime()) + " и " + f.format(now.getTime())
+ " составляет " + (int) ((double) Math.abs(u - n) / 1000 / 60 / 60 / 24) + " дня.");
} else {
System.out.println("Неверный ввод даты");
System.exit(0);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mirea.lab11;

/* Напишите пользовательский код, который формирует объекты Date и
Calendar по следующим данным, вводимым пользователем:
<Год><Месяц><Число>
<Часы1><минуты> */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public abstract class Prac11p4 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Введите формат вывода даты\nИспользуйте <Год><Месяц><Число><Часы1><минуты>:");
String inp = sc.nextLine();
inp = inp.replace("<Год>", "yyyy");
inp = inp.replace("<Месяц>", "MM");
inp = inp.replace("<Число>", "dd");
inp = inp.replace("<Часы1>", "hh");
inp = inp.replace("<минуты>", "mm");
SimpleDateFormat f = new SimpleDateFormat(inp);
System.out.println("Текущая дата:\n" + f.format(Calendar.getInstance().getTime()));
}
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p13/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p13</artifactId>
<description>13</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package mirea.lab13;

import java.util.Locale;
import java.util.Scanner;

public abstract class Prac13p1 {
public static String p1(String s) {
return s;
}

public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Введите строку: ");
String s = sc.nextLine();
System.out.println("P1: " + p1(s));
System.out.println("P2: " + s.charAt(s.length() - 1));
System.out.println("P3: " + s.endsWith("!!!"));
System.out.println("P4: " + s.startsWith("I like"));
System.out.println("P5: " + s.contains("Java"));
System.out.println("P6: " + s.lastIndexOf("Java"));
System.out.println("P7: " + s.replace("a", "o"));
System.out.println("P8: " + s.toUpperCase(Locale.getDefault()));
System.out.println("P9: " + s.toLowerCase(Locale.getDefault()));
System.out.println("P10: " + s.substring(s.lastIndexOf("Java"), s.lastIndexOf("Java") + 4));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mirea.lab13;

public abstract class Prac13p5 {
public static String phoneFormat(String p) {
if (p.startsWith("8")) {
p = p.replaceFirst("8", "+7");
}
if (p.startsWith("+")) {
return p.substring(0, 2) + " " + p.substring(2, 5) + "-" + p.substring(5, 8) + "-" + p.substring(8);
} else {
return " ";
}
}

public static void main(String[] args) {
System.out.println(phoneFormat("+71346644453"));
System.out.println(phoneFormat("89653050013"));
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p14/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p14</artifactId>
<description>14</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mirea.lab14;

import java.util.Scanner;

/* Написать регулярное выражение, определяющее является ли данная
строка строкой "abcdefghijklmnopqrstuv18340" или нет. */

public abstract class Prac14p2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
String ex = "abcdefghijklmnopqrstuv18340";
System.out.print("Введите строку: ");
String inp = sc.nextLine();
if (inp.matches(ex)) {
System.out.println("Строка совпадает с " + ex);
} else {
System.out.println("Строка не совпадает с " + ex);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mirea.lab14;

import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Scanner;

/* Дан текст со списками цен. Извлечь из него цены в USD, RUВ, EU */

public abstract class Prac14p3 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {

Pattern p = Pattern.compile("(\\d+\\.\\d\\d ((USD)|(RUB)|(EU)))");
System.out.print("Введите строку: ");
String inp = sc.nextLine();
Matcher m = p.matcher(inp);
if (m.find()) {
System.out.println(m.group(1));
}
}
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p18/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p18</artifactId>
<description>18</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mirea.lab18.p1;

public class Exception1 {
public void exceptionDemo() {
try {
System.out.println(2.0 / 0.0);
} catch (ArithmeticException e) {
System.out.println("Attempted division by zero");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mirea.lab18.p1;

public abstract class Prac18p1 {
public static void main(String[] args) {
new Exception1().exceptionDemo();
}
}

/*
* При делении целого числа на ноль вызывается исключение ArithmeticException
* При делении числа с плавующей точкой на ноль возвращается Infinity
* */
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mirea.lab18.p2;

import java.util.Scanner;

public class Exception2 {
public void exceptionDemo() {
try (Scanner myScanner = new Scanner(System.in)) {
System.out.print("Enter an integer ");
String intString = myScanner.next();
try {
int i = Integer.parseInt(intString);
System.out.println(2 / i);
} catch (NumberFormatException e) {
System.out.println("Input is not an integer!");
} catch (ArithmeticException e) {
System.out.println("Division by zero!");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mirea.lab18.p2;

public abstract class Prac18p2 {
public static void main(String[] args) {
new Exception2().exceptionDemo();
}
}

/*
* При вводе qwerty: NumberFormatException, невозможно преобразовать строку qwerty в Int
* При вводе 0: ArithmeticException, попытка деления на 0
* При вводе 1.2: NumberFormatException невозможно преобразовать 1.2 в Int
* При вводе 1: Нет ошибок
* */
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p19/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p19</artifactId>
<description>19</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mirea.lab19.p1;

public class InnException extends RuntimeException {
public InnException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mirea.lab19.p1;

import java.util.Scanner;

public abstract class Prac19p1 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Введите ФИО: ");
String name = sc.nextLine();
System.out.print("\nВведите ИНН: ");
String inn = sc.nextLine();
if (inn == null || !inn.matches("\\d{10}")) {
throw new InnException("Введён неверный ИНН: " + inn);
}
System.out.printf("\nЗаказ успешно создан для:\n%s\nИНН: %s", name, inn);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mirea.lab19.p2;

public class EmptyStringException extends RuntimeException {
public EmptyStringException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mirea.lab19.p2;

import java.util.ArrayList;
import java.util.List;

public class LabClass {
private List<Student> students;

LabClass() {
this.students = new ArrayList<>();
}

public void stadd(String name, int gpa) {
students.add(new Student(name, gpa));
}

public String stfind(String name) {
if (name.trim().isEmpty()) {
throw new EmptyStringException("Строка ФИО пустая!");
}
for (Student i : students) {
if (i.getName().equalsIgnoreCase(name)) {
return i.toString();
}
}
throw new StudentNotFoundException("Студент " + name + " не найден.");
}

public void stlist() {
System.out.println("Текущий список студентов:");
for (Student i : students) {
System.out.println(i.toString());
}
}

public List<Student> stsortgpa() {
students.sort(new StdComparator());
return students;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mirea.lab19.p2;

public abstract class LabClassDriver {
public static void main(String[] args) {
LabClassUI l = new LabClassUI();
l.menu();

}
}
Loading

0 comments on commit 20322d0

Please sign in to comment.