Banks and other financial service companies offer many types of accounts for client’s to invest their fund– every one of them has a notion of their current value , but the details of calculating such value depends upon the exact nature of the account. Write an abstract class , Account, with the following: – an integer static variable , nextId initialized to 10001 – an integer instance variable , id – a string instance variable name – a constructor that accepts a single string parameter used to initialize the name instance variable . The constructor also assigns to id the value of nextId which is then incremented . – two accessor methods , getId and getName which return the values of the corresponding instance variables – an abstract method named getValue that accepts no parameters and returns and object of type Cash.

Banks and other financial service companies offer many types of accounts for client’s to invest their fund– every one of them has a notion of their current value , but the details of calculating such value depends upon the exact nature of the account. Write an abstract class , Account, with the following: – an integer static variable , nextId initialized to 10001 – an integer instance variable , id – a string instance variable name – a constructor that accepts a single string parameter used to initialize the name instance variable . The constructor also assigns to id the value of nextId which is then incremented . – two accessor methods , getId and getName which return the values of the corresponding instance variables – an abstract method named getValue that accepts no parameters and returns and object of type Cash.

LANGUAGE: JAVA

CHALLENGE:

Banks and other financial service companies offer many types of accounts for client’s to invest their fund– every one of them has a notion of their current value , but the details of calculating such value depends upon the exact nature of the account. Write an abstract class , Account, with the following: – an integer static variable , nextId initialized to 10001 – an integer instance variable , id – a string instance variable name – a constructor that accepts a single string parameter used to initialize the name instance variable . The constructor also assigns to id the value of nextId which is then incremented . – two accessor methods , getId and getName which return the values of the corresponding instance variables – an abstract method named getValue that accepts no parameters and returns and object of type Cash.

SOLUTION:

public abstract class Account{
    private static int nextId = 10001;
    private int id;
    private String name;
    public Account(String theName){
        name = theName;
        id = nextId;
        nextId++;
    }
    public int getId(){
        return id;
    }
    public String getName(){
        return name;
    }
    public abstract Cash getValue();
}

Add comment