This code is just some exercise code printing questions and waiting for answers. It is working perfectly well as far as I can tell. I would like to know if this code could be considered acceptable or how it could be improved.import java.util.ArrayList;import java.util.Scanner;public class MainClass {    public static void main(String[] args) {        ArrayList<Citizens> list = new ArrayList<Citizens>();        Citizens p1 = new Portuguese();        list.add(p1);        p1.addName();        p1.addAge();        p1.addAdress();        Citizens p2 = new German();        list.add(p2);        p2.addName();        p2.addAge();        p2.addAdress();        boolean addCitizen = true;        while (addCitizen) {            Scanner input = new Scanner(System.in);            System.out.println(Do you want to add another citizen?Y or N?);            String answer = input.next();            if (answer.equals(y)) {                System.out.println(Do you want to add a Portuguese or a German citizen?PT or GER?);                answer = input.next();                if (answer.equals(pt)) {                    Citizens p3 = new Portuguese();                    list.add(p3);                    p3.addName();                    p3.addAge();                    p3.addAdress();                } else if (answer.equals(ger)) {                    Citizens p3 = new German();                    list.add(p3);                    p3.addName();                    p3.addAge();                    p3.addAdress();                } else if (!answer.equals(pt) || (!answer.equals(ger))) {                    System.out.println(Please choose PT or GER!);                }            } else if (answer.equals(n)) {                System.out.println(Youre not gonna add a new citizen!);                addCitizen = false;            } else {                System.out.println(Please enter y or n);            }        } System.out.println(The end);  }}class Citizensimport java.util.Scanner;public class Citizens {    private String name;    private int age;    private String adress;    String answer;    public int answernr;    boolean afirmativeanswer = true;    Scanner input = new Scanner(System.in);    public void addName() {        System.out.println(Do you want to add the citizen name?Y or N?);        answer = input.nextLine();        while (!answer.equals(y) || (!answer.equals(n))) {            if (answer.equals(y)) {                System.out.println(Please give the citizens name !);                String giveName = input.nextLine();                this.setName(giveName);                break;            } else if (answer.equals(n)) {                System.out.println(Not adding a name!);                break;            } else {                System.out.println(Please enter y or n);                answer = input.nextLine();            }        }    }    public void addAge() {        System.out.println(Do you want to add  + this.getName() + s age? Y or N?);        while (afirmativeanswer) {            answer = input.nextLine();            if (answer.equals(y)) {                System.out.println(Please enter  + this.getName() + s age!);                answernr = input.nextInt();                this.setAge(answernr);                afirmativeanswer = false;            } else if (answer.equals(n)) {                System.out.println(You choose not to add  + this.getName() + s age!);                afirmativeanswer = false;            } else {                System.out.println(Please enter y or n);            }        }    }     public void addAdress() {            System.out.println(Do you want to add  + this.getName() + s Adress?Y or N?);            afirmativeanswer = true;            while (afirmativeanswer) {              answer =  input.next();                if (answer.equals(y)) {                    System.out.println(Enter  + this.getName() + s Adress!);                    answer = input.next();                    this.setAdress(answer);                    afirmativeanswer = false;                } else if (answer.equals(n)) {                    System.out.println(You choose not to add  + this.getName() + s Adress!);                    afirmativeanswer = false;                } else {                    System.out.println(Please choose Y or N!);                }            }        }    public void setName(String s) {        this.name = s;    }    public String getName() {        return name;    }    public void setAge(int i) {        this.age = i;    }    public int getAge() {        return age;    }    public void setAdress(String c) {        this.adress = c;    }    public String getAdress() {        return adress;    }    public String toString() {        return name;    }}The Portuguese and German classes have just one constructor each.
Simple input/output practice
java;io
NamingNaming is fundamental to make your code easier to read.ArrayList<Citizens> list = new ArrayList<Citizens>();Name this to citizens.Citizens p1 = new Portuguese();p1 is not an adequate name. Rather name it as person1. Replace also p2 to person2.Rename Citizens to Citizen: person1 is Citizen not Citizens. Same thing for person2.Also use correct English spelling and follow Java capitalization conventions when you name a variable:boolean afirmativeanswer = true;should be affirmativeAnswer.Java is a language where CamelCase is mostly respected. Why didn't you use it?MethodA constructor is mostly used to access that classes methods and attributes parallel to other objects created.For an infinite-loop, you can do while(true) (preferred) or for(;;). Use break to exit from the while loop. So you don't even need to use afirmativeanswer.Use toLowerCase() method to not differentiate from inputting UPPERCASE or lowercase characters.There is no need to make answer and answernr instance variables. Just put them into the methods when you need them.