Compare commits
2 Commits
IO-24/02-Б
...
ІО-24/30-Ф
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7a259d3c6 | ||
|
|
8b6da131a0 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
96
lab1 fedoniuk
Normal file
96
lab1 fedoniuk
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class lab1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int C2, C3, C5;
|
||||||
|
var C7 = 0;
|
||||||
|
|
||||||
|
Scanner id = new Scanner(System.in);
|
||||||
|
System.out.print("Enter the student's ID number: ");
|
||||||
|
int idbook = id.nextInt();
|
||||||
|
|
||||||
|
C2 = idbook % 2;
|
||||||
|
C3 = idbook % 3;
|
||||||
|
C5 = idbook % 5;
|
||||||
|
C7 = idbook % 7;
|
||||||
|
|
||||||
|
String[] oper1 = {"+", "-"};
|
||||||
|
String[] oper2 = {"*", "/", "%", "+", "-"};
|
||||||
|
String[] oper3 = {"byte", "short", "int", "long", "char", "float", "double"};
|
||||||
|
|
||||||
|
int C = C3;
|
||||||
|
|
||||||
|
String O1 = oper1[C2];
|
||||||
|
String O2 = oper2[C5];
|
||||||
|
String O3 = oper3[C7];
|
||||||
|
|
||||||
|
System.out.println("C2 is: " + C2 + ", operation is: " + O1);
|
||||||
|
System.out.println("C3 = " + C);
|
||||||
|
System.out.println("C5 is: " + C5 + ", operation is: " + O2);
|
||||||
|
System.out.println("C7 is: " + C7 + ", Type of indexes i and j is: " + O3);
|
||||||
|
|
||||||
|
double i = 0;
|
||||||
|
double j = 0;
|
||||||
|
System.out.println("\nEnter a values for lower limits (i and j) in the "+ O3+" type: ");
|
||||||
|
switch (O3) {
|
||||||
|
case "byte" -> {
|
||||||
|
i = id.nextByte();
|
||||||
|
j = id.nextByte();
|
||||||
|
}
|
||||||
|
case "short" -> {
|
||||||
|
i = id.nextShort();
|
||||||
|
j = id.nextShort();
|
||||||
|
}
|
||||||
|
case "int" -> {
|
||||||
|
i = id.nextInt();
|
||||||
|
j = id.nextInt();
|
||||||
|
}
|
||||||
|
case "long" -> {
|
||||||
|
i = id.nextLong();
|
||||||
|
j = id.nextLong();
|
||||||
|
}
|
||||||
|
case "char" -> {
|
||||||
|
i = id.next().charAt(0);
|
||||||
|
j = id.next().charAt(0);
|
||||||
|
}
|
||||||
|
case "float" -> {
|
||||||
|
i = id.nextFloat();
|
||||||
|
j = id.nextFloat();
|
||||||
|
}
|
||||||
|
case "double" -> {
|
||||||
|
i = id.nextDouble();
|
||||||
|
j = id.nextDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("The value of the created variables is: " + i + " and " + j);
|
||||||
|
System.out.println("Enter values for top limits (n and m):");
|
||||||
|
int n, m;
|
||||||
|
n = id.nextInt();
|
||||||
|
m = id.nextInt();
|
||||||
|
|
||||||
|
double sum = 0, res = 0, res2 = 0;
|
||||||
|
|
||||||
|
if ((O1.equals("-") && i + n >= C && i <= C) || i > n || j > m || (C == 0 && i == 0)) {
|
||||||
|
System.out.println("Incorrect input, try another values");
|
||||||
|
} else {
|
||||||
|
for (double a = i; a <= n; a++) {
|
||||||
|
for (double b = j; b <= m; b++) {
|
||||||
|
switch (O1) {
|
||||||
|
case "+" -> res = a + C;
|
||||||
|
case "-" -> res = a - C;
|
||||||
|
}
|
||||||
|
switch (O2) {
|
||||||
|
case "+" -> res2 = a + b;
|
||||||
|
case "-" -> res2 = a - b;
|
||||||
|
case "*" -> res2 = a * b;
|
||||||
|
case "/" -> res2 = a / b;
|
||||||
|
case "%" -> res2 = a % b;
|
||||||
|
}
|
||||||
|
sum += res2 / res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Sum is: " + sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package IO_24._02_Бондаренко_Тарас_Андрійович.lab1;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Lab1 {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// O1 = +
|
|
||||||
// C = 2
|
|
||||||
// O2 = %
|
|
||||||
// i, j = short(-32.768 to 32.768)
|
|
||||||
final int c = 2;
|
|
||||||
double result = 0;
|
|
||||||
Scanner scan = new Scanner(System.in);
|
|
||||||
System.out.print("Enter a: ");
|
|
||||||
int a = scan.nextInt();// Entering a
|
|
||||||
System.out.print("Enter b: ");
|
|
||||||
int b = scan.nextInt();// Entering b
|
|
||||||
System.out.print("Enter n: ");
|
|
||||||
int n = scan.nextInt();// Entering n
|
|
||||||
System.out.print("Enter m: ");
|
|
||||||
int m = scan.nextInt();// Entering m
|
|
||||||
scan.close();
|
|
||||||
|
|
||||||
if (a <= -c && n >= -c || b <= 0 && m >= 0) {
|
|
||||||
System.out.println("Error! Division by zero");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if(a > n || b > m){
|
|
||||||
result = 0;
|
|
||||||
System.out.println(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (short i = (short) a; i <= n; i++) {
|
|
||||||
for (short j = (short) b; j <= m; j++) {
|
|
||||||
result += (double) (i % j) / (i + c); //Calculation of the result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("\ns = " + result); // Outputting the result
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package IO_24._02_Бондаренко_Тарас_Андрійович.lab2;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Lab2 {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// C5 = 2
|
|
||||||
// C7 = 1
|
|
||||||
// C11 = 4
|
|
||||||
Scanner scan = new Scanner(System.in);
|
|
||||||
System.out.print("Enter the number of matrix rows: ");
|
|
||||||
int m = scan.nextInt();
|
|
||||||
System.out.print("Enter the number of matrix columns: ");
|
|
||||||
int n = scan.nextInt();
|
|
||||||
|
|
||||||
System.out.println("\nFilling matrix A:");
|
|
||||||
byte[][] matrixA = new byte[m][n]; // Creating MxN matrix A
|
|
||||||
scanMatrix(matrixA, scan);
|
|
||||||
|
|
||||||
System.out.println("\nMatrix A"); // Printing matrix A
|
|
||||||
printMatrix(matrixA);
|
|
||||||
|
|
||||||
System.out.println("\nFilling matrix B:");
|
|
||||||
byte[][] matrixB = new byte[m][n];// Creating MxN matrix B
|
|
||||||
scanMatrix(matrixB, scan);
|
|
||||||
|
|
||||||
scan.close();
|
|
||||||
|
|
||||||
System.out.println("\nMatrix B:");// Printing matrix B
|
|
||||||
printMatrix(matrixB);
|
|
||||||
|
|
||||||
System.out.println("\nMatrix C:");
|
|
||||||
byte[][] matrixC = new byte[m][n];// Creating matrix C
|
|
||||||
for (byte i = 0; i < m; i++) {
|
|
||||||
for (byte j = 0; j < n; j++) {
|
|
||||||
matrixC[i][j] = (byte) (matrixA[i][j] + matrixB[i][j]);
|
|
||||||
System.out.print(matrixC[i][j] + "\t ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
byte evenSum = 0; // Sum for the largest numbers in even rows
|
|
||||||
byte oddSum = 0;// Sum for the smallest numbers in even rows
|
|
||||||
|
|
||||||
for (byte i = 0; i < matrixC.length; i++) {
|
|
||||||
byte largest = Byte.MIN_VALUE; // variable for largest element
|
|
||||||
byte smallest = Byte.MAX_VALUE;// variable for smallest element
|
|
||||||
for (byte j = 0; j < matrixC[i].length; j++) {
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
smallest = (byte) Math.min(smallest, matrixC[i][j]);
|
|
||||||
} else {
|
|
||||||
largest = (byte) Math.max(largest, matrixC[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
oddSum += smallest;
|
|
||||||
} else {
|
|
||||||
evenSum += largest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("\nSum of the biggest elements: " + evenSum);
|
|
||||||
System.out.println("Sum of the smallest elements: " + oddSum);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void scanMatrix(byte[][] matrix, Scanner scan) { //Method for filling matrix
|
|
||||||
for (byte i = 0; i < matrix.length; i++) {
|
|
||||||
for (byte j = 0; j < matrix[i].length; j++) {
|
|
||||||
System.out.printf("Enter element [%d][%d]", i, i);
|
|
||||||
matrix[i][j] = scan.nextByte();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printMatrix(byte[][] matrix) {//Method for printing matrix
|
|
||||||
for (byte[] row : matrix) {
|
|
||||||
for (byte el : row) {
|
|
||||||
System.out.print(el + "\t ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package IO_24._02_Бондаренко_Тарас_Андрійович.lab3;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Lab3 {
|
|
||||||
// String
|
|
||||||
// Надрукувати слова без повторень заданого тексту в алфавітному порядку за першою літерою.
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Mauris a diam maecenas sed enim ut sem viverra. Amet est placerat in egestas erat imperdiet. Sed turpis tincidunt id aliquet risus. Amet porttitor eget dolor morbi non arcu risus quis. Elementum nibh tellus molestie nunc non blandit massa. Feugiat scelerisque varius morbi enim nunc faucibus. Ipsum faucibus vitae aliquet nec ullamcorper sit amet risus nullam. Quis enim lobortis scelerisque fermentum dui faucibus in. Sem viverra aliquet eget sit amet tellus cras adipiscing enim. Sed ullamcorper morbi tincidunt ornare. Sodales ut eu sem integer vitae justo eget magna. Mi ipsum faucibus vitae aliquet nec ullamcorper.";
|
|
||||||
String[] words = text.split("[\\p{Punct}\\s]+");
|
|
||||||
List<String> wordList = new ArrayList<>(Arrays.asList(words));//Class ArrayList implements interface List
|
|
||||||
// asList returns immutable list
|
|
||||||
Set<String> wordSet = new HashSet<>(wordList);// Class HashSet implements interface Set
|
|
||||||
wordList.clear();
|
|
||||||
wordList.addAll(wordSet);
|
|
||||||
wordList.sort(String::compareToIgnoreCase);
|
|
||||||
|
|
||||||
for (String element : wordList) {
|
|
||||||
System.out.println(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package IO_24._02_Бондаренко_Тарас_Андрійович.lab4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that represents a boat with different characteristics.
|
|
||||||
*/
|
|
||||||
public class Boat {
|
|
||||||
private String name;
|
|
||||||
private int price;
|
|
||||||
private int mass;
|
|
||||||
private int age;
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
public Boat(String name, int price, int mass, int age, String type) {
|
|
||||||
this.name = name;
|
|
||||||
this.price = price;
|
|
||||||
this.mass = mass;
|
|
||||||
this.age = age;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("%s - %s, which was built %d years ago, with mass - %d kg, has price - %d$;",
|
|
||||||
type, name, age, mass, price);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package IO_24._02_Бондаренко_Тарас_Андрійович.lab4;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Lab4 {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
List<Boat> boatList = Arrays.asList(
|
|
||||||
new Boat("Row V. Wave", 150000, 50000, 25, "cutter"),
|
|
||||||
new Boat("Dirty Oar", 250000, 40000, 15, "cutter"),
|
|
||||||
new Boat("Tumeric", 450000, 100000, 45, "cutter"),
|
|
||||||
new Boat("Life is Good", 350000, 20000, 5, "cutter")
|
|
||||||
);
|
|
||||||
|
|
||||||
boatList.sort(Comparator.comparing(Boat::getName));// comparing - method of Comparator interface
|
|
||||||
System.out.println("Sorted by name:");
|
|
||||||
printed(boatList);
|
|
||||||
|
|
||||||
boatList.sort(Comparator.comparing(Boat::getPrice).reversed());
|
|
||||||
System.out.println("\nSorted by price in reverse order:");
|
|
||||||
printed(boatList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Print all characteristics of boats.
|
|
||||||
*
|
|
||||||
* @param boatList List of boats.
|
|
||||||
*/
|
|
||||||
public static void printed(List<Boat> boatList) {
|
|
||||||
for (Boat boat : boatList) {
|
|
||||||
System.out.println(boat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package encapsulationInheritancePolymorphism.inheritance;
|
||||||
|
|
||||||
|
public class ElectricEngine extends Engine {
|
||||||
|
private String batteryType;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package encapsulationInheritancePolymorphism.inheritance;
|
||||||
|
|
||||||
|
public class Engine {
|
||||||
|
private int power;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package encapsulationInheritancePolymorphism.inheritance;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ElectricEngine electricEngine = new ElectricEngine();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user