Проблема. Есть 2 сеттера, и есть конструктор, в нем 2 аргумента (waterAmount, coffeeAmount) поля таким названием есть так-же в классе. И при попытке сделать setWaterAmount(waterAmount);
выбирает переменную не из метода(конструктора) а из класса.
Возникает следующая ошибка:
The method setCoffeeAmount(short) in the type CoffeeMachine is not applicable for the arguments (int)
Код:
package com.company;
public class CoffeeMachine {
private final int maxWaterAmount = 4;
private final int maxCoffeeAmount = 1000;
private byte waterFill = 0;
private short coffeeAmount = 0;
public byte getWaterFill() {
return waterFill;
}
public void setWaterFill(byte waterFill) {
if (waterFill <= maxWaterAmount) {
this.waterFill = waterFill;
} else {
this.waterFill = maxWaterAmount;
}
}
public short getCoffeeAmount() {
return coffeeAmount;
}
public void setCoffeeAmount(short coffeeAmount) {
if (coffeeAmount <= maxCoffeeAmount) {
this.coffeeAmount = coffeeAmount;
} else {
this.coffeeAmount = maxCoffeeAmount;
}
}
public CoffeeMachine(int waterFill, int coffeeAmount) {
setCoffeeAmount(coffeeAmount);//ошибка
setWaterFill(waterFill);//ошибка
}
public CoffeeMachine() {}
public String printCoffeeMachineData() {
return "water amount is: "+waterFill+"l "+"coffee amount is: "+coffeeAmount+"g";
}
public String printCoffeeMachine() {
return "water amount is: "+waterFill+"l "+"coffee amount is: "+coffeeAmount+"g";
}
}
CoffeeMachine
и демонстрирует проблему. Пока все выглядит нормально.CoffeeMachine