Search code examples
javagetter-setter

I am stuck with this code, kindly guide me - get & set methods in Java?


I am stuck in this below code, especially the below part

public String getBalanceForCid(double balance){
        double b = 0;
        if (cid = custid)
            b = balance;
        else
            b;
        return
            b;
}

Please guide me the right way.

Here is full code fyr

package practices;

public class Bank {

    public Bank(){
        cid = 0;
        cname = "";
        actno = 0;
        balance = 0;
    }

    public Bank(int custid, String custname, int custno, double custbal){
         cid = custid;
         cname = custname;
         actno = custno;
         balance = custbal;
    }


    public void setCustid(int custid){
         cid = custid;
    }

    public void setCustname(String custname){
         cname = custname;
    }

    public void setCustno(int custno){
        actno = custno;
    }

    public void setCustbal(double custbal){
        balance = custbal;
    }

    public int getCustoid(){
        return cid;
    }

    public String getCustname(){
        return cname;
    }

    public int getCustno(){
        return actno;
    }

    public double getCustbal(){
        return balance;
    }

    public String getBalanceForCid(double balance){
        double b = 0;
        if (cid = custid)
            b = balance;
        else
            b;
        return
            b;
    }


        private int cid;
        private String cname;
        private int actno;
        private double balance;
    }

above is my challenge (I am typing this message here again because I am getting message from SOF to add more details


Solution

  • Let's focus to getBalanceForCid(...) method:

    1. you should read in manual about if/else conditions

    2. you should read in manual about types/returning data types from methods and generally about methods. Then about accessors and mutators in classes.