21158 - VictoriaBrown/MyProgrammingLab_Ch10 GitHub Wiki

QUESTION:

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.

CODE:

public abstract class Account {

	// Instance variables:
	private static int nextId = 10001;
	private int id;
	private String name;

	// Constructor:
	public Account(String name) {
		this.name = name;
		id = nextId;
		nextId++;
	}

	// Return id (get method):
	public int getId() {
		return id;
	}
	
	// Return name (get method):
	public String getName() {
		return name;
	}

	// Abstract method:
	public abstract Cash getValue();
}