Изменил(а) на 'MyFirstUniverse/src/com/company/cosmicbody/Planet.java'

This commit is contained in:
Oleksandr Hryshchenko 2022-11-07 22:14:20 +00:00
parent a357b0578f
commit 8efe7417df

View File

@ -1,103 +1,103 @@
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;
}
private 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.");
}
}
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);
} else {
decreaseGravity(0.1);
}
this.weight = weight;
}
public double getDiameter() {
return diameter;
}
private void setDiameter(double diameter) {
this.diameter = diameter;
}
public String getName() {
return name;
}
private 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;
}
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;
}
// public Planet() {
// this.name = "Zem";
// this.weight = 5972200;
// this.diameter = 12756;
// }
}
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;
}
private 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.");
}
}
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);
} else {
decreaseGravity(0.1);
}
this.weight = weight;
}
public double getDiameter() {
return diameter;
}
private void setDiameter(double diameter) {
this.diameter = diameter;
}
public String getName() {
return name;
}
private 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;
}
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;
}
// public Planet() {
// this.name = "Zem";
// this.weight = 5972200;
// this.diameter = 12756;
// }
}