**
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("********WELCOME TO CUSTOMER DETAIL**********");
System.out.println("");
BankAccount customerDetails = new BankAccount();
customerDetails.setAccountNumber(527553054);
System.out.println("Account Number : " + customerDetails.getAccountNumber());
customerDetails.setBalance(300000.00);
System.out.println("Balance : " + customerDetails.getBalance());
customerDetails.setCustomerName("Anish Shrestha");
System.out.println("Customer Name : " + customerDetails.getCustomerName());
customerDetails.setEmail("blah@gmail.com");
System.out.println("Email : " + customerDetails.getEmail());
customerDetails.setPhoneNumber(980709277);
System.out.println("Phone Number : "+ customerDetails.getPhoneNumber());
System.out.println("");
System.out.println("*********************");
BankAccount deposit = new BankAccount();
deposit.depositFunds(566);
}
}
package learnJava;
public class BankAccount {
public void depositFunds(double depositAmount) {
this.balance += depositAmount;
System.out.println("The total sum of money : " + this.balance);
}
private long accountNumber ;
private double balance;
private String customerName;
private String email;
private long phoneNumber;
//SETTER
public void setAccountNumber(long accountNumber) {
this.accountNumber = accountNumber;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void setEmail(String email) {
this.email = email ;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber ;
}
//GETTER
public long getAccountNumber() {
return this.accountNumber;
}
public double getBalance() {
return this.balance;
}
public String getCustomerName() {
return this.customerName;
}
public String getEmail() {
return this.email;
}
public long getPhoneNumber() {
return this.phoneNumber;
}
}
**
i could not add up deposit Amount to main balance Is it due to the setter/getter or there is something wrong in my code...... I am beginner so help me out guysss.....
I am not able to access the data of getter What could be the problem or is it a rule?
I have copy-paste your code, there is no problem. In comment, the output:
BankAccount deposit = new BankAccount();
deposit.depositFunds(100); // The total sum of money : 100.0
deposit.depositFunds(100); // The total sum of money : 200.0
System.out.println(deposit.getBalance()); // 200.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.