Ciao ragazzi,
ho un problema con questo codice:
import java.io.*;
public class CALCOLA {
static double operando1;
static double operando2;
static String operatore;
static double RISULTATO;
void PRENDIADDENDO(double operando) { //prende numero e lo converte da stringa a intero
String stringa = ""; //inizializzo stringa vuota
try { BufferedReader flussoInput = new
BufferedReader(new InputStreamReader(System.in));
stringa = flussoInput.readLine();
}
catch (Exception e){ System.out.println("Errore: " + e + " in input");
System.exit(0);
}
operando = Double.valueOf(stringa).doubleValue();
return;
}
void PRENDISEGNO() { //prende operatore
String stringa = "";
try { BufferedReader flussoInput = new
BufferedReader(new InputStreamReader(System.in));
stringa = flussoInput.readLine();
}
catch (Exception e){ System.out.println("Errore: " + e + " in input");
System.exit(0);
}
operatore = stringa;
return;
}
boolean SVOLGICALCOLO() {
if ( operatore.compareTo("+") == 0) //se 0 che viene da compareTo e' uguale a 0 da' true
{ RISULTATO = operando1 + operando2;
return true;
}
else if ( operatore.compareTo("-") == 0)
{ RISULTATO = operando1 - operando2;
return true;
}
else if ( operatore.compareTo("*") == 0)
{ RISULTATO = operando1 * operando2;
return true;
}
else if ( operatore.compareTo("/") == 0)
{ if (operando2 != 0)
{ RISULTATO = operando1 / operando2;
return true;
}
else
{ return false;
}
}
else
{ return false;
}
}
void STAMPACALCOLA() {
System.out.println("Ecco il risultato: " + RISULTATO);
}
public static void main (String args[]) {
CALCOLA RESULT;
boolean OPERATOREVALIDO;
RESULT = new CALCOLA(); //istanziamento oggetto RESULT
System.out.println("PRIMO:");
RESULT.PRENDIADDENDO(operando1); // INSERISCI PRIMO OPERANDO, richiama metodo PRENDIADDENDO1
System.out.println("SECONDO:");
RESULT.PRENDIADDENDO(operando2); // INSERISCI SECONDO OPERANDO, richiama metodo PRENDIADDENDO2
System.out.println("OPERAZIONE:");
RESULT.PRENDISEGNO (); // INSERISCI SEGNO
OPERATOREVALIDO = RESULT.SVOLGICALCOLO();
if ( OPERATOREVALIDO == true)
{ RESULT.STAMPACALCOLA();
}
else
{ System.out.println("sbagliato non hai messo operando giusto");
}
}
}
alla compilazione nessun errore, se poi lancio il programma, mi torna sempre 0.0 come risultato qualsiasi cifra inserisco.. dove ho sbagliato????
Grazie dell'aiuto che saprete darmi,
Ciao,Antonio

Rispondi quotando
