3
I have the following code one ebook
who inherits the class Livro
(superclass).
However, I can’t create a new ebook
and set in name, when I put the main method (main
) makes a mistake.
Class Autor
:
public class Autor {
private String nome;
private String cpf;
private String email;
}
Class Livro
:
public class Livro {
private String nome;
private String descricao;
private double valor;
private String isbn;
private Autor autor;
private boolean impresso;
public Livro(Autor autor) {
this.autor = autor;
this.isbn = "00-000-0000-00";
this.impresso = true;
}
public void setNome(String nome) {
this.nome = nome;
}
public String nome() {
return nome;
}
public boolean aplicaDescontoDe(double porcentagem) {
if(porcentagem > 0.3) { //for maior que 30%
return false; //retorna falso;
} else if (!this.impresso && porcentagem > 0.15){ //se livro digital e for maior que 15% de desconto
return false; //retorna falso
}
this.valor -=this.valor *porcentagem;
return true;
}
}
Class Ebook
:
public class Ebook extends Livro {
private String waterMark;
public Ebook(Autor autor) {
super(autor); //superclasse
}
public void setWaterMark(String weterMark) {
this.waterMark = waterMark;
}
public String getWaterMark() {
return waterMark;
}
}
I can’t call the main
in class Ebook
and create a new object ebook
, and set the name, and gives error.
Ebook ebook = new Ebook() {
ebook.setNome("Bla bla bla");
}
Error it, I create the object in the Ebook class? And the main one too? because the set and get of the name(private) is in the Book class
– Leonardo
@Leonardinho already updated the answer, missing some builders also
– Bruno César
@Leonardinho updated the answer, see if you have any questions about modeling =)
– Bruno César
Okay, settled...
– Leonardo