'Variable that I point to using this keyword is not used [duplicate]
I am trying build a method(showCost) that takes in the product number and return the cost of the product.My second method is where the error occurs.
I am trying to use the this keyword to point the payment to my local variable payment amount.However, the program says that my paymentamount variable is not used.
public class CashRegister {
Double [] cost = {3.0,4.0,5.0,6.0};
private Double paymentamount;
public Double showCost (int productnum){
return (cost[productnum]);
}
public void payAmount(double payment){
this.paymentamount = payment;
}
}
Solution 1:[1]
The program says that paymentamount variable is not used.
Because: You're just assigning the value in paymentamount variable, but you are not using that variable anywhere else.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shridutt Kothari |
