Estou fazendo um projeto em que devem aparecer os dados do livro e o nome do autor em formato ABNT. Porém não consigo ajustar o código para que dê certo…
public class Livro {
String titulo;
int ano;
String editora;
String autor;
public String getAutorFormatoAbnt ();
public String getInformacaoCompletaLivro ();
}
public class autor {
public static void main(String[] args) {
String vetor;
String nome = "autor/nome";
String[] array = nome.split("/");
for (int i = vetor.length(); i>0; i--){
if (i>--i){
System.out.println(vetor[i].toUpperCase(vetor[i])+", "+vetor[--i]);
}
}
}
}
O .lenght não funcionava de jeito nenhum… declarei private e joguei para cima do main. E o toUpperCase tive que criar um método no final. Porquê isso? Ficou assim:
public class autor {
private int codigo;
private String nome;
private char tipoLiterario;
public static void main(String[] args) {
autor[] nome = new autor[20];
for (int i = nome.length; i>0; i--){
if (i>--i){
System.out.println(nome[i].toUpperCase()+", "+nome[--i]);
}
}
}
private String toUpperCase() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of
generated methods, choose Tools | Templates.
}
}
Outro erro que não sei como escrever…
public class Livro {
private String titulo;
private int ano;
private String editora;
private String autor;
public String getAutorFormatoAbnt(){
return autor;
}
public void setAutorFormatoAbnt(String autor){
this.autor = autor;
}
public String getInformacaoCompletaLivro (){
return titulo + editora + ano + autor;
}
public void setInformacaoCompletaLivro(String (String titulo)(String editora)(String ano)
(String autor)){
this.titulo = titulo;
this.ano = ano;
this.editora = editora;
this.autor = autor;
}
}
Tipo no return eu uso + para retornar mais de um, mas no //public void seInformacaoCompletaLivro ( bla)// como declaro todas as informações? sendo que o ano é int. ?
Entendi, deu certo. Mas e sobre o toUpperCase? em todas aplicações nenhuma da certo sem aquele método para me atrapalhar… será que falta algum import? tipo Math.random, o .lenght e toUpperCase (sempre aparecem erro).
Sei que eu digitei ali o codigo com () mas ja havia testado com e sem parenteses.
— maven-resources-plugin:2.6:resources (default-resources) @ MeuLivro —
Using ‘UTF-8’ encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\aless\Documents\NetBeansProjects\MeuLivro\src\main\resources
— maven-compiler-plugin:3.1:compile (default-compile) @ MeuLivro —
Nothing to compile - all classes are up to date
— exec-maven-plugin:1.5.0:exec (default-cli) @ MeuLivro —
Exception in thread “main” java.lang.NullPointerException
at com.mycompany.meulivro.autor.main(autor.java:15)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
BUILD FAILURE
Total time: 7.072 s
Finished at: 2020-03-10T18:24:48-03:00
Final Memory: 8M/34M
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project MeuLivro: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
public class autor {
private int codigo;
private String nome;
private char tipoLiterario;
String Nome = nome.toUpperCase();
public static void main(String[] args) {
autor[] nome = new autor[20];
for (int i = nome.length; i>0; i--){
if (i>--i){
System.out.println(nome[i].toUpperCase()+", "+nome[--i]);
}
}
}
}
Obs: continua dando como erro o System.out.println(nome[i].toUpperCase()+", "+nome[–i]);
public class Livro {
private String titulo;
private int ano;
private String editora;
private String autor;
public String getAutorFormatoAbnt(){
return autor;
}
public void setAutorFormatoAbnt(String autor){
this.autor = autor;
}
public String getInformacaoCompletaLivro (){
return titulo + editora + ano + autor;
}
public void setInformacaoCompletaLivro(String titulo, String editora, int ano,String autor){
this.titulo = titulo;
this.ano = ano;
this.editora = editora;
this.autor = autor;
}
}