From 943b5fe09bcb3d749149969add6b500c8042967d Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Tue, 8 Nov 2022 13:37:59 +0100 Subject: [PATCH] Universe --- MyFirstUniverse/.idea/description.html | 1 + MyFirstUniverse/.idea/discord.xml | 7 + MyFirstUniverse/.idea/encodings.xml | 6 + MyFirstUniverse/.idea/misc.xml | 12 ++ MyFirstUniverse/.idea/modules.xml | 8 + MyFirstUniverse/.idea/project-template.xml | 3 + MyFirstUniverse/.idea/uiDesigner.xml | 124 +++++++++++++ MyFirstUniverse/.idea/vcs.xml | 6 + MyFirstUniverse/.idea/workspace.xml | 166 ++++++++++++++++++ MyFirstUniverse/MyFirstUniverse.iml | 11 ++ MyFirstUniverse/src/com/company/Main.java | 65 +++++++ .../com/company/cosmicbody/CosmicBody.java | 13 ++ .../src/com/company/cosmicbody/Planet.java | 106 +++++++++++ .../com/company/cosmicbody/SolarSystem.java | 40 +++++ .../src/com/company/cosmicbody/Star.java | 68 +++++++ .../src/com/company/cosmicbody/Сomet.java | 21 +++ .../src/com/company/universe/Galaxy.java | 46 +++++ .../com/company/universe/PlanetaryNebula.java | 28 +++ .../src/com/company/universe/Universe.java | 40 +++++ 19 files changed, 771 insertions(+) create mode 100644 MyFirstUniverse/.idea/description.html create mode 100644 MyFirstUniverse/.idea/discord.xml create mode 100644 MyFirstUniverse/.idea/encodings.xml create mode 100644 MyFirstUniverse/.idea/misc.xml create mode 100644 MyFirstUniverse/.idea/modules.xml create mode 100644 MyFirstUniverse/.idea/project-template.xml create mode 100644 MyFirstUniverse/.idea/uiDesigner.xml create mode 100644 MyFirstUniverse/.idea/vcs.xml create mode 100644 MyFirstUniverse/.idea/workspace.xml create mode 100644 MyFirstUniverse/MyFirstUniverse.iml create mode 100644 MyFirstUniverse/src/com/company/Main.java create mode 100644 MyFirstUniverse/src/com/company/cosmicbody/CosmicBody.java create mode 100644 MyFirstUniverse/src/com/company/cosmicbody/Planet.java create mode 100644 MyFirstUniverse/src/com/company/cosmicbody/SolarSystem.java create mode 100644 MyFirstUniverse/src/com/company/cosmicbody/Star.java create mode 100644 MyFirstUniverse/src/com/company/cosmicbody/Сomet.java create mode 100644 MyFirstUniverse/src/com/company/universe/Galaxy.java create mode 100644 MyFirstUniverse/src/com/company/universe/PlanetaryNebula.java create mode 100644 MyFirstUniverse/src/com/company/universe/Universe.java diff --git a/MyFirstUniverse/.idea/description.html b/MyFirstUniverse/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/MyFirstUniverse/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/MyFirstUniverse/.idea/discord.xml b/MyFirstUniverse/.idea/discord.xml new file mode 100644 index 0000000..2a6a89a --- /dev/null +++ b/MyFirstUniverse/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/encodings.xml b/MyFirstUniverse/.idea/encodings.xml new file mode 100644 index 0000000..ab2dc53 --- /dev/null +++ b/MyFirstUniverse/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/misc.xml b/MyFirstUniverse/.idea/misc.xml new file mode 100644 index 0000000..7e211a1 --- /dev/null +++ b/MyFirstUniverse/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/modules.xml b/MyFirstUniverse/.idea/modules.xml new file mode 100644 index 0000000..774cf7c --- /dev/null +++ b/MyFirstUniverse/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/project-template.xml b/MyFirstUniverse/.idea/project-template.xml new file mode 100644 index 0000000..d57a956 --- /dev/null +++ b/MyFirstUniverse/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/uiDesigner.xml b/MyFirstUniverse/.idea/uiDesigner.xml new file mode 100644 index 0000000..b93ac08 --- /dev/null +++ b/MyFirstUniverse/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/vcs.xml b/MyFirstUniverse/.idea/vcs.xml new file mode 100644 index 0000000..94f066c --- /dev/null +++ b/MyFirstUniverse/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/.idea/workspace.xml b/MyFirstUniverse/.idea/workspace.xml new file mode 100644 index 0000000..9d214b5 --- /dev/null +++ b/MyFirstUniverse/.idea/workspace.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "D:/Study/3year/OOP/MyFirstUniverse", + "settings.editor.selected.configurable": "project.propVCSSupport.DirectoryMappings" + } +} + + + + + + + + + + + + + + 1664307490741 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/MyFirstUniverse.iml b/MyFirstUniverse/MyFirstUniverse.iml new file mode 100644 index 0000000..9465dd8 --- /dev/null +++ b/MyFirstUniverse/MyFirstUniverse.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MyFirstUniverse/src/com/company/Main.java b/MyFirstUniverse/src/com/company/Main.java new file mode 100644 index 0000000..3527e85 --- /dev/null +++ b/MyFirstUniverse/src/com/company/Main.java @@ -0,0 +1,65 @@ +package com.company; + +import com.company.cosmicbody.Planet; +import com.company.cosmicbody.SolarSystem; +import com.company.cosmicbody.Star; +import com.company.universe.Galaxy; +import com.company.universe.PlanetaryNebula; +import com.company.universe.Universe; + +public class Main { + + public static void main(String[] args) { + Universe myuniverse = new Universe(); + + System.out.println("\n"); + + PlanetaryNebula orion = new PlanetaryNebula("Orion",5, 18000,200,200,200); + PlanetaryNebula buba = new PlanetaryNebula("Buba", 8, 2300, 12,59,94); + PlanetaryNebula phonk = new PlanetaryNebula("Phonk", 20, 100000, 0,0,0); + + System.out.println("\n"); + + Planet Mercury = new Planet("Mercury", 1333, 6083, 0); + Planet Venus = new Planet("Venus", 4867, 938, 12.1); + Planet Earth = new Planet("Earth", 100000, 108321); + Planet Mars = new Planet("Mars", 641, 16318, 9.81); + Planet Jupiter = new Planet("Jupiter", 3, 71313, 20.89); + Planet Saturn = new Planet("Saturn", 1000, 108408, 95.8); + Planet Uranus = new Planet("Uranus", 1000, 202156, 255.55); + Planet Neptune = new Planet("Neptune", 7050, 620654, 0); + + System.out.println("\n"); + Star sun = new Star("Sun", 1.392, 1.40927, 1499726.85); + sun.on(); + + System.out.println("\n"); + + SolarSystem solarSystem = new SolarSystem(); + solarSystem.addBody(Mercury); + solarSystem.addBody(Venus); + solarSystem.addBody(Earth); + solarSystem.addBody(Mars); + solarSystem.addBody(Jupiter); + solarSystem.addBody(Saturn); + solarSystem.addBody(Uranus); + solarSystem.addBody(Neptune); + + System.out.println("\n"); + + Galaxy milkyWay = new Galaxy("Milky Way"); + milkyWay.addSustava(solarSystem); + + Galaxy Hryshchenko = new Galaxy("Hryshchenko"); + Hryshchenko.addSustava(solarSystem); + + System.out.println("\n"); + + milkyWay.sendMessage(Hryshchenko, "Hi, I'm you friend"); + Hryshchenko.sendMessage(milkyWay, "Hi."); + + System.out.println("\n"); + + myuniverse.stopUniverse(); + } +} \ No newline at end of file diff --git a/MyFirstUniverse/src/com/company/cosmicbody/CosmicBody.java b/MyFirstUniverse/src/com/company/cosmicbody/CosmicBody.java new file mode 100644 index 0000000..75edda2 --- /dev/null +++ b/MyFirstUniverse/src/com/company/cosmicbody/CosmicBody.java @@ -0,0 +1,13 @@ +package com.company.cosmicbody; + +public class CosmicBody { + private String body; + + public String getBody() { + return body; + } + + protected void setBody(String body) { + this.body = body; + } +} diff --git a/MyFirstUniverse/src/com/company/cosmicbody/Planet.java b/MyFirstUniverse/src/com/company/cosmicbody/Planet.java new file mode 100644 index 0000000..c309811 --- /dev/null +++ b/MyFirstUniverse/src/com/company/cosmicbody/Planet.java @@ -0,0 +1,106 @@ +package com.company.cosmicbody; + +public class Planet extends CosmicBody { + private String name; + private double weight; + private double diameter; + private double gravitation; + private Boolean weightSet = false; + + public void setPlanetaryWeight(double weight){ + if(!weightSet){ + setWeight(weight); + weightSet = true; + } + } + + + public double getWeight() { + return weight; + } + + public void setWeight(double weight) { + if(this.weight>weight){ + if(Math.abs(this.weight-weight) <= 1000){ + System.out.println("I'm losing weight."); + } + else { + System.out.println("I'm losing a lot of weight."); + } + if(Math.abs(this.weight-weight) > 1000){ + decreaseGravity(0.1); + } + } + else{ + if(Math.abs(this.weight-weight) <= 1000){ + System.out.println("Damn, I woke up."); + } + else { + System.out.println("Damn, I put on too much weight."); + } + if(Math.abs(this.weight-weight) > 1000){ + increaseGravity(0.1); + } + } + + this.weight = weight; + } + + public double getDiameter() { + return diameter; + } + + public void setDiameter(double diameter) { + this.diameter = diameter; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getGravitation() { + return gravitation; + } + + public void setGravitation(double gravitation) { + this.gravitation = gravitation; + } + + public Planet(String name, double weight, double diameter) { +// setWeight(weight); +// setDiameter(diameter); +// setName(name); + this.name = name; + this.weight = weight; + this.diameter = diameter; + this.gravitation = 9.81; + System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation); + } + + private void increaseGravity(double add){ + gravitation = gravitation + add; + } + private void decreaseGravity(double dec){ + gravitation = gravitation - dec; + } + + public Planet(String name, double weight, double diameter, double gravitation) { + this.name = name; + this.weight = weight; + this.diameter = diameter; + this.gravitation = gravitation; + System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation); + } + + public Planet() { + this.name = "Earth"; + this.weight = 5972200; + this.diameter = 12756; + System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation); + } + +} diff --git a/MyFirstUniverse/src/com/company/cosmicbody/SolarSystem.java b/MyFirstUniverse/src/com/company/cosmicbody/SolarSystem.java new file mode 100644 index 0000000..eacad76 --- /dev/null +++ b/MyFirstUniverse/src/com/company/cosmicbody/SolarSystem.java @@ -0,0 +1,40 @@ +package com.company.cosmicbody; + +public class SolarSystem { +// private Star Sun = new Star(); + +// private Planet Earth; +// private Planet Mars; +// private Planet Jupiter; +// private Planet Saturn; + + private CosmicBody[] orbitalBody = new CosmicBody[500000000]; + private int objectCounter; + + public SolarSystem() { + //star = new Star(); + + setObjectCounter(0); + orbitalBody[objectCounter] = new Planet("Mars", 432432, 432432); + objectCounter++; + + orbitalBody[objectCounter] = new Planet("Venusa", 55, 32342); + objectCounter++; + + orbitalBody[objectCounter] = new Star("Polar",0,0,0); + objectCounter++; + } + + public void addBody(CosmicBody newBody){ + orbitalBody[objectCounter] = newBody; + objectCounter++; + } + + public int getObjectCounter() { + return objectCounter; + } + + public void setObjectCounter(int objectCounter) { + this.objectCounter = objectCounter; + } +} diff --git a/MyFirstUniverse/src/com/company/cosmicbody/Star.java b/MyFirstUniverse/src/com/company/cosmicbody/Star.java new file mode 100644 index 0000000..230ddfc --- /dev/null +++ b/MyFirstUniverse/src/com/company/cosmicbody/Star.java @@ -0,0 +1,68 @@ +package com.company.cosmicbody; + +public class Star extends CosmicBody { + private String name; + private double weight; + private double radius; + private double temperature; + private Boolean light = false; + + public Star(String name, double weight, double radius, double temperature) { + this.name = name; + this.weight = weight; + this.radius = radius; + this.temperature = temperature; + System.out.println("Star is: " + name + " has been created. Parameters: " + weight + ", " + radius + ", " + temperature); + } + + public Star(){ + this.name = "naname"; + this.weight = 1000^35; + this.temperature = 500000; + System.out.println("Star is: " + name + " has been created"); + } + + public void on(){ + this.light = true; + this.temperature = temperature + 10000; + System.out.println("Status: on" + ". Temperature = " + temperature); + } + + public void off(){ + this.light = false; + this.temperature = temperature - 10000; + System.out.println("Status: off" + ". Temperature = " + temperature); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getWeight() { + return weight; + } + + public void setWeight(double weight) { + this.weight = weight; + } + + public double getRadius() { + return radius; + } + + public void setRadius(double radius) { + this.radius = radius; + } + + public double getTemperature() { + return temperature; + } + + public void setTemperature(double temperature) { + this.temperature = temperature; + } +} diff --git a/MyFirstUniverse/src/com/company/cosmicbody/Сomet.java b/MyFirstUniverse/src/com/company/cosmicbody/Сomet.java new file mode 100644 index 0000000..630946a --- /dev/null +++ b/MyFirstUniverse/src/com/company/cosmicbody/Сomet.java @@ -0,0 +1,21 @@ +package com.company.cosmicbody; + +public class Сomet extends CosmicBody { + private int object_counter; + + private CosmicBody[] orbitalBody = new CosmicBody[500000000]; + + public Сomet() { + setObject_counter(0); + orbitalBody[object_counter] = new Сomet(); + object_counter++; + } + + public int getObject_counter() { + return object_counter; + } + + public void setObject_counter(int object_counter) { + this.object_counter = object_counter; + } +} diff --git a/MyFirstUniverse/src/com/company/universe/Galaxy.java b/MyFirstUniverse/src/com/company/universe/Galaxy.java new file mode 100644 index 0000000..ad3c1fc --- /dev/null +++ b/MyFirstUniverse/src/com/company/universe/Galaxy.java @@ -0,0 +1,46 @@ +package com.company.universe; + +import com.company.cosmicbody.SolarSystem; + +public class Galaxy { + + private String name; + private SolarSystem[] systems = new SolarSystem[5000]; + private int objectCounter; + + private String message; + + public void sendMessage(Galaxy galaxy, String message){ + galaxy.setMessage(message); + System.out.println("Meassage: '" + message + "' from " + this.name + " has been send to: " + galaxy.name); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Galaxy(String name) { + this.name = name; + this.objectCounter = 0; + System.out.println("Galaxy is: " + name + " has been created."); + } + + + + public void addSustava(SolarSystem system){ + this.systems[objectCounter] = system; + this.setObjectCounter(this.objectCounter++); + } + + public int getObjectCounter() { + return objectCounter; + } + + private void setObjectCounter(int objectCounter) { + this.objectCounter = objectCounter; + } +} diff --git a/MyFirstUniverse/src/com/company/universe/PlanetaryNebula.java b/MyFirstUniverse/src/com/company/universe/PlanetaryNebula.java new file mode 100644 index 0000000..88de17d --- /dev/null +++ b/MyFirstUniverse/src/com/company/universe/PlanetaryNebula.java @@ -0,0 +1,28 @@ +package com.company.universe; + +public class PlanetaryNebula { + + private String name; + private long size; + private long lifeDuration; + private long x, y , z; + + public PlanetaryNebula(){ + name = "myName"; + size = 0; + lifeDuration = 0; + x = 0; y = 0; z=0; + System.out.println("Created Planetary Nebula: " + name + "Parameters: " + lifeDuration + ", " + size + ". Coordination: " + x + ", " + y + ", " + z); + } + + public PlanetaryNebula(String name,long lifeDuration, long size, long x, long y, long z) { + this.name = name; + this.lifeDuration = lifeDuration; + this.size = size; + this.x = x; + this.y = y; + this.z = z; + System.out.println("Created Planetary Nebula: " + name + "Parameters: " + lifeDuration + ", " + size + ". Coordination: " + x + ", " + y + ", " + z); + } +} + diff --git a/MyFirstUniverse/src/com/company/universe/Universe.java b/MyFirstUniverse/src/com/company/universe/Universe.java new file mode 100644 index 0000000..3c4a176 --- /dev/null +++ b/MyFirstUniverse/src/com/company/universe/Universe.java @@ -0,0 +1,40 @@ +package com.company.universe; + +public class Universe { + private boolean state; + private long size; + + public Universe() { + state = false; + size = 0; + startUniverse(); + } + + public void startUniverse(){ + state = true; + System.out.println("World is ready"); + increaseSize(); + decreaseSize(10000); + } + + public void stopUniverse(){ + state = false; + System.out.println("World is stop"); + } + + private void increaseSize(){ + while (size<999000){ + size++; + //System.out.println("Wait. Universe " + size + "km3"); + } + System.out.println("Universe is " + size + "km3"); + } + + private void decreaseSize(long desiredSize){ + while (size > desiredSize){ + size--; + //System.out.println ("Wait. Compressed world " + size + "km3"); + } + System.out.println ("Compress world is " + size + "km3"); + } +}