Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need help with basic math functions

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Thanked 0 Times in 0 Posts

    Question 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);


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    My Mood
    Thanked 263 Times in 232 Posts

    Default 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.

    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.
    Last edited by jps; October 9th, 2012 at 10:47 AM.

  3. #3
    Join Date
    Sep 2012
    Thanked 14 Times in 14 Posts

    Default 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.

Similar Threads

  1. Help me with a very basic math algorithm?
    By seaofFire in forum Java Theory & Questions
    Replies: 5
    Last Post: May 22nd, 2012, 08:53 PM
  2. Replies: 1
    Last Post: February 14th, 2012, 11:53 AM
  3. Basic Math Expression Java Problem
    By andyluvskrissy in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 15th, 2011, 02:22 AM
  4. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  5. Basic Math Expression Java Problem
    By andyluvskrissy in forum Object Oriented Programming
    Replies: 3
    Last Post: September 30th, 2010, 02:46 PM