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

Лабораторная №4 #51

Merged
merged 11 commits into from
Sep 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ private Main() {
}

public static void main(String[] args) {
System.out.println("Первая практическая работа!");
System.out.println("Вторая практическая работа!");
}
}
13 changes: 13 additions & 0 deletions students/23K0120/23K0120-p04/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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0120</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0120-p04</artifactId>
<description>Enum</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0120;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("Четвёртая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.mirea.practice.s23k0120.atelier;

public abstract class Atelier {

public static void dressMan(Clothes[] clothes) {
for (Clothes clothe : clothes) {
if (clothe instanceof MenClothing) {
((MenClothing) clothe).dressMan();
System.out.print('\n');
}
}
}

public static void dressWoman(Clothes[] clothes) {
for (Clothes clothe : clothes) {
if (clothe instanceof WomenClothing) {
((WomenClothing) clothe).dressWoman();
System.out.print('\n');
}
}
}

public static void main(String[] args) {
Clothes[] clothes = new Clothes[4];

clothes[0] = new TShirt(ClothingSizes.XXS, 1000, "Красный");
clothes[1] = new Pants(ClothingSizes.M, 5000, "Синий");
clothes[2] = new Skirt(ClothingSizes.L, 10000, "Чёрный");
clothes[3] = new Tie(ClothingSizes.S, 2000, "Зелёный");

dressMan(clothes);
dressWoman(clothes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.mirea.practice.s23k0120.atelier;


import java.text.NumberFormat;
import java.util.Locale;

public abstract class Clothes {
ClothingSizes size;
float cost;
String color;

public Clothes(ClothingSizes size, float cost, String color) {
this.size = size;
this.cost = cost;
this.color = color;
}

public String getDescription() {
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("ru", "Ru"));
return String.format("%s, Цена: %s, Цвет: %s", size, format.format(cost), color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.mirea.practice.s23k0120.atelier;

public enum ClothingSizes {
XXS(32), XS(34), S(36), M(38), L(40);

final int euroSize;

ClothingSizes(int euroSize) {
this.euroSize = euroSize;
}

public String getDescription() {
if (euroSize >= 34) {
return "Взрослый размер";
} else {
return "Детский размер";
}
}

@Override
public String toString() {
return String.format("%s, %d", getDescription(), this.euroSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.mirea.practice.s23k0120.atelier;

public interface MenClothing {
void dressMan();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.mirea.practice.s23k0120.atelier;

public class Pants extends Clothes implements MenClothing, WomenClothing {
public Pants(ClothingSizes size, float cost, String color) {
super(size, cost, color);
}

@Override
public void dressMan() {
System.out.printf("Мужские Брюки %s", getDescription());
}

@Override
public void dressWoman() {
System.out.printf("Женские Брюки %s", getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0120.atelier;

public class Skirt extends Clothes implements WomenClothing {
public Skirt(ClothingSizes size, float cost, String color) {
super(size, cost, color);
}

@Override
public void dressWoman() {
System.out.printf("Юбка %s", getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s23k0120.atelier;

public class TShirt extends Clothes implements MenClothing, WomenClothing {
public TShirt(ClothingSizes size, float cost, String color) {
super(size, cost, color);
}

@Override
public void dressMan() {
System.out.printf("Мужская Футболка %s", getDescription());
}

@Override
public void dressWoman() {
System.out.printf("Женская Футболка %s", getDescription());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0120.atelier;

public class Tie extends Clothes implements MenClothing {
public Tie(ClothingSizes size, float cost, String color) {
super(size, cost, color);
}

@Override
public void dressMan() {
System.out.printf("Галстук %s", getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.mirea.practice.s23k0120.atelier;

public interface WomenClothing {
void dressWoman();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0120.seasons;

public abstract class Main {
public static void main(String[] args) {
Seasons season = Seasons.SPRING;
System.out.printf("%s, Длится с 1 марта по 31 мая, Второе время года в году\n", season);

for (Seasons s : Seasons.values()) {
System.out.printf("%s, %s\n", s, s.getDescription());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ru.mirea.practice.s23k0120.seasons;

public enum Seasons {
SUMMER(25f),
AUTUMN(5f),
WINTER(-10f),
SPRING(15f);

private final float temperature;

Seasons(float temperature) {
this.temperature = temperature;
}

public float getTemperature() {
return temperature;
}

public static void like(Seasons season) {
String seasonStr;
switch (season) {
case SUMMER:
seasonStr = "лето";
break;
case SPRING:
seasonStr = "весну";
break;
case AUTUMN:
seasonStr = "осень";
break;
case WINTER:
seasonStr = "зиму";
break;
default:
seasonStr = "-";
break;
}
System.out.printf("Я люблю %s\n", seasonStr);
}

public String getDescription() {
String season;
switch (this) {
case SUMMER:
season = "Тёплое";
break;
case SPRING:
season = "Умеренное";
break;
case AUTUMN:
season = "Прохладное";
break;
case WINTER:
season = "Холодное";
break;
default:
season = "-";
break;
}
return String.format("%s время года", season);
}

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

проверка странная, зачем приводить к int?

String season;
switch (this) {
case SUMMER:
season = "Лето";
break;
case SPRING:
season = "Весна";
break;
case AUTUMN:
season = "Осень";
break;
case WINTER:
season = "Зима";
break;
default:
season = "-";
break;
}
return String.format("Время года - %s, Средняя температура - %.2f°C", season, this.temperature);
}
}
13 changes: 13 additions & 0 deletions students/23K0120/23K0120-p04_1/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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>23K0120</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0120-p04_1</artifactId>
<description>Наследование и Абстракция</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0120;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("Четвёртая практическая работа! - часть 2");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.mirea.practice.s23k0120.exercise1;

public class Circle extends Shape {
double radius;

public Circle() {
// Default constructor
}

public Circle(double radius) {
this.radius = radius;
}

public Circle(double radius, String color, boolean filled) {
super(color, filled);
this.radius = radius;
}

public double getRadius() {
return radius;
}

public void setRadius(float radius) {
this.radius = radius;
}

@Override
public double getPerimeter() {
return radius * Math.PI * 2;
}

@Override
public double getArea() {
return radius * radius * Math.PI;
}

@Override
public String toString() {
return "Circle{" + "radius=" + radius + ", color='" + color + '\'' + ", filled=" + filled + '}';
}
}
Loading
Loading