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

Commit 8a1feed

Browse files
authored
Merge pull request #1 from marina-devel/features/lab3
Лабораторная работа №2,3,4.1
2 parents f8c66f3 + a473a10 commit 8a1feed

File tree

39 files changed

+1057
-13
lines changed

39 files changed

+1057
-13
lines changed

students/23K0346/23K0346-p02/src/main/java/ru/mirea/practice/s0000001/Main.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
class Author {
4+
private String name;
5+
private String email;
6+
private char gender;
7+
8+
public Author(String name, String email, char gender) {
9+
this.name = name;
10+
this.email = email;
11+
this.gender = gender;
12+
}
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public String getEmail() {
19+
return email;
20+
}
21+
22+
public void setEmail(String email) {
23+
this.email = email;
24+
}
25+
26+
public char getGender() {
27+
return gender;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return "Author[name=" + name + ", email=" + email + ", gender=" + gender + "]";
33+
}
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.mirea.practice.s0000001.task1;
2+
3+
public abstract class TestAuthor {
4+
public static void main(String[] args) {
5+
Author author = new Author("John Joh", "john@gmail.com", 'M');
6+
System.out.println(author);
7+
author.setEmail("john@gmail.com");
8+
System.out.println(author);
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001.task10;
2+
3+
import java.util.Scanner;
4+
5+
public abstract class HowMany {
6+
public static void main(String[] args) {
7+
try (Scanner scanner = new Scanner(System.in)) {
8+
System.out.println("Enter a sentence:");
9+
String input = scanner.nextLine();
10+
11+
String[] words = input.trim().split("\\s+");
12+
System.out.println("Number of words: " + words.length);
13+
}
14+
}
15+
}
16+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ru.mirea.practice.s0000001.task2;
2+
3+
public class Ball {
4+
private double x = 0.0;
5+
private double y = 0.0;
6+
7+
public Ball() {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
13+
public double getX() {
14+
return x;
15+
}
16+
17+
public void setX(double x) {
18+
this.x = x;
19+
}
20+
21+
public double getY() {
22+
return y;
23+
}
24+
25+
public void setY(double y) {
26+
this.y = y;
27+
}
28+
29+
public void setXY(double x, double y) {
30+
this.x = x;
31+
this.y = y;
32+
}
33+
34+
public void move(double xdisp, double ydisp) {
35+
x += xdisp;
36+
y += ydisp;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "Ball[x=" + x + ", y=" + y + "]";
42+
}
43+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.mirea.practice.s0000001.task2;
2+
3+
public abstract class TestBall {
4+
public static void main(String[] args) {
5+
Ball ball = new Ball();
6+
System.out.println(ball);
7+
ball.move(1.5, -2.0);
8+
System.out.println(ball);
9+
}
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s0000001.task3;
2+
3+
public class Circle {
4+
private Point center;
5+
private double radius;
6+
7+
public Circle(Point center, double radius) {
8+
this.center = center;
9+
this.radius = radius;
10+
}
11+
12+
public Point getCenter() {
13+
return center;
14+
}
15+
16+
public double getRadius() {
17+
return radius;
18+
}
19+
20+
public void setRadius(double radius) {
21+
this.radius = radius;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return "Circle[center=" + center + ", radius=" + radius + "]";
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001.task3;
2+
3+
public class Point {
4+
private int x;
5+
private int y;
6+
7+
public Point(int x, int y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
public int getX() {
13+
return x;
14+
}
15+
16+
public int getY() {
17+
return y;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "(" + x + ", " + y + ")";
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ru.mirea.practice.s0000001.task3;
2+
3+
public class Tester {
4+
private Circle[] circles;
5+
private int numberOfCircles;
6+
7+
public Tester(int size) {
8+
circles = new Circle[size];
9+
numberOfCircles = 0;
10+
}
11+
12+
public void addCircle(Circle circle) {
13+
if (numberOfCircles < circles.length) {
14+
circles[numberOfCircles++] = circle;
15+
}
16+
}
17+
18+
public void printCircles() {
19+
for (int i = 0; i < numberOfCircles; i++) {
20+
System.out.println(circles[i]);
21+
}
22+
}
23+
24+
public static void main(String[] args) {
25+
Tester tester = new Tester(5);
26+
tester.addCircle(new Circle(new Point(0, 0), 5));
27+
tester.addCircle(new Circle(new Point(2, 3), 10));
28+
tester.printCircles();
29+
}
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ru.mirea.practice.s0000001.task5;
2+
3+
public class Dog {
4+
private String name;
5+
private int age;
6+
7+
public Dog(String name, int age) {
8+
this.name = name;
9+
this.age = age;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public int getAge() {
21+
return age;
22+
}
23+
24+
public void setAge(int age) {
25+
this.age = age;
26+
}
27+
28+
public int getHumanAge() {
29+
return age * 7;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "Dog[name=" + name + ", age=" + age + ", human age=" + getHumanAge() + "]";
35+
}
36+
}

0 commit comments

Comments
 (0)