Quindi quello che sto cercando di fare è questo:Come utilizzare Enums in getter e setter?
Scrivi una classe User
utente:
- ha un esempio username 'fj3'
- ha un UserType che può essere: 'utente', 'editore' o 'admin'
- ha un nome ad esempio 'Francis'
- ha un costruttore che prende il nome utente, UserType e il nome come parametri
- ha un metodo getUsername()
- ha un metodo getUserType()
- ha un metodo getName()
- ha un metodo setUserType() corrispondente a uno dei tipi di utente come parametro
il mio codice finora:
public class User{
public String id;
public String userPermissions;
public String actualName;
public User(String username, String userType, String name){
id = username;
userPermissions = userType;
actualName= name;
}
public String getUsername(){
return id;
}
public String getUserType(){
return userPermissions;
}
public String getName(){
return actualName;
}
public enum UserType{
admin, editor, user;
}
public void setUserType(String input){
userPermissions = input;
}
}
che cosa devo fare per ottenere questo lavoro? Non so come renderlo così gli unici tipi di utente che possono essere scelti sono admin, editor o utente.
convalidare i dati? Utilizzare un elenco di tipi noti? –
_Come dovrei farlo in bluej? _ Lo fai in java, non bluej, bluej è solo un IDE – BackSlash
Dovresti rinominare 'userPermissions' in' userType'. – kelunik