0
Good, I’m relatively new to Java programming! The following is a Super Class named User of which there are 2 subclasses Citizen and Autarchy, within the Citizen class I have created an Arraylist that will guard the Prizes of that Citizen, these prizes will be inserted in this list by Autarchy and I also have a Prize class from which I will create several instances of prizes to be awarded to the Cities as I must proceed so that the Autarchy can give the prizes to the Citizens?
package Users;
public class User {
private String name;
private String password;
private String email;
public User(String name, String password, String email) {
this.name = name;
this.password = password;
this.email = email;
}
//public receiveEmail(this.email) function to email a confirmation email to the user
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
}
package Users;
import java.util.ArrayList;
public class Citizen extends User{
private ArrayList prizes = new ArrayList<>();
public Citizen(String name, String password, String email) {
super(name, password, email);
}
public ArrayList getPrizes() {
return this.prizes;
}
@Override
public String toString() {
return "Name: " + this.getName() + " | Password: " + this.getPassword() +" | E-mail: " + this.getEmail() + " | prizes: " + this.prizes;
}
package Users;
public class Prize{
private String name;
private String description;
private int value;
public Prize(String name, String description, int value) {
this.name = name;
this.description = description;
this.value = value;
}
@Override
public String toString() {
return "Achievment: " + this.name;
}
But all the
Cizitens
saneUsers
? It seems a little strange this modeling. And should always useArrayList
generic, which in the case of its classCitizen
would beprivate ArrayList<Prize> prizes
– Isac
Yes all Citizens and Autarchy will be users of the app, only have different functionalities
– Asherab