У меня проблемы с sysout, и он не печатает последнюю часть моего кода. Вот два файла и мои результаты:


Код: Выделить всё
public class Main {
public static void main(String[] args) {
Flower tulip1 = new Flower(1, "tulip");
Flower rose1 = new Flower(3, 45.21, "rose");
Flower tulip2 = new Flower(2, 39.881, "tulip");
Flower dandelion1 = new Flower(0, 0, "dandelion");
if (tulip1.Compare(tulip2) == true) {
System.out.println("These two flowers are the same type.");
}
else {
System.out.println("These two flowers are not the same type.");
}
if (rose1.Compare(dandelion1)) {
System.out.println("These two flowers are the same type.");
}
else {
System.out.println("These two flowers are not the same type.");
}
System.out.println(rose1.ReturnHeightAndStage());
tulip1.Age();
tulip1.randomPollenPercentage();
tulip1.pollenCheck();
dandelion1.Grow(5.86);
rose1.setPollenPercentage(78.9971);
}
}
Код: Выделить всё
public class Flower {
private int stage;
private double heightInCM;
private String flowerType;
private double pollenPercentage;
public Flower(int s, double h, String ft) {
stage = s;
flowerType = ft;
heightInCM = h;
}
public Flower(int s, String ft) {
stage = s;
flowerType = ft;
heightInCM = 0;
}
public void Age() {
if (stage < 3){
stage += 1;
}
}
public void Grow(double growth) {
heightInCM += growth;
}
public boolean Compare(Flower anyFlower) {
if (this.flowerType.equals(anyFlower.flowerType)) {
return true;
}
else {
return false;
}
}
public void setPollenPercentage(double newValue) {
if (newValue > 100.00) {
newValue = 100.00;
}
if (newValue < 0.00) {
newValue = 0.00;
}
pollenPercentage = newValue;
}
public void randomPollenPercentage() {
pollenPercentage = Math.random() * 100.00;
}
public String ReturnHeightAndStage() {
double height = this.heightInCM;
int growthStage = this.stage;
if (growthStage == 1) {
return "Your flower is " + height + " centimeters tall, and it is a BUD.";
}
else if (growthStage == 2) {
return "Your flower is " + height + " centimeters tall, and it is a SPROUT.";
}
else if (growthStage == 3) {
return "Your flower is " + height + " centimeters tall, and it is a FULL-GROWN FLOWER.";
}
else {
this.heightInCM = 0;
return "Your flower has died mysteriously.";
}
}
public void pollenCheck() {
if (pollenPercentage > 100.00) {
pollenPercentage = 100.00;
}
if (pollenPercentage == 100.00) {
System.out.println("Your flower is in perfect health! Good job!");
}
else if (pollenPercentage >= 90.00) {
System.out.println("Your flower is in great health.");
}
else if (pollenPercentage >= 75.00) {
System.out.println("Your flower is in good health. It could be better.");
}
else {
System.out.println("Your flower is dead due to unhealthy conditions.");
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... i-fix-this
Мобильная версия