From 04d97dc93848a61c28d46d4ebb703297585702c2 Mon Sep 17 00:00:00 2001 From: Hellissheep Date: Sat, 2 Nov 2024 20:07:13 +0100 Subject: [PATCH] DU3 complete --- src/com/company/Main.java | 48 ++++++++++++------- src/com/company/vesmirnetelesa/Zem.java | 44 +++++++++++++++++ src/com/company/zive_tvory/Bezstavovce.java | 7 +++ src/com/company/zive_tvory/Stavovec.java | 32 +++++++++++++ src/com/company/zive_tvory/Tvor.java | 17 +++++++ src/com/company/zive_tvory/bornable.java | 7 +++ src/com/company/zive_tvory/dieable.java | 7 +++ src/com/company/zive_tvory/hmyz/Hmyz.java | 26 ++++++++++ src/com/company/zive_tvory/hmyz/Mucha.java | 7 +++ src/com/company/zive_tvory/ryby/Kapor.java | 7 +++ src/com/company/zive_tvory/ryby/Losos.java | 7 +++ src/com/company/zive_tvory/ryby/Ryba.java | 27 +++++++++++ .../zive_tvory/stavovce_diely/Chrbtica.java | 18 +++++++ .../zive_tvory/stavovce_diely/Stavec.java | 4 ++ .../zive_tvory/stavovce_diely/Sustava.java | 14 ++++++ .../stavovce_diely/Typ_sustavy.java | 12 +++++ src/com/company/zive_tvory/vtaky/Orel.java | 7 +++ src/com/company/zive_tvory/vtaky/Vtak.java | 27 +++++++++++ 18 files changed, 300 insertions(+), 18 deletions(-) create mode 100644 src/com/company/vesmirnetelesa/Zem.java create mode 100644 src/com/company/zive_tvory/Bezstavovce.java create mode 100644 src/com/company/zive_tvory/Stavovec.java create mode 100644 src/com/company/zive_tvory/Tvor.java create mode 100644 src/com/company/zive_tvory/bornable.java create mode 100644 src/com/company/zive_tvory/dieable.java create mode 100644 src/com/company/zive_tvory/hmyz/Hmyz.java create mode 100644 src/com/company/zive_tvory/hmyz/Mucha.java create mode 100644 src/com/company/zive_tvory/ryby/Kapor.java create mode 100644 src/com/company/zive_tvory/ryby/Losos.java create mode 100644 src/com/company/zive_tvory/ryby/Ryba.java create mode 100644 src/com/company/zive_tvory/stavovce_diely/Chrbtica.java create mode 100644 src/com/company/zive_tvory/stavovce_diely/Stavec.java create mode 100644 src/com/company/zive_tvory/stavovce_diely/Sustava.java create mode 100644 src/com/company/zive_tvory/stavovce_diely/Typ_sustavy.java create mode 100644 src/com/company/zive_tvory/vtaky/Orel.java create mode 100644 src/com/company/zive_tvory/vtaky/Vtak.java diff --git a/src/com/company/Main.java b/src/com/company/Main.java index a3dee05..2a529d4 100644 --- a/src/com/company/Main.java +++ b/src/com/company/Main.java @@ -1,26 +1,38 @@ package com.company; -import com.company.vesmirne_lodi.Mimozemska_lod; -import com.company.vesmirnetelesa.*; + +import com.company.vesmirnetelesa.Planeta; +import com.company.vesmirnetelesa.Zem; +import com.company.zive_tvory.Tvor; +import com.company.zive_tvory.ryby.Kapor; +import com.company.zive_tvory.ryby.Losos; +import com.company.zive_tvory.ryby.Ryba; +import com.company.zive_tvory.vtaky.Orel; +import com.company.zive_tvory.vtaky.Vtak; +import com.company.zive_tvory.hmyz.Mucha; +import java.util.Date; - - -public class Main { +public class Main{ public static void main(String[] args) { - Slnecna_sustava nasaSustava = new Slnecna_sustava("Naša sustava"); + Zem zem = new Zem(); + Kapor vianocnykapor = new Kapor(50); + Losos losos = new Losos(40); + Orel orel = new Orel(30); + Mucha mucha = new Mucha(); + Date dNow = new Date(); - Galaxia MilkyWay = new Galaxia("MilkyWay"); - MilkyWay.addSustava(nasaSustava); - - MilkyWay.addLod(new Mimozemska_lod("Avrora", "Mars", 1300)); - MilkyWay.lodi[0].broadcastSosMessage(); - - Galaxia Korotkyy = new Galaxia("Korotkyy"); - - MilkyWay.lodi[0].broadcastSosMessage(Korotkyy); - - System.out.println("Korotkyy last message: " + Korotkyy.getLast_message()); + vianocnykapor.born(dNow); + zem.addTvor(vianocnykapor); + zem.addTvor(losos); + zem.addTvor(orel); + zem.addTvor(mucha); + vianocnykapor.hybsa(10, 10, 0); + vianocnykapor.die(new Date()); + System.out.println("Vianocny kapor sa narodil " + vianocnykapor.getDate_of_birth()); + for (int i = 0; i < vianocnykapor.getSustavy().length; i++) { + System.out.println(vianocnykapor.getSustavy()[i].getTypSustavy()); + } } -} \ No newline at end of file +} diff --git a/src/com/company/vesmirnetelesa/Zem.java b/src/com/company/vesmirnetelesa/Zem.java new file mode 100644 index 0000000..e8bacf1 --- /dev/null +++ b/src/com/company/vesmirnetelesa/Zem.java @@ -0,0 +1,44 @@ +package com.company.vesmirnetelesa; +import com.company.zive_tvory.Tvor; + +public class Zem extends Planeta { + + private Tvor[] poleTvorov; + private int tvorovCount; + + public Zem() { + super("Zem", 5972200, 12756, 9.81); + this.poleTvorov = new Tvor[100]; + this.tvorovCount = 0; + } + + public Zem(double vaha, double priemer) { + super("Zem", vaha, priemer, 9.81); + this.poleTvorov = new Tvor[100]; + this.tvorovCount = 0; + } + + public Zem(double vaha, double priemer, double gravitacia) { + super("Zem", vaha, priemer, gravitacia); + this.poleTvorov = new Tvor[100]; + this.tvorovCount = 0; + } + + // Метод для добавления создания в массив + public void addTvor(Tvor tvor) { + if (tvorovCount < poleTvorov.length) { + poleTvorov[tvorovCount++] = tvor; + System.out.println("A creature has been added to Earth."); + } else { + System.out.println("No space left for more creatures."); + } + } + + // Дополнительный метод для вывода информации о всех созданиях + public void displayCreatures() { + System.out.println("Displaying all creatures on Earth:"); + for (int i = 0; i < tvorovCount; i++) { + System.out.println("Creature " + (i + 1) + ": " + poleTvorov[i].getClass().getSimpleName()); + } + } +} diff --git a/src/com/company/zive_tvory/Bezstavovce.java b/src/com/company/zive_tvory/Bezstavovce.java new file mode 100644 index 0000000..3ad2f95 --- /dev/null +++ b/src/com/company/zive_tvory/Bezstavovce.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory; + +public abstract class Bezstavovce extends Tvor { + public Bezstavovce() { + super(); + } +} diff --git a/src/com/company/zive_tvory/Stavovec.java b/src/com/company/zive_tvory/Stavovec.java new file mode 100644 index 0000000..a4c4c20 --- /dev/null +++ b/src/com/company/zive_tvory/Stavovec.java @@ -0,0 +1,32 @@ +package com.company.zive_tvory; + +import com.company.zive_tvory.stavovce_diely.Chrbtica; +import com.company.zive_tvory.stavovce_diely.Stavec; +import com.company.zive_tvory.stavovce_diely.Sustava; +import com.company.zive_tvory.stavovce_diely.Typ_sustavy; + +public abstract class Stavovec extends Tvor{ + protected Chrbtica chrbtica; + protected Sustava[] sustavy; + public Stavovec(int pocet_stavcoc){ + chrbtica = new Chrbtica(pocet_stavcoc); + create_sustavy(); + } + + private void create_sustavy() { + sustavy = new Sustava[8]; + + sustavy[0] = new Sustava(Typ_sustavy.OBEHOVA); + sustavy[1] = new Sustava(Typ_sustavy.OPORNA); + sustavy[2] = new Sustava(Typ_sustavy.VYLUCOVACIA); + sustavy[3] = new Sustava(Typ_sustavy.POHYBOVA); + sustavy[4] = new Sustava(Typ_sustavy.DYCHACIA); + sustavy[5] = new Sustava(Typ_sustavy.TRAVIACA); + sustavy[6] = new Sustava(Typ_sustavy.ROZMNOZOVACIA); + sustavy[7] = new Sustava(Typ_sustavy.NERVOVA); + } + + public Sustava[] getSustavy() { + return sustavy; + } +} diff --git a/src/com/company/zive_tvory/Tvor.java b/src/com/company/zive_tvory/Tvor.java new file mode 100644 index 0000000..6844d92 --- /dev/null +++ b/src/com/company/zive_tvory/Tvor.java @@ -0,0 +1,17 @@ +package com.company.zive_tvory; + + +import java.util.Date; + + +public abstract class Tvor implements bornable, dieable{ + protected Date date_of_birth; + protected Date date_of_death; + + public abstract void hybsa(int directionX, int directionY, int directionZ); + + public Date getDate_of_birth() { + return date_of_birth; + } + +} \ No newline at end of file diff --git a/src/com/company/zive_tvory/bornable.java b/src/com/company/zive_tvory/bornable.java new file mode 100644 index 0000000..5d92ed0 --- /dev/null +++ b/src/com/company/zive_tvory/bornable.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory; + +import java.util.Date; + +public interface bornable { + public void born(Date day_of_birth); +} diff --git a/src/com/company/zive_tvory/dieable.java b/src/com/company/zive_tvory/dieable.java new file mode 100644 index 0000000..c0c3302 --- /dev/null +++ b/src/com/company/zive_tvory/dieable.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory; + +import java.util.Date; + +public interface dieable { + public void die(Date day_of_death); +} diff --git a/src/com/company/zive_tvory/hmyz/Hmyz.java b/src/com/company/zive_tvory/hmyz/Hmyz.java new file mode 100644 index 0000000..72ea12a --- /dev/null +++ b/src/com/company/zive_tvory/hmyz/Hmyz.java @@ -0,0 +1,26 @@ +package com.company.zive_tvory.hmyz; + +import com.company.zive_tvory.Bezstavovce; + +import java.util.Date; + +public abstract class Hmyz extends Bezstavovce { + public Hmyz() { + super(); + } + + @Override + public void hybsa(int directionX, int directionY, int directionZ) { + System.out.println("I am flying in directions: " + directionX + ", " + directionY + ", " + directionZ); + } + @Override + public void born(Date day_of_birth){ + super.date_of_birth=day_of_birth; + System.out.println("I was born on" + super.date_of_birth.toString()); + } + @Override + public void die(Date day_of_death){ + super.date_of_death=day_of_death; + System.out.println("I died on " + super.date_of_birth.toString()); + } +} diff --git a/src/com/company/zive_tvory/hmyz/Mucha.java b/src/com/company/zive_tvory/hmyz/Mucha.java new file mode 100644 index 0000000..aee36e4 --- /dev/null +++ b/src/com/company/zive_tvory/hmyz/Mucha.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory.hmyz; + +public class Mucha extends Hmyz { + public Mucha() { + super(); + } +} diff --git a/src/com/company/zive_tvory/ryby/Kapor.java b/src/com/company/zive_tvory/ryby/Kapor.java new file mode 100644 index 0000000..4b950b9 --- /dev/null +++ b/src/com/company/zive_tvory/ryby/Kapor.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory.ryby; + +public class Kapor extends Ryba{ + public Kapor(int pocet_stavcov){ + super(pocet_stavcov); + } +} diff --git a/src/com/company/zive_tvory/ryby/Losos.java b/src/com/company/zive_tvory/ryby/Losos.java new file mode 100644 index 0000000..f4b17f7 --- /dev/null +++ b/src/com/company/zive_tvory/ryby/Losos.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory.ryby; + +public class Losos extends Ryba { + public Losos(int pocet_stavcov){ + super(pocet_stavcov); + } +} diff --git a/src/com/company/zive_tvory/ryby/Ryba.java b/src/com/company/zive_tvory/ryby/Ryba.java new file mode 100644 index 0000000..3f5fa12 --- /dev/null +++ b/src/com/company/zive_tvory/ryby/Ryba.java @@ -0,0 +1,27 @@ +package com.company.zive_tvory.ryby; + +import com.company.zive_tvory.Stavovec; + +import java.util.Date; + +public abstract class Ryba extends Stavovec { + + public Ryba(int pocet_stavcoc){ + super(pocet_stavcoc); + } + + @Override + public void hybsa(int directionX, int directionY, int directionZ) { + System.out.println("The fish is swimming in directions: " + directionX + ", " + directionY + ", " + directionZ); + } + @Override + public void born(Date day_of_birth){ + super.date_of_birth=day_of_birth; + System.out.println("I was born on " + super.date_of_birth.toString()); + } + @Override + public void die(Date day_of_death){ + super.date_of_death=day_of_death; + System.out.println("I died on " + super.date_of_birth.toString()); + } +} diff --git a/src/com/company/zive_tvory/stavovce_diely/Chrbtica.java b/src/com/company/zive_tvory/stavovce_diely/Chrbtica.java new file mode 100644 index 0000000..d2060a5 --- /dev/null +++ b/src/com/company/zive_tvory/stavovce_diely/Chrbtica.java @@ -0,0 +1,18 @@ +package com.company.zive_tvory.stavovce_diely; + +public class Chrbtica { + + private Stavec[] stavce; // Массив для хранения позвонков + + public Chrbtica(int pocetStavcov) { + this.stavce = new Stavec[pocetStavcov]; // Создаем массив с заданным количеством позвонков + for (int i = 0; i < pocetStavcov; i++) { + stavce[i] = new Stavec(); // Заполняем массив экземплярами Stavec + } + } + + // Метод для получения количества позвонков + public int getPocetStavcov() { + return stavce.length; + } +} diff --git a/src/com/company/zive_tvory/stavovce_diely/Stavec.java b/src/com/company/zive_tvory/stavovce_diely/Stavec.java new file mode 100644 index 0000000..baa6d5d --- /dev/null +++ b/src/com/company/zive_tvory/stavovce_diely/Stavec.java @@ -0,0 +1,4 @@ +package com.company.zive_tvory.stavovce_diely; + +public class Stavec { +} diff --git a/src/com/company/zive_tvory/stavovce_diely/Sustava.java b/src/com/company/zive_tvory/stavovce_diely/Sustava.java new file mode 100644 index 0000000..9f33820 --- /dev/null +++ b/src/com/company/zive_tvory/stavovce_diely/Sustava.java @@ -0,0 +1,14 @@ +package com.company.zive_tvory.stavovce_diely; + +public class Sustava { + Typ_sustavy typSustavy; // typ sústavy - jedna z obehová/oporná/vylučovacia ... + + // konštruktor triedy sústava + public Sustava(Typ_sustavy typSustavy) { + this.typSustavy = typSustavy; + } + + public Typ_sustavy getTypSustavy() { + return typSustavy; + } +} diff --git a/src/com/company/zive_tvory/stavovce_diely/Typ_sustavy.java b/src/com/company/zive_tvory/stavovce_diely/Typ_sustavy.java new file mode 100644 index 0000000..63d6d79 --- /dev/null +++ b/src/com/company/zive_tvory/stavovce_diely/Typ_sustavy.java @@ -0,0 +1,12 @@ +package com.company.zive_tvory.stavovce_diely; + +public enum Typ_sustavy { + OPORNA, + OBEHOVA, + VYLUCOVACIA, + POHYBOVA, + DYCHACIA, + TRAVIACA, + ROZMNOZOVACIA, + NERVOVA +} diff --git a/src/com/company/zive_tvory/vtaky/Orel.java b/src/com/company/zive_tvory/vtaky/Orel.java new file mode 100644 index 0000000..9ea92cf --- /dev/null +++ b/src/com/company/zive_tvory/vtaky/Orel.java @@ -0,0 +1,7 @@ +package com.company.zive_tvory.vtaky; + +public class Orel extends Vtak { + public Orel(int pocet_stavcov){ + super(pocet_stavcov); + } +} diff --git a/src/com/company/zive_tvory/vtaky/Vtak.java b/src/com/company/zive_tvory/vtaky/Vtak.java new file mode 100644 index 0000000..23bf47d --- /dev/null +++ b/src/com/company/zive_tvory/vtaky/Vtak.java @@ -0,0 +1,27 @@ +package com.company.zive_tvory.vtaky; + +import com.company.zive_tvory.Stavovec; + +import java.util.Date; + +public abstract class Vtak extends Stavovec { + + public Vtak(int pocet_stavcov){ + super(pocet_stavcov); + } + + @Override + public void hybsa(int directionX, int directionY, int directionZ) { + System.out.println("I am flying in directions: " + directionX + ", " + directionY + ", " + directionZ); + } + @Override + public void born(Date day_of_birth){ + super.date_of_birth=day_of_birth; + System.out.println("I was born on" + super.date_of_birth.toString()); + } + @Override + public void die(Date day_of_death){ + super.date_of_death=day_of_death; + System.out.println("I died on " + super.date_of_birth.toString()); + } +}