zadanie oop

This commit is contained in:
Oleksandr Hryshchenko 2022-11-08 13:24:25 +01:00
parent e5ec8b4a06
commit 7eb34b6b86
8 changed files with 93 additions and 44 deletions

View File

@ -3,7 +3,4 @@
<component name="GitSharedSettings"> <component name="GitSharedSettings">
<option name="synchronizeBranchProtectionRules" value="false" /> <option name="synchronizeBranchProtectionRules" value="false" />
</component> </component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/svet" vcs="Git" />
</component>
</project> </project>

View File

@ -3,6 +3,7 @@ package com.company;
import com.company.cosmicbody.Planet; import com.company.cosmicbody.Planet;
import com.company.cosmicbody.SolarSystem; import com.company.cosmicbody.SolarSystem;
import com.company.cosmicbody.Star; import com.company.cosmicbody.Star;
import com.company.universe.Galaxy;
import com.company.universe.PlanetaryNebula; import com.company.universe.PlanetaryNebula;
import com.company.universe.Universe; import com.company.universe.Universe;
@ -10,22 +11,30 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Universe myuniverse = new Universe(); Universe myuniverse = new Universe();
myuniverse.startUniverse();
System.out.println("\n");
PlanetaryNebula orion = new PlanetaryNebula("Orion",5, 18000,200,200,200); PlanetaryNebula orion = new PlanetaryNebula("Orion",5, 18000,200,200,200);
PlanetaryNebula buba = new PlanetaryNebula("Buba", 8, 2300, 12,59,94); PlanetaryNebula buba = new PlanetaryNebula("Buba", 8, 2300, 12,59,94);
PlanetaryNebula phonk = new PlanetaryNebula("Phonk", 20, 100000, 0,0,0); PlanetaryNebula phonk = new PlanetaryNebula("Phonk", 20, 100000, 0,0,0);
Planet Mercury = new Planet("Mercury", 1333, 6083); System.out.println("\n");
Planet Venus = new Planet("Venus", 4867, 938);
Planet Earth = new Planet("Earth", 100000, 108321);
Planet Mars = new Planet("Mars", 641, 16318);
Planet Jupiter = new Planet("Jupiter", 3, 71313);
Planet Saturn = new Planet("Saturn", 1000, 108408);
Planet Uranus = new Planet("Uranus", 1000, 202156);
Planet Neptune = new Planet("Neptune", 7050, 620654);
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); Star sun = new Star("Sun", 1.392, 1.40927, 1499726.85);
sun.on();
System.out.println("\n");
SolarSystem solarSystem = new SolarSystem(); SolarSystem solarSystem = new SolarSystem();
solarSystem.addBody(Mercury); solarSystem.addBody(Mercury);
solarSystem.addBody(Venus); solarSystem.addBody(Venus);
@ -36,6 +45,20 @@ public class Main {
solarSystem.addBody(Uranus); solarSystem.addBody(Uranus);
solarSystem.addBody(Neptune); 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(); myuniverse.stopUniverse();
} }

View File

@ -19,13 +19,16 @@ public class Planet extends CosmicBody {
return weight; return weight;
} }
private void setWeight(double weight) { public void setWeight(double weight) {
if(this.weight>weight){ if(this.weight>weight){
if(Math.abs(this.weight-weight) <= 1000){ if(Math.abs(this.weight-weight) <= 1000){
System.out.println("I'm losing weight."); System.out.println("I'm losing weight.");
} }
else { else {
System.out.println("I am very poor."); System.out.println("I'm losing a lot of weight.");
}
if(Math.abs(this.weight-weight) > 1000){
decreaseGravity(0.1);
} }
} }
else{ else{
@ -35,12 +38,9 @@ public class Planet extends CosmicBody {
else { else {
System.out.println("Damn, I put on too much weight."); System.out.println("Damn, I put on too much weight.");
} }
}
if(Math.abs(this.weight-weight) > 1000){ if(Math.abs(this.weight-weight) > 1000){
increaseGravity(0.1); increaseGravity(0.1);
} else { }
decreaseGravity(0.1);
} }
this.weight = weight; this.weight = weight;
@ -50,7 +50,7 @@ public class Planet extends CosmicBody {
return diameter; return diameter;
} }
private void setDiameter(double diameter) { public void setDiameter(double diameter) {
this.diameter = diameter; this.diameter = diameter;
} }
@ -58,7 +58,7 @@ public class Planet extends CosmicBody {
return name; return name;
} }
private void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@ -78,6 +78,7 @@ public class Planet extends CosmicBody {
this.weight = weight; this.weight = weight;
this.diameter = diameter; this.diameter = diameter;
this.gravitation = 9.81; this.gravitation = 9.81;
System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation);
} }
private void increaseGravity(double add){ private void increaseGravity(double add){
@ -92,12 +93,14 @@ public class Planet extends CosmicBody {
this.weight = weight; this.weight = weight;
this.diameter = diameter; this.diameter = diameter;
this.gravitation = gravitation; this.gravitation = gravitation;
System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation);
} }
// public Planet() { public Planet() {
// this.name = "Zem"; this.name = "Earth";
// this.weight = 5972200; this.weight = 5972200;
// this.diameter = 12756; this.diameter = 12756;
// } System.out.println("Planet is: " + name + " has been created. Parameters: " + weight + " " + diameter + ". Gravitation: " + gravitation);
}
} }

View File

@ -1,12 +1,12 @@
package com.company.cosmicbody; package com.company.cosmicbody;
public class SolarSystem { public class SolarSystem {
private Star Sun = new Star(); // private Star Sun = new Star();
private Planet Earth; // private Planet Earth;
private Planet Mars; // private Planet Mars;
private Planet Jupiter; // private Planet Jupiter;
private Planet Saturn; // private Planet Saturn;
private CosmicBody[] orbitalBody = new CosmicBody[500000000]; private CosmicBody[] orbitalBody = new CosmicBody[500000000];
private int objectCounter; private int objectCounter;

View File

@ -12,22 +12,26 @@ public class Star extends CosmicBody {
this.weight = weight; this.weight = weight;
this.radius = radius; this.radius = radius;
this.temperature = temperature; this.temperature = temperature;
System.out.println("Star is: " + name + " has been created. Parameters: " + weight + ", " + radius + ", " + temperature);
} }
public Star(){ public Star(){
this.name = "naname"; this.name = "naname";
this.weight = 1000^35; this.weight = 1000^35;
this.temperature = 500000; this.temperature = 500000;
System.out.println("Star is: " + name + " has been created");
} }
void on(){ public void on(){
this.light = true; this.light = true;
this.temperature = temperature + 10000; this.temperature = temperature + 10000;
System.out.println("Status: on" + ". Temperature = " + temperature);
} }
void off(){ public void off(){
this.light = false; this.light = false;
this.temperature = temperature - 1000; this.temperature = temperature - 10000;
System.out.println("Status: off" + ". Temperature = " + temperature);
} }
public String getName() { public String getName() {

View File

@ -5,14 +5,32 @@ import com.company.cosmicbody.SolarSystem;
public class Galaxy { public class Galaxy {
private String name; private String name;
private SolarSystem[] systems = new SolarSystem[500000000]; private SolarSystem[] systems = new SolarSystem[5000];
private int objectCounter; 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) { public Galaxy(String name) {
this.name = name; this.name = name;
this.objectCounter = 0; this.objectCounter = 0;
System.out.println("Galaxy is: " + name + " has been created.");
} }
public void addSustava(SolarSystem system){ public void addSustava(SolarSystem system){
this.systems[objectCounter] = system; this.systems[objectCounter] = system;
this.setObjectCounter(this.objectCounter++); this.setObjectCounter(this.objectCounter++);

View File

@ -7,11 +7,13 @@ public class PlanetaryNebula {
private long lifeDuration; private long lifeDuration;
private long x, y , z; private long x, y , z;
// public PlanetaryNebula(){ public PlanetaryNebula(){
// size = 0; name = "myName";
// lifeDuration = 0; size = 0;
// x = 0; y = 0; z=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) { public PlanetaryNebula(String name,long lifeDuration, long size, long x, long y, long z) {
this.name = name; this.name = name;
@ -20,6 +22,7 @@ public class PlanetaryNebula {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
System.out.println("Created Planetary Nebula: " + name + "Parameters: " + lifeDuration + ", " + size + ". Coordination: " + x + ", " + y + ", " + z);
} }
} }

View File

@ -7,18 +7,19 @@ public class Universe {
public Universe() { public Universe() {
state = false; state = false;
size = 0; size = 0;
startUniverse();
} }
public void startUniverse(){ public void startUniverse(){
state = true; state = true;
System.out.println("World is ready\n"); System.out.println("World is ready");
increaseSize(); increaseSize();
decreaseSize(10000); decreaseSize(10000);
} }
public void stopUniverse(){ public void stopUniverse(){
state = false; state = false;
System.out.println("\nWorld is stop"); System.out.println("World is stop");
} }
private void increaseSize(){ private void increaseSize(){
@ -34,6 +35,6 @@ public class Universe {
size--; size--;
//System.out.println ("Wait. Compressed world " + size + "km3"); //System.out.println ("Wait. Compressed world " + size + "km3");
} }
System.out.println ("Compress world is " + size + "km3\n"); System.out.println ("Compress world is " + size + "km3");
} }
} }