Skip to content
Open
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
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/java-first-project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Task2_and_Task3/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Task2_and_Task3/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Task2_and_Task3/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Task2_and_Task3/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions Task2_and_Task3/Java task.java
Original file line number Diff line number Diff line change
@@ -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<Product> list;

Cart(){
list = new ArrayList<Product>();
}

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();
}
}


68 changes: 68 additions & 0 deletions Task2_and_Task3/Task2.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
11 changes: 11 additions & 0 deletions Task2_and_Task3/Task2_and_Task3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
53 changes: 53 additions & 0 deletions Task2_and_Task3/Task3.java
Original file line number Diff line number Diff line change
@@ -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());
42 changes: 12 additions & 30 deletions first-project/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -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());

}
}
} else {
System.out.println( c);
}
15 changes: 15 additions & 0 deletions first-project/src/main/java/org/example/Max_of_four.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
11 changes: 11 additions & 0 deletions first-project/src/main/java/org/org.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="org" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>