Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/lab17 19 #548

Closed
wants to merge 4 commits into from
Closed
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
25 changes: 25 additions & 0 deletions students/23K1302/23K1302-p17/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p17</artifactId>
<description>Задание 17</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.mirea.practice.s0000001;

import java.util.Scanner;

public class Ex1 {

public static String funk(boolean a) {
if (a) {
return "Список пуст";
} else {
return "Список полон";
}
}

public static void main(String[] args) {
LinkedList list = new LinkedList();
Scanner scanner = new Scanner(System.in);
int choice;

do {
System.out.println("\nМеню:");
System.out.println("1. Добавить элемент");
System.out.println("2. Удалить элемент");
System.out.println("3. Вывести список");
System.out.println("4. Очистить список");
System.out.println("5. Проверить, пуст ли список");
System.out.println("0. Выход");
System.out.print("Выберите опцию: ");
choice = scanner.nextInt();

switch (choice) {
case 1 -> list.addElement();
case 2 -> list.removeElement();
case 3 -> list.displayElements();
case 4 -> list.clearList();
case 5 -> System.out.println(funk(list.isEmpty()));
case 0 -> System.out.println("Выход из программы.");
default -> System.out.println("Неверный выбор. Пожалуйста, попробуйте снова.");
}
} while (choice != 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ru.mirea.practice.s0000001;

public class LinkedList {
private Node head;

public LinkedList() {
this.head = null;
}

public void addElement() {
Node newNode = new Node();
newNode.readAttributes();
newNode.next = head;
head = newNode;
System.out.println("Элемент добавлен.");
}

public void removeElement() {
if (head == null) {
System.out.println("Список пуст.");
return;
}
head = head.next;
System.out.println("Элемент удалён.");
}

public void displayElements() {
if (head == null) {
System.out.println("Список пуст.");
return;
}
Node current = head;
while (current != null) {
current.displayAttributes();
current = current.next;
}
}

public void clearList() {
head = null;
System.out.println("Список очищен.");
}

public boolean isEmpty() {
return head == null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.mirea.practice.s0000001;

import java.util.Scanner;

public class Node {
private String name;
private int age;
public Node next;

public void readAttributes() {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Введите имя: ");
this.name = scanner.nextLine();
System.out.print("Введите возраст: ");
this.age = scanner.nextInt();
} catch (Exception e) {
System.out.println("Ошибка при вводе данных: " + e.getMessage());
}
}

public void displayAttributes() {
System.out.println("Имя: " + name + ", Возраст: " + age);
}
}
13 changes: 13 additions & 0 deletions students/23K1302/23K1302-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>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p18</artifactId>
<description>Задание 18</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.mirea.practice.s0000001;

public class Ex1o1 {
public void exceptionDemo() {
System.out.println(2.0 / 0.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.mirea.practice.s0000001;

public class Ex1o2 {
public void exceptionDemo() {
System.out.println(2.0 / 0.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.mirea.practice.s0000001;

public class Ex1o3 {
public void exceptionDemo() {
try {
System.out.println(2 / 0);
} catch (ArithmeticException e) {
System.out.println("Attempted division by zero");
}
}
}
13 changes: 13 additions & 0 deletions students/23K1302/23K1302-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>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p19</artifactId>
<description>Задание 19</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.mirea.practice.s0000001;

public final class Ex1 {

private Ex1() {
// NONE
}

public static void main(String[] args) {
try {
String inn = "12345967890";

validateInn(inn);
System.out.println("Заказ успешно оформлен!");
} catch (InvalidInnException e) {
System.out.println("Ошибка: " + e.getMessage());
}
}

public static void validateInn(String inn) throws InvalidInnException {
if (inn.length() != 10) {
throw new InvalidInnException("Недействительный ИНН: " + inn);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.mirea.practice.s0000001;

public class InvalidInnException extends Exception {
public InvalidInnException(String message) {
super(message);
}
}
3 changes: 3 additions & 0 deletions students/23K1302/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
<module>23K1302-p14</module>
<module>23K1302-p15</module>
<module>23K1302-p16</module>
<module>23K1302-p17</module>
<module>23K1302-p18</module>
<module>23K1302-p19</module>
</modules>
</project>
Loading