The following is someone’s definition for the Checking class. public class Checking { //Only one attribute (for simplicity, nothing wrong here) private double balance; public void Checking(double iniBalance){ setbalance(iniBalance); } // Define getter and setter public String getbalance(){ return balance; } public void setbalance(double newbalance){ double balance = 0; if(newbalance>0){ //validity check balance = newbalance; } else{ System.out.println("Your input is invalid!"); } } }
Find the errors in the following code:
The following is someone’s definition for the Checking class.
public class Checking {
//Only one attribute (for simplicity, nothing wrong here)
private double balance;
public void Checking(double iniBalance){
setbalance(iniBalance);
}
// Define getter and setter
public String getbalance(){
return balance;
}
public void setbalance(double newbalance){
double balance = 0;
if(newbalance>0){ //validity check
balance = newbalance;
}
else{
System.out.println("Your input is invalid!");
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps