diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/java-first-project.iml b/.idea/java-first-project.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/java-first-project.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0314a68 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Task2_and_Task3/.idea/.gitignore b/Task2_and_Task3/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/Task2_and_Task3/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/Task2_and_Task3/.idea/misc.xml b/Task2_and_Task3/.idea/misc.xml new file mode 100644 index 0000000..4eb4f51 --- /dev/null +++ b/Task2_and_Task3/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task2_and_Task3/.idea/modules.xml b/Task2_and_Task3/.idea/modules.xml new file mode 100644 index 0000000..43c97f4 --- /dev/null +++ b/Task2_and_Task3/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Task2_and_Task3/.idea/vcs.xml b/Task2_and_Task3/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Task2_and_Task3/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task2_and_Task3/Java task.java b/Task2_and_Task3/Java task.java new file mode 100644 index 0000000..17c02fa --- /dev/null +++ b/Task2_and_Task3/Java task.java @@ -0,0 +1,72 @@ +class Product{ + + String name; + double price; + + Product(String n, double p){ + name = n; + price = p; + } + String getName(){ + return name; + } + double getPrice(){ + return price; + } +} +import java.util.ArrayList; + +class Cart{ + + ArrayList list; + + Cart(){ + list = new ArrayList(); + } + + void add(Product pr){ + list.add(pr); + } + + void del(String name){ + for (int i = 0; i < list.size(); i++){ + if (list.get(i).getName().equals(name)){ + list.remove(i); + return; + } + } + } + double sum(){ + double s = 0; + for (int i = 0; i < list.size(); i++){ + s = s + list.get(i).getPrice(); + } + return s; + } + + void show() { + System.out.println("Ваша корзина:"); + for (int i = 0; i < list.size(); i++){ + System.out.println(list.get(i).getName() + " " + list.get(i).getPrice()); + } + System.out.println("Сумма выбранных товаров = " + sum()); + } +} + +public class Main{ + public static void main(String[] args){ + + Product a = new Product("Яблоко", 15); + Product b = new Product("Банан", 24); + Product c = new Product("Як", 1500000); + Cart k = new Cart(); + k.add(a); + k.add(b); + k.add(c); + k.show(); + k.del("Яблоко"); + k.show(); + } +} + + diff --git a/Task2_and_Task3/Task2.java b/Task2_and_Task3/Task2.java new file mode 100644 index 0000000..8a9c784 --- /dev/null +++ b/Task2_and_Task3/Task2.java @@ -0,0 +1,68 @@ + class Rectangle{ + double width; + double height; + + Rectangle(double w, double h){ + if (w <= 0 || h <= 0){ + throw new RuntimeException("Введены неправильнык параметры фигуры"); + } + width = w; + height = h; + } + + double S(){ + return width * height; + } + + double P(){ + return 2 * (width + height); + } + } + class Triangle{ + double gip; + double kat1; + double kat2; + + Triangle(double a, double b, double c){ + if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || a + c <= b || b + c <= a){ + throw new RuntimeException("Введены неправильные параметыр фигуры"); + } + gip = a; + kat1 = b; + kat2 = c; + } + + double P(){ + return gip + kat1 + kat2; + } + + double S(){ + double p = P() / 2; + return Math.sqrt(p * (p - gip) * (p - kat1) * (p - kat2)); + } + } + class Circle{ + double radius; + + Circle(double r){ + if (r <= 0){ + throw new RuntimeException("Введены неправильнык параметры"); + } + radius = r; + } + + double S(){ + return 3.14 * radius * radius; + } + + double P(){ + return 2 * 3.14 * radius; + } + } + public class Main { + public static void main(String[] args) { + Rectangle R = new Rectangle(4, 5); + System.out.println("Rectangle area: " + R.S()); + System.out.println("Rectangle perimeter: " + R.P()); + } + } \ No newline at end of file diff --git a/Task2_and_Task3/Task2_and_Task3.iml b/Task2_and_Task3/Task2_and_Task3.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/Task2_and_Task3/Task2_and_Task3.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Task2_and_Task3/Task3.java b/Task2_and_Task3/Task3.java new file mode 100644 index 0000000..f461840 --- /dev/null +++ b/Task2_and_Task3/Task3.java @@ -0,0 +1,53 @@ +class korobkastrok { + + private String[] stroki; + private int count; + private int totalLength; + + korobkastrok(int amount) { + stroki = new String[amount]; + count = 0; + totalLength = 0; + } + void add(String string) { + if (count == stroki.length) { + throw new RuntimeException("Коробка строк заполнена"); + } + int cor = count; + for (int i = count - 1; i >= 0; i--) { + if (stroki[i].length() > string.length()) { + stroki[i + 1] = stroki[i]; + cor = i; + } else { + break; + } + } + stroki[cor] = string; + count++; + totalLength += string.length(); + } + + String maxLength() { + if (count == 0) { + return null; + } + return stroki[count - 1]; + } + + double avgLength() { + if (count == 0) { + return 0; + } + return (double) totalLength / count; + } +} + + + +//korobkastrok m = new korobkastrok(5); +//m.add("Яблоко"); +//m.add("Банан"); +//m.add("Як"); +// +//System.out.println(m.maxLength()); +//System.out.println(m.avgLength()); \ No newline at end of file diff --git a/first-project/src/main/java/org/example/Main.java b/first-project/src/main/java/org/example/Main.java index b150994..f6e7563 100644 --- a/first-project/src/main/java/org/example/Main.java +++ b/first-project/src/main/java/org/example/Main.java @@ -1,33 +1,15 @@ -package org.example; +public class MaxOf3Num { + int a; + int b; + int c; -public class Main { - public static void main(String[] args) { - int a = -1; - int b = 2; - double d = 2.2; - float f = 2.2f; - String s = "just-string"; - boolean l = true; -// System.out.println(a + b); + void findMax (int a, int b, int c) { -// if (a > 0) { -// System.out.println(a); -// }else{ -// System.out.println("a<=0"); -// } -// int i = 0; -// while(i < 10){ -// System.out.println(i); -// i++; -// } + if (a > b && a > c) { + System.out.println( a); + } else if (b > c) { + System.out.println( b); - Human human = new Human(30, 180); - Human human1 = new Human(29, 179); - Human baby1 = new Human(55); - - - System.out.println(baby1.olderThan18()); - System.out.println(human.getAge()); - - } -} \ No newline at end of file + } else { + System.out.println( c); + } \ No newline at end of file diff --git a/first-project/src/main/java/org/example/Max_of_four.java b/first-project/src/main/java/org/example/Max_of_four.java new file mode 100644 index 0000000..0575af4 --- /dev/null +++ b/first-project/src/main/java/org/example/Max_of_four.java @@ -0,0 +1,15 @@ +package org.example; + +public class Main { + static void main() { + int[] arr = {1, 5, 3, 9, 2}; + int max = arr[0]; + for (int i = 1; i < arr.length; i++) { + if (arr[i] > max) { + max = arr[i]; + } + } + System.out.println(max); + } + } +} \ No newline at end of file diff --git a/first-project/src/main/java/org/org.iml b/first-project/src/main/java/org/org.iml new file mode 100644 index 0000000..eb5178e --- /dev/null +++ b/first-project/src/main/java/org/org.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file