fixed-sized arrays
This commit is contained in:
parent
43ba3753f9
commit
938d7af3ed
3 changed files with 179 additions and 67 deletions
226
Dados.java
226
Dados.java
|
|
@ -7,10 +7,10 @@ public class Dados {
|
||||||
private Bolsista[] bolsistas;
|
private Bolsista[] bolsistas;
|
||||||
|
|
||||||
public Dados(){
|
public Dados(){
|
||||||
alunos = new Aluno[]{};
|
this.alunos = new Aluno[256];
|
||||||
chamada = "";
|
this.chamada = "";
|
||||||
acompanhamentos = new Acompanhamento[]{};
|
this.acompanhamentos = new Acompanhamento[256];
|
||||||
bolsistas = new Bolsista[]{};
|
this.bolsistas = new Bolsista[256];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String appendAluno(Aluno aluno){
|
public String appendAluno(Aluno aluno){
|
||||||
|
|
@ -18,62 +18,80 @@ public class Dados {
|
||||||
return Erro.E3;
|
return Erro.E3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = this.alunos.length;
|
int size = 0;
|
||||||
|
|
||||||
Aluno[] novoArray = new Aluno[size + 1];
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
for (int i = 0; i < size; i++){
|
size = i;
|
||||||
novoArray[i] = this.alunos[i];
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
novoArray[size] = aluno;
|
if (size == 255){
|
||||||
this.alunos = novoArray;
|
return Erro.E10;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.alunos[size] = aluno;
|
||||||
|
|
||||||
|
System.out.println("debug_alunos.size:"+size);
|
||||||
|
|
||||||
return "Aluno cadastrado com sucesso.";
|
return "Aluno cadastrado com sucesso.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String appendAcompanhamento(Acompanhamento acomp){
|
public String appendAcompanhamento(Acompanhamento acomp){
|
||||||
if (checkDuplicate(acomp.getAluno().getNome())){
|
|
||||||
return Erro.E3;
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.acompanhamentos.length; i++){
|
||||||
|
if (this.acompanhamentos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = this.acompanhamentos.length;
|
if (size == 255){
|
||||||
|
return Erro.E10;
|
||||||
Acompanhamento[] novoArray = new Acompanhamento[size + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++){
|
|
||||||
novoArray[i] = this.acompanhamentos[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
novoArray[size] = acomp;
|
this.acompanhamentos[size] = acomp;
|
||||||
this.acompanhamentos = novoArray;
|
|
||||||
|
System.out.println("debug_acompanhamentos.size:"+size);
|
||||||
|
|
||||||
return "Acompanhamento cadastrado com sucesso.";
|
return "Acompanhamento cadastrado com sucesso.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String appendBolsista(Bolsista bolsista){
|
public String appendBolsista(Bolsista bolsista){
|
||||||
if (checkDuplicate(bolsista.getNome())){
|
|
||||||
return Erro.E3;
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.bolsistas.length; i++){
|
||||||
|
if (this.bolsistas[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = this.bolsistas.length;
|
if (size == 255){
|
||||||
|
return Erro.E10;
|
||||||
Bolsista[] novoArray = new Bolsista[size + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++){
|
|
||||||
novoArray[i] = this.bolsistas[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
novoArray[size] = bolsista;
|
this.bolsistas[size] = bolsista;
|
||||||
this.bolsistas = novoArray;
|
|
||||||
|
|
||||||
return "Bolsista cadastrado com sucesso.";
|
return "Bolsista cadastrado com sucesso.";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkDuplicate(String nome){
|
private boolean checkDuplicate(String nome){
|
||||||
for (int i = 0; i < alunos.length; i++){
|
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++){
|
||||||
if (nome.equals(alunos[i].getNome())){
|
if (nome.equals(alunos[i].getNome())){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +101,17 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findAlunoIndex(String nome){
|
private int findAlunoIndex(String nome){
|
||||||
for (int i = 0; i < alunos.length; i++){
|
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++){
|
||||||
if (nome.equals(alunos[i].getNome()))
|
if (nome.equals(alunos[i].getNome()))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
@ -101,8 +129,20 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Acompanhamento findAcompanhamento(String nome){
|
public Acompanhamento findAcompanhamento(String nome){
|
||||||
for (int i = 0; i < acompanhamentos.length; i++){
|
|
||||||
if (acompanhamentos[i].getAluno().getNome().equals(nome)) {
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.acompanhamentos.length; i++){
|
||||||
|
if (this.acompanhamentos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("debug_acompanhamentos.size:"+size);
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
if (this.acompanhamentos[i].getAluno().getNome().equals(nome)) {
|
||||||
return acompanhamentos[i];
|
return acompanhamentos[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,11 +151,19 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String listAlunos(){
|
public String listAlunos(){
|
||||||
if (alunos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E5;
|
return Erro.E5;
|
||||||
|
|
||||||
String lista = "";
|
String lista = "";
|
||||||
for (int i = 0; i < alunos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
lista = lista.concat(alunos[i].getNome() + "\n");
|
lista = lista.concat(alunos[i].getNome() + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,11 +171,20 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String listBolsistas(){
|
public String listBolsistas(){
|
||||||
if (bolsistas.length == 0)
|
int size = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < this.bolsistas.length; i++){
|
||||||
|
if (this.bolsistas[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E5;
|
return Erro.E5;
|
||||||
|
|
||||||
String lista = "";
|
String lista = "";
|
||||||
for (int i = 0; i < bolsistas.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
lista = lista.concat(bolsistas[i].getNome());
|
lista = lista.concat(bolsistas[i].getNome());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,12 +192,20 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String riskReport(){
|
public String riskReport(){
|
||||||
if (acompanhamentos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.acompanhamentos.length; i++){
|
||||||
|
if (this.acompanhamentos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E8;
|
return Erro.E8;
|
||||||
|
|
||||||
String relatorio = "";
|
String relatorio = "";
|
||||||
|
|
||||||
for (int i = 0; i < acompanhamentos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
relatorio = relatorio.concat(acompanhamentos[i].getAluno().getNome() + ": Risco ");
|
relatorio = relatorio.concat(acompanhamentos[i].getAluno().getNome() + ": Risco ");
|
||||||
relatorio = relatorio.concat(acompanhamentos[i].getRiscoLabel() + "\n");
|
relatorio = relatorio.concat(acompanhamentos[i].getRiscoLabel() + "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -150,12 +215,20 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String riskReportHigh(){
|
public String riskReportHigh(){
|
||||||
if (acompanhamentos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.acompanhamentos.length; i++){
|
||||||
|
if (this.acompanhamentos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E8;
|
return Erro.E8;
|
||||||
|
|
||||||
String relatorio = "";
|
String relatorio = "";
|
||||||
|
|
||||||
for (int i = 0; i < acompanhamentos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
if (acompanhamentos[i].getRiscoLabel().equals("ALTO")){
|
if (acompanhamentos[i].getRiscoLabel().equals("ALTO")){
|
||||||
relatorio = relatorio.concat(acompanhamentos[i].getAluno().getNome() + ": Risco ALTO\n");
|
relatorio = relatorio.concat(acompanhamentos[i].getAluno().getNome() + ": Risco ALTO\n");
|
||||||
}
|
}
|
||||||
|
|
@ -168,11 +241,21 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String maiorNome(){
|
public String maiorNome(){
|
||||||
if (alunos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E5;
|
return Erro.E5;
|
||||||
|
if (size == 1)
|
||||||
|
return alunos[0].getNome();
|
||||||
|
|
||||||
int k = 0;
|
int k = 0;
|
||||||
for (int i = 1; i < alunos.length; i++){
|
for (int i = 1; i < size; i++){
|
||||||
if (alunos[i].getNome().length() > alunos[k].getNome().length())
|
if (alunos[i].getNome().length() > alunos[k].getNome().length())
|
||||||
k = i;
|
k = i;
|
||||||
}
|
}
|
||||||
|
|
@ -180,26 +263,42 @@ public class Dados {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String averageAge(){
|
public String averageAge(){
|
||||||
if (alunos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E5;
|
return Erro.E5;
|
||||||
|
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
for (int i = 0; i < alunos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
sum += alunos[i].getIdade();
|
sum += alunos[i].getIdade();
|
||||||
}
|
}
|
||||||
|
|
||||||
sum = sum / alunos.length;
|
sum = sum / size;
|
||||||
return "Idade média dos alunos: " + sum;
|
return "Idade média dos alunos: " + sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String totalVowels(){
|
public String totalVowels(){
|
||||||
if (alunos.length == 0)
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
return Erro.E5;
|
return Erro.E5;
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
for (int k = 0; k < alunos.length; k++){
|
for (int k = 0; k < size; k++){
|
||||||
String nome = alunos[k].getNome();
|
String nome = alunos[k].getNome();
|
||||||
|
|
||||||
for (int j = 0; j < nome.length(); j++){
|
for (int j = 0; j < nome.length(); j++){
|
||||||
|
|
@ -221,10 +320,18 @@ public class Dados {
|
||||||
public void makeChamada(){
|
public void makeChamada(){
|
||||||
this.chamada = "";
|
this.chamada = "";
|
||||||
|
|
||||||
if (alunos.length == 0){
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0){
|
||||||
this.chamada = Erro.E5;
|
this.chamada = Erro.E5;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < alunos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
this.chamada = this.chamada.concat(alunos[i].getMatricula() + " / ");
|
this.chamada = this.chamada.concat(alunos[i].getMatricula() + " / ");
|
||||||
this.chamada = this.chamada.concat(alunos[i].getNome() + " / ");
|
this.chamada = this.chamada.concat(alunos[i].getNome() + " / ");
|
||||||
this.chamada = this.chamada.concat(alunos[i].getCurso() + "\n");
|
this.chamada = this.chamada.concat(alunos[i].getCurso() + "\n");
|
||||||
|
|
@ -241,12 +348,19 @@ public class Dados {
|
||||||
|
|
||||||
public double coursePercent(String curso){
|
public double coursePercent(String curso){
|
||||||
double num = 0;
|
double num = 0;
|
||||||
|
int size = 0;
|
||||||
|
for (int i = 0; i < this.alunos.length; i++){
|
||||||
|
if (this.alunos[i] == null){
|
||||||
|
size = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < alunos.length; i++){
|
for (int i = 0; i < size; i++){
|
||||||
if (alunos[i].getCurso().equals(curso))
|
if (alunos[i].getCurso().equals(curso))
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (num / alunos.length) * 100;
|
return (num / size) * 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,4 +8,5 @@ public class Erro {
|
||||||
public static final String E7 = "Erro: Não foi possível calcular o risco pedagógico.";
|
public static final String E7 = "Erro: Não foi possível calcular o risco pedagógico.";
|
||||||
public static final String E8 = "Erro: Não existem acompanhamentos cadastrados.";
|
public static final String E8 = "Erro: Não existem acompanhamentos cadastrados.";
|
||||||
public static final String E9 = "Erro: Não existe nenhum aluno com risco alto.";
|
public static final String E9 = "Erro: Não existe nenhum aluno com risco alto.";
|
||||||
|
public static final String E10 = "Erro: Numero máximo de alunos atingido.";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,16 @@ public class Gerenciador {
|
||||||
private Dados dados;
|
private Dados dados;
|
||||||
private static Scanner input = new Scanner(System.in);
|
private static Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
String nome = "", local = "", curso = "", matricula = "", projeto = "", orientador = "";
|
|
||||||
int idade = 0, semestre = 0, ano = 0;
|
|
||||||
boolean bolsista = false;
|
|
||||||
|
|
||||||
public Gerenciador(Dados dados) {
|
public Gerenciador(Dados dados) {
|
||||||
this.dados = dados;
|
this.dados = dados;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cadastrarAluno() {
|
public String cadastrarAluno() {
|
||||||
|
String nome = "", local = "", curso = "", matricula = "";
|
||||||
|
int idade = 0, semestre = 0, ano = 0;
|
||||||
|
|
||||||
while (nome.length() == 0){
|
while (nome.length() == 0){
|
||||||
System.out.println("Insira o nome do aluno:");
|
System.out.println("Insira o nome do aluno:");
|
||||||
nome = input.nextLine();}
|
nome = input.nextLine();}
|
||||||
|
|
@ -60,6 +61,7 @@ public class Gerenciador {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cadastrarBolsista(boolean resposta, Aluno alunoparametro) {
|
public String cadastrarBolsista(boolean resposta, Aluno alunoparametro) {
|
||||||
|
String projeto = "", orientador = "";
|
||||||
|
|
||||||
Aluno aluno;
|
Aluno aluno;
|
||||||
|
|
||||||
|
|
@ -74,11 +76,11 @@ public class Gerenciador {
|
||||||
|
|
||||||
while (projeto.length() == 0){
|
while (projeto.length() == 0){
|
||||||
System.out.println("Insira o nome do projeto:");
|
System.out.println("Insira o nome do projeto:");
|
||||||
String projeto = input.nextLine();}
|
projeto = input.nextLine();}
|
||||||
|
|
||||||
while (orientador.length() == 0){
|
while (orientador.length() == 0){
|
||||||
System.out.println("Insira o nome do orientador:");
|
System.out.println("Insira o nome do orientador:");
|
||||||
String orientador = input.nextLine();}
|
orientador = input.nextLine();}
|
||||||
|
|
||||||
Bolsista bolsista = new Bolsista(aluno, projeto, orientador);
|
Bolsista bolsista = new Bolsista(aluno, projeto, orientador);
|
||||||
aluno.setBolsista(true);
|
aluno.setBolsista(true);
|
||||||
|
|
@ -125,12 +127,7 @@ public class Gerenciador {
|
||||||
if (acomp.setAtividadesNaoEstudadas(naoestudadas))
|
if (acomp.setAtividadesNaoEstudadas(naoestudadas))
|
||||||
return Erro.E4;
|
return Erro.E4;
|
||||||
|
|
||||||
if (ia + explicadas + semajuda + naoestudadas > entregues)
|
return this.dados.appendAcompanhamento(acomp);
|
||||||
return Erro.E4;
|
|
||||||
|
|
||||||
this.dados.appendAcompanhamento(acomp);
|
|
||||||
return "Acompanhamento registrado com sucesso.";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String listarAlunos() {
|
public String listarAlunos() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue