I'm continuing my studies on object-oriented Java programming.
I'm currently studying encapsulation and get
and set
methods and came across the following exercise:
Encapsulate the value attribute of the Ticket class.
This attribute should not be set directly. The user of the class informs the value and the student. If the student is approved a 10% discount on the ticket amount is granted and the get method must display the amount with the discount granted.
And I created this code:
Student Class:
package Academico;
public class Aluno {
public String nome;
private String matricula;
private String curso;
protected Disciplina disciplina[];
}
Class Discipline:
package Academico;
public class Disciplina {
String nome;
double nota1, nota2, nota3, nota4;
}
Ticket Class:
package Financeiro;
import Academico.*;
public class Boleto {
private Aluno aluno;
private String referencia;
private double valor;
public Boleto(Aluno aluno, String referencia, double valor){
this.aluno = aluno;
this.referencia = referencia;
this.valor = valor;
}
public double desconto() {
disciplina = new Disciplina[3];
if(disciplina == true){
this.valor = this.valor-(this.valor*0.1);
return this.valor;
}
}
public double getValorDesconto() {
return this.valor;
}
}
Is there any error in constructing the code, in the encapsulation and in the methods Get
and Set
?