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

Commit 7700565

Browse files
authored
Merge pull request #607 from ImSpaceLover/features/lab24
Лабораторная №24
2 parents 0f5d4a7 + ba3aefe commit 7700565

File tree

13 files changed

+165
-0
lines changed

13 files changed

+165
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0120</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0120-p24</artifactId>
12+
<description>Порождающие паттерны</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0120;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("Двадцать четвёртая практическая работа!");
11+
}
12+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
4+
public class Complex {
5+
private double real;
6+
private double imag;
7+
8+
public Complex(double real, double imag) {
9+
this.real = real;
10+
this.imag = imag;
11+
}
12+
13+
public Complex() {
14+
this.real = 0;
15+
this.imag = 0;
16+
}
17+
18+
public double getReal() {
19+
return real;
20+
}
21+
22+
public void setReal(double real) {
23+
this.real = real;
24+
}
25+
26+
public double getImag() {
27+
return imag;
28+
}
29+
30+
public void setImag(double imag) {
31+
this.imag = imag;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
String complexString;
37+
if (imag >= 0) {
38+
complexString = String.format("%f + %fi", real, imag);
39+
} else {
40+
complexString = String.format("%f - %fi", real, Math.abs(imag));
41+
}
42+
return complexString;
43+
}
44+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
public interface ComplexAbstractFactory {
4+
Complex createComplex();
5+
6+
Complex createComplex(int real, int imag);
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
public class ComplexFactory implements ComplexAbstractFactory {
4+
@Override
5+
public Complex createComplex() {
6+
return new Complex();
7+
}
8+
9+
@Override
10+
public Complex createComplex(int real, int imag) {
11+
return new Complex(real, imag);
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.mirea.practice.s23k0120.task2;
2+
3+
public abstract class AbstractChairFactory {
4+
abstract VictorianChair createVictorianChair(int age);
5+
6+
abstract MagicChair createMagicChair();
7+
8+
abstract FunctionalChair createFunctionalChair();
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.mirea.practice.s23k0120.task2;
2+
3+
public interface Chair {
4+
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s23k0120.task2;
2+
3+
public class ChairFactory extends AbstractChairFactory {
4+
5+
@Override
6+
VictorianChair createVictorianChair(int age) {
7+
return new VictorianChair(age);
8+
}
9+
10+
@Override
11+
MagicChair createMagicChair() {
12+
return new MagicChair();
13+
}
14+
15+
@Override
16+
FunctionalChair createFunctionalChair() {
17+
return new FunctionalChair();
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.mirea.practice.s23k0120.task2;
2+
3+
public class Client {
4+
private Chair chair;
5+
6+
public void sit() {
7+
System.out.printf("The client sat on a %s", chair);
8+
}
9+
10+
public void setChair(Chair chair) {
11+
this.chair = chair;
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.mirea.practice.s23k0120.task2;
2+
3+
public class FunctionalChair {
4+
5+
public int sum(int a, int b) {
6+
return a + b;
7+
}
8+
}

0 commit comments

Comments
 (0)