You are on page 1of 1

import java.util.

ArrayList;
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Aluno> alunos = new ArrayList<>();

int option;

do {
System.out.println("Do you wanna register a new student? (Type 1 for
Yes and 2 for No)");
option = scanner.nextInt();
scanner.nextLine();

if (option == 2) {
for (Aluno aluno : alunos) {
System.out.println(aluno);
}
break;
}

System.out.println("What is the student name?");


String name = scanner.nextLine();

System.out.println("What is the student age?");


int age = scanner.nextInt();

System.out.println("What is the student registration number?");


int nregistration = scanner.nextInt();

Aluno aluno = new Aluno(name, age, nregistration);


alunos.add(aluno);

} while (option == 1);


}
}

public class Aluno {


String name;
int age;
int nregistration;
public Aluno(String name, int age, int nregistration) {
this.name = name;
this.age = age;
this.nregistration = nregistration;
}

@Override
public String toString(){
return "Students name: " + name + "\n" +
"Students age: " + age + "\n" +
"Students registration number: " + nregistration + "\n";

}
}

You might also like