Я не знаю, что я должен изменить в своем коде, чтобы не допустить загрузки жидкости del
, когда я перемещаю ее из одной в другую (когда она заполнена).
package com.company;
public class Main {
public static void main(String[] args) {
int x = 10;
Bottle[] bottles = new Bottle[x];
for (int y = 0; y < bottles.length; y++) {
bottles[y] = new Bottle(50, 80);
}
System.out.println(bottles[3].getContent());
System.out.println(bottles[2].getContent());
bottles[2].move(31, bottles[5]);
System.out.println(bottles[2].getContent());
System.out.println(bottles[5].getContent());
}
}
class Bottle {
private double content;
private double volume;
Bottle(double content, double volume) {
this.content = content;
this.volume = volume;
}
double getContent() {
return content;
}
double getVolume() {
return volume;
}
boolean add(double amount) {
if (amount + this.content <= this.volume) {
this.content = this.content + amount;
} else {System.out.println("xxxxxxxxxxxxx");
return false;}
return true;
}
boolean del(double amount) {
if (amount <= this.content) {
this.content = this.content - amount;
} else {System.out.println("yyyyyyyyyyyyy");
return false;}
return true;
}
void move(double amount, Bottle number){
if (this.del(amount)){
number.add(amount);}
else {
System.out.println("zzzzzzzzzz");
}
}
}