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">
<option name="synchronizeBranchProtectionRules" value="false" />
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/svet" vcs="Git" />
</component>
</project>

View File

@ -3,6 +3,7 @@ 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;
@ -10,22 +11,30 @@ public class Main {
public static void main(String[] args) {
Universe myuniverse = new Universe();
myuniverse.startUniverse();
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);
Planet Mercury = new Planet("Mercury", 1333, 6083);
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);
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);
@ -36,6 +45,20 @@ public class Main {
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();
}

View File

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

View File

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

View File

@ -12,22 +12,26 @@ public class Star extends CosmicBody {
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");
}
void on(){
public void on(){
this.light = true;
this.temperature = temperature + 10000;
System.out.println("Status: on" + ". Temperature = " + temperature);
}
void off(){
public void off(){
this.light = false;
this.temperature = temperature - 1000;
this.temperature = temperature - 10000;
System.out.println("Status: off" + ". Temperature = " + temperature);
}
public String getName() {

View File

@ -5,14 +5,32 @@ import com.company.cosmicbody.SolarSystem;
public class Galaxy {
private String name;
private SolarSystem[] systems = new SolarSystem[500000000];
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++);

View File

@ -7,11 +7,13 @@ public class PlanetaryNebula {
private long lifeDuration;
private long x, y , z;
// public PlanetaryNebula(){
// size = 0;
// lifeDuration = 0;
// x = 0; y = 0; z=0;
// }
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;
@ -20,6 +22,7 @@ public class PlanetaryNebula {
this.x = x;
this.y = y;
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() {
state = false;
size = 0;
startUniverse();
}
public void startUniverse(){
state = true;
System.out.println("World is ready\n");
System.out.println("World is ready");
increaseSize();
decreaseSize(10000);
}
public void stopUniverse(){
state = false;
System.out.println("\nWorld is stop");
System.out.println("World is stop");
}
private void increaseSize(){
@ -34,6 +35,6 @@ public class Universe {
size--;
//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");
}
}