Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Features/lab29 32 #678

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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<module>students/23K0186</module>
<module>students/23K0755</module>
<module>students/23K1292</module>
<module>students/23L0908</module>

</modules>
<dependencies>
Expand Down
13 changes: 13 additions & 0 deletions students/23L0908/23L0908-p01/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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23L0908</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23L0908-p01</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.mirea.practice.s23l0908;

import java.util.Scanner;

public final class Task3 {
private Task3() {
}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Enter n: ");
int n = scanner.nextInt();
int[] arr = new int[n];
int sum = 0;
for (int i = 0; i < n; i++) {
System.out.print("arr[" + (i + 1) + "] = ");
arr[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
sum += arr[i];
}
double average = (double) sum / n;
System.out.println("Sum: " + sum);
System.out.println("Average: " + average);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ru.mirea.practice.s23l0908;

import java.util.Scanner;

public final class Task4 {

private Task4() {
}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Enter n: ");
int n = scanner.nextInt();
int[] arr = new int[n];
int i = 0;
int sum = 0;
do {
System.out.print("arr[" + i + "] = ");
arr[i] = scanner.nextInt();
sum += arr[i];
i++;
} while (i < n);

i = 0;
int min = arr[0];
int max = arr[0];
while (i < n) {
if (arr[i] < min) {
min = arr[i];
}
if (arr[i] > max) {
max = arr[i];
}
i++;
}

System.out.println("Sum = " + sum);
System.out.println("Min = " + min);
System.out.println("Max = " + max);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.mirea.practice.s23l0908;

public final class Task5 {

private Task5() {
}

public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Doi so dong lenh duoc truyen vao:");
for (int i = 0; i < args.length; i++) {
System.out.println("Doi so " + i + " = " + args[i]);
}
} else {
System.out.println("Doi so khong duoc truyen");
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.mirea.practice.s23l0908;

public final class Task6 {

private Task6() {
// Private constructor to prevent instantiation
}

public static void main(String[] args) {
int n = 10;
double sum = 0.0;
System.out.println("10 number:");
for (int i = 1; i <= n; i++) {
sum += 1.0 / i;
System.out.printf("H%d = %.4f%n", i, sum);
}
System.out.println("Result: " + sum);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.mirea.practice.s23l0908;

import java.util.Scanner;

public final class Task7 {

private Task7() {
// Private constructor to prevent instantiation
}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.println("Enter n: ");
int n = scanner.nextInt();
long result = giaithua(n);
System.out.print("Result: " + result);
}
}

public static long giaithua(int n) {
if (n < 0) {
System.out.println("Cannot calculate factorial for negative numbers!");
return -1;
} else {
long fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
}
}

13 changes: 13 additions & 0 deletions students/23L0908/23L0908-p02/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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23L0908</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23L0908-p02</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.mirea.practice.s23l0908.task;

public class Author {
private String name;
private String email;
private char gender;

public Author(String name, String email, char gender) {
this.name = name;
this.email = email;
this.gender = gender;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public char getGender() {
return gender;
}

public void setGender(char gender) {
this.gender = gender;
}

@Override
public String toString() {
return "Author{"
+
"name='" + name
+ '\''
+
", email='"
+ email
+ '\''
+
", gender="
+ gender
+
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ru.mirea.practice.s23l0908.task;

@SuppressWarnings("unused")
public class Circle {
private double x;
private double y;
private double r;
private String colour;

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}

public double getR() {
return r;
}

public void setR(double r) {
this.r = r;
}

public String getColour() {
return colour;
}

public void setColour(String colour) {
this.colour = colour;
}

// Calculates and returns the perimeter of the circle
public double getPerimeter() {
return 2 * Math.PI * this.r;
}

@Override
public String toString() {
return "Circle{"
+
"x="
+ x
+
", y="
+ y
+
", r="
+ r
+
", colour='"
+ colour
+ '\''
+
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.mirea.practice.s23l0908.task;

public final class TestAuthor {

private TestAuthor() {
}

public static void main(String[] args) {
Author author = new Author("Nguyen", "ok.com", 'm');
System.out.println(author);
author.setEmail("hoangpphong11@gmail.com");
author.setName("Hoang Xuan Phong");
author.setGender('m');
System.out.println("Updated name: " + author.getName());
System.out.println("Updated email: " + author.getEmail());
System.out.println("Updated gender: " + author.getGender());
System.out.println(author);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.mirea.practice.s23l0908.task10;

import java.util.Scanner;

public final class Main {

private Main() {

}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) { // Sử dụng try-with-resources để tự động đóng tài nguyên
System.out.println("Enter a line of text:");
String input = scanner.nextLine();

if (input.trim().isEmpty()) {
System.out.println("You entered 0 words.");
} else {
String[] words = input.trim().split("\\s+");
System.out.println("Number of words entered: " + words.length);
}
}
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.mirea.practice.s23l0908.task2;

public class Ball {
private float x;
private float y;
private float xspeed;
private float yspeed;

@SuppressWarnings("unused")
public Ball() {
this.x = 0.0f;
this.y = 0.0f;
this.xspeed = 1.0f;
this.yspeed = 1.0f;
}

public Ball(float x, float y, float xspeed, float yspeed) {
this.x = x;
this.y = y;
this.xspeed = xspeed;
this.yspeed = yspeed;
}

public void move() {
x += xspeed;
y += yspeed;
}

public void reverse() {
xspeed = -xspeed;
yspeed = -yspeed;
}

public String toString() {
return "Ball {"
+ "x= " + x
+ ", y= " + y
+ ",xSpeed=" + xspeed
+ ",ySpeed=" + yspeed
+ "}";
}
}
Loading
Loading