Need help with basic math functions
Hey guys I cant seem to got my computations to work! Any clue and what im doing wrong and also how do I get to display an decimal point? thanks very much
in eclipse it says something like string is undefined or something similar
import java.util.Scanner;
import javax.swing.JOptionPane;
public class converter {
public static final int ONE_PENCE_IN_NEW_PENNIES= 67;
public static final int ONE_SHILLING_IN_NEW_PENNIES= 804;
public static final int ONE_OLD_POUND_IN_NEW_PENNIES= 16080;
public static final int ONE_NEW_POUND_IN_NEW_PENNIES= 100;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String oldPoundsInput= JOptionPane.showInputDialog("Insert Pounds:");
Scanner oldPoundsScanner= new Scanner(oldPoundsInput);
String oldShillingsInput= JOptionPane.showInputDialog("Insert Shillings:");
Scanner oldShillingsScanner= new Scanner(oldShillingsInput);
String oldPenceInput= JOptionPane.showInputDialog("Insert Pence:");
Scanner oldPenceScanner= new Scanner(oldPenceInput);
int newPounds = ((oldPenceInput)*(ONE_PENCE_IN_NEW_PENNIES)) + ((oldShillingsInput)*(ONE_SHILLING_IN_NEW_PENNIES) ) + ((oldPoundsInput)*(ONE_OLD_POUND_IN_NEW_PENNIES));
JOptionPane.showMessageDialog(null, "The value is:"+newPounds);
}
}
Re: Need help with basic math functions
Please see the announcements page for important information including the use of code tags on the posted code.
Quote:
it says something like string is undefined or something similar
You have to put this thing here in that place over there or something similar. Seriously how do you expect anyone to have a clue what you are talking about. Copy paste the error messages so people can see what they say. Something similar can be a different but similar problem.
Re: Need help with basic math functions
You are trying to do a multiplication of a String and an integer.
Try and use something like double values for currency.
You can then format the output to round off the double to 2 decimal places.