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); } }