I'm writing a code in Java using abstract classes for the first time and I have a problem. I have a list (array) of users, each of them is an object of userClass. I have created an abstract class 'account' and 2 classes which extends it 'basicAccount' and 'premiumAccount' and I would like to create basic or premium account for every user depending on an input. My problem is that I don't know how to implement userClass, so it would create object of basic or premium class depending on a string 'accountType' Example:
public class userClass {
private String email;
private String accountType;
private account account;
public userClass(String email, String accountType){
this.setEmail(email);
this.setAccountType(accountType);
if(accountType.equals("Basic")){
basicAccount account = new basicAccount();
}
else if(accountType.equals("Premium")){
premiumAccount account = new premiumAccount();
}
}
Could you please help me? Can I put those if's in userClass method?