当我将1 : llvm_cpu.0
2 : opencl_amd_amd_radeon_pro_555_compute_engine.0
3 : metal_amd_radeon_pro_460.0
4 : opencl_intel_intel(r)_hd_graphics_630.0
5 : opencl_cpu.0
6 : metal_intel(r)_hd_graphics_unknown.0
Default device? (1,2,3,4,5,6)[1]:
液体从一种转移到另一种(充满)时,我不知道该如何更改代码以防止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");
}
}
}