-2
package aplicativo_enel;
public class A1_Residencial {
//Atributos entrada de dados
int imposto1;
final int ICMS1 = 0;
private float leitura;
private final float TE = 0.25588f;
private final float TUSD = 0.25971f;
private final float COSIP = 9.70F;
int icmsResidencial() {
return imposto1;
}
String situacao( ) {
if (icmsResidencial() <= ICMS1) {
System.out.println("Você esta Isenta de imposto ICMS");
}else if(icmsResidencial() > ICMS1 && icmsResidencial() == ICMS1) {
System.out.println("12% de ICMS");
}else {
System.out.println("25% de ICMS");
}
}
// Construtores
public A1_Residencial () {
this.leitura = 0.0f;
}
public A1_Residencial (float leitura) {
this.leitura = leitura;
}
//Métodos de acesso
public float getLeitura() {
return this.leitura;
}
public float getTe() {
return this.TE;
}
public float getTusd() {
return this.TUSD;
}
public void setLeitura(float leitura) {
this.leitura = leitura;
}
// Comportamento - saída
public float consumo () {
return getTe() + getTusd() * getLeitura();
}
public float PrecoParcial() {
return consumo() + COSIP;
}
@Override
public String toString(){
String residencial = "Conta Enel";
residencial += "\nLeitura " + getLeitura();
residencial += "\nConsumo + Eletrica + Sistema de Distribuição R$" + consumo();
residencial += "\nValor Parcial R$" + PrecoParcial();
residencial += "\nIMCS " + situacao();
return residencial;
}
}
Hello guys, my code makes a mistake and talks "this method should return a string type result". The error is in String situacao()...
.
Could someone help me how to fix this please ?
Your
if
is weird. First you test ificmsResidencial() <= ICMS1
(up here, ok). But then you doelse if(icmsResidencial() > ICMS1 && icmsResidencial() == ICMS1)
- that is, ificmsResidencial
is larger and equal toICMS1
(There’s no way he’s bigger and equal at the same time, so you’ll never get into thatif
). And as the firstif
already tests whether it is less or equal, the only alternative that remains for theelse
is that he’s bigger, so that’selse if
doesn’t make sense.– hkotsubo