I've been at my wits end with this problem. In a class right now and for this assignment I'm needed to use the Scanner to input data and use this same data within my nested methods to calculate two things; Temperature Conversion and Currency Conversion.
Problem I'm having is I have no idea how to define my variables throughout my whole piece of code, as I get compiler errors saying that certain variables aren't defined; e.g. tC, and euro.
How do I assign those two variables to be able to compile this correctly?
import java.util.Scanner;
public class MethodsMS {
// required main method of the class
public static void main(String [] args) {
performTemperatureConversion();
System.out.println(); // blank line
performCurrencyConversion();
double numDouble;
} // end main
// (no changes needed above this point)
//--------------------------------------------------------------
// (write the following methods)
//--------------------------------------------------------------
// write method to perform temperature conversion...
public static void performTemperatureConversion()
{
double numDouble;
readDouble();
degreeConversion();
display();
}
//--------------------------------------------------------------
// write method to perform currency conversion...
public static void performCurrencyConversion()
{
readDouble();
currencyConversion();
display();
}
//--------------------------------------------------------------
// write method to obtain an input double value (use Scanner)...
public static double readDouble()
{
double numDouble;
Scanner input = new Scanner(System.in);
System.out.print("Enter a double number: ");
numDouble = input.nextDouble();
return numDouble;
}
//--------------------------------------------------------------
// write method to print an input string inside a formatted box...
public static void display()
{
System.out.print("Conversion number is now: " + numDouble);
}
//--------------------------------------------------------------
// write method to convert F to C...
public static void degreeConversion()
{
double numDouble, tC;
tC = (numDouble - 32) * 5/9;
return;
}
//--------------------------------------------------------------
// write method to convert $ to Euros...
public static void currencyConversion()
{
double euro;
euro = numDouble * 0.894614;
return euro;
}
} // end class
return euro;) and input parameters (i.e.performTemperatureConversion(double numDouble)). That looks like what you want to be doing more than what you asked.