Compare commits

..

1 Commits

Author SHA1 Message Date
lesflq b25ceea45d
Add files via upload 2023-02-26 13:15:56 +02:00
16 changed files with 50 additions and 192 deletions

11
lab1/lab1.iml Normal file
View File

@ -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$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

38
lab1/src/Main.java Normal file
View File

@ -0,0 +1,38 @@
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
/* Номер залікової книжки - 2425,
C2 = 1, C3 = 1 = C,C5 = 0, C7 = 3, index's type = long */
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
public static void main(String[] args) {
//System.out.println("Перед тим як вводити значення враховуйте умову: 0 < a <= n\n 0 <= b <= m");
System.out.print("\nВеддіть ваше значення a: ");
Scanner a1 = new Scanner(System.in);
int a = a1.nextInt();
System.out.print("\nВеддіть ваше значення b: ");
Scanner b1 = new Scanner(System.in);
int b = b1.nextInt();
System.out.print("\nВеддіть ваше значення m: ");
Scanner m1 = new Scanner(System.in);
int m = m1.nextInt();
System.out.print("\nВеддіть ваше значення n: ");
Scanner n1 = new Scanner(System.in);
int n = n1.nextInt();
double S = 0;
final int C = 1; //Const
if (b >= 0 && a <= n && b <= m && a > 1) {
for (long i = a; i <= n; i++) {
for (long j = b; j <= m; j++) {
S += (double) (i * j) / (i - C);
}
}
System.out.println("Значення S = " + DECIMAL_FORMAT.format(S));
} else {
System.out.println("Значення А має бути > 0\nЗначення А має бути <= n");
System.out.println("Значення B має бути >= 0\nЗначення B має бути <= m");
}
}
}

View File

@ -3,33 +3,6 @@ public class Main {
System.out.println(args[2]);
System.out.println("Hello world!");
// System.out.println(1);
int a = 1;
int b = 2;
int c = 1;
int d = 1;
System.out.println(2&1);
System.out.println(2|1);
int aa = 2;
/*if (aa) {
}*/
// System.out.println("a"&"b");
System.out.println('a'&'b');
if ((a > b) & MyBooleanMethod()) {
System.out.println("?????????????????????????");
}
}
static boolean MyBooleanMethod() {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return true;
}
void myFunction() {

View File

@ -2,8 +2,4 @@ package encapsulationInheritancePolymorphism.inheritance;
public class ElectricEngine extends Engine {
private String batteryType;
/*private class Engine {
private int power;
}*/
}

View File

@ -1,5 +0,0 @@
package encapsulationInheritancePolymorphism.inheritance;
public class FuelEngine extends Engine {
private String fuelType;
}

View File

@ -2,7 +2,6 @@ package encapsulationInheritancePolymorphism.inheritance;
public class Main {
public static void main(String[] args) {
ElectricEngine electricEngine = new ElectricEngine(); // створення нового об'єкту (екземпляру) класу ElectricEngine
FuelEngine fuelEngine = new FuelEngine();
ElectricEngine electricEngine = new ElectricEngine();
}
}

View File

@ -1,14 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism;
public class ElectricEngine extends Engine {
private String batteryType;
@Override
public int getPower() {
return 20;
}
/*private class Engine {
private int power;
}*/
}

View File

@ -1,9 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism;
public class Engine {
private int power;
public int getPower() {
return power;
}
}

View File

@ -1,10 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism;
public class FuelEngine extends Engine {
private String fuelType;
@Override
public int getPower() {
return 50;
}
}

View File

@ -1,38 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism;
/*import encapsulationInheritancePolymorphism.inheritance.ElectricEngine;
import encapsulationInheritancePolymorphism.inheritance.FuelEngine;*/
public class Main {
public static void main(String[] args) {
/*encapsulationInheritancePolymorphism.inheritance.*/ElectricEngine electricEngine = new ElectricEngine(); // створення нового об'єкту (екземпляру) класу ElectricEngine
/*encapsulationInheritancePolymorphism.inheritance.*/FuelEngine fuelEngine = new FuelEngine();
Engine engine1 = fuelEngine;
Engine[] engines = {
electricEngine,
fuelEngine
};
for (Engine engine : engines) {
System.out.println(engine.getPower());
}
/*for (int i = 0; i < engines.length; i++) {
System.out.println(engines[i].getPower());
}*/
// +
int a = 1;
int b = 1;
int c = a + b;
System.out.println(c);
String sA = "1";
String sB = "1";
String sC = sA + sB;
System.out.println(sC);
}
}

View File

@ -1,19 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism.enhanced;
public class ElectricEngine extends Engine {
private String batteryType;
private int chargeLevel = 9;
private int criticalChargeLevel = 10;
private float coefficientCriticalPowerCut = 0.1f;
@Override
public int getPower() {
return chargeLevel > criticalChargeLevel
? super.getPower()
: (int) (super.getPower() * coefficientCriticalPowerCut);
}
/*private class Engine {
private int power;
}*/
}

View File

@ -1,9 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism.enhanced;
public class Engine {
private int power = 100;
public int getPower() {
return power;
}
}

View File

@ -1,10 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism.enhanced;
public class FuelEngine extends Engine {
private String fuelType;
/*public int getPower() {
return 50;
}*/
}

View File

@ -1,28 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism.enhanced;
/*import encapsulationInheritancePolymorphism.inheritance.ElectricEngine;
import encapsulationInheritancePolymorphism.inheritance.FuelEngine;*/
public class Main {
public static void main(String[] args) {
/*encapsulationInheritancePolymorphism.inheritance.*/
ElectricEngine electricEngine = new ElectricEngine(); // створення нового об'єкту (екземпляру) класу ElectricEngine
/*encapsulationInheritancePolymorphism.inheritance.*/
FuelEngine fuelEngine = new FuelEngine();
Engine engine1 = fuelEngine;
Engine[] engines = {
electricEngine,
fuelEngine
};
for (Engine engine : engines) {
System.out.println(engine.getPower());
}
/*for (int i = 0; i < engines.length; i++) {
System.out.println(engines[i].getPower());
}*/
}
}

View File

@ -1,17 +0,0 @@
package encapsulationInheritancePolymorphism.polymorphism.overload;
public class MyClassForOverloadExample {
void myMethod(int a) {
System.out.println("Integer: " + a);
}
void myMethod(double a) {
System.out.println("Double: " + a);
}
public static void main(String[] args) {
MyClassForOverloadExample overload = new MyClassForOverloadExample();
overload.myMethod(1);
overload.myMethod(0.1);
}
}