DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: A little help!

Hybrid View

  1. #1
    Eric Guest

    A little help!


    Can anyone help me with this little problem, I need to make my sum a
    float so that the answer can be decimal numbers. I would
    really appreicate it . Thanks, Eric


    import javax.swing.JOptionPane;


    public class paycheck{

    public static void main( String[] args )
    {

    String hours, // Hours worked
    name, // Name of worker
    rate; // Hourly rate


    int number1, // first number to multiply
    number2, // second number to multiply
    sum; // sum of both numbers

    // Prompt user to enter name
    name = JOptionPane.showInputDialog( "Who Goes There?" );


    // Prompt user to enter hours worked
    hours = JOptionPane.showInputDialog( "Please enter your hours
    worked"
    );


    // Prompt user to enter horly rate
    rate = JOptionPane.showInputDialog( "Please enter your hourly
    rate"
    );


    // convert from string to int
    number1 = Integer.parseInt( hours );
    number2 = Integer.parseInt( rate );


    // multiply the numbers
    sum = number1 * number2;


    // display the check
    JOptionPane.showMessageDialog( null, "Pay to the order of:
    " +
    name + sum, "PayCheck", JOptionPane.PLAIN_MESSAGE );


    System.exit(0);
    }


    }



  2. #2
    ray/ Guest

    Re: A little help!


    Try using doubleint in the code, instead of just int by itself.
    ament too sure on this but it may work...

    "Eric " <wdiv@hotmail.com> wrote:
    >
    >Can anyone help me with this little problem, I need to make my sum a
    > float so that the answer can be decimal numbers. I would
    > really appreicate it . Thanks, Eric
    >
    >
    > import javax.swing.JOptionPane;
    >
    >
    > public class paycheck{
    >
    > public static void main( String[] args )
    > {
    >
    > String hours, // Hours worked
    > name, // Name of worker
    > rate; // Hourly rate
    >
    >
    > int number1, // first number to multiply
    > number2, // second number to multiply
    > sum; // sum of both numbers
    >
    > // Prompt user to enter name
    > name = JOptionPane.showInputDialog( "Who Goes There?" );
    >
    >
    > // Prompt user to enter hours worked
    > hours = JOptionPane.showInputDialog( "Please enter your hours
    >worked"
    > );
    >
    >
    > // Prompt user to enter horly rate
    > rate = JOptionPane.showInputDialog( "Please enter your hourly
    >rate"
    > );
    >
    >
    > // convert from string to int
    > number1 = Integer.parseInt( hours );
    > number2 = Integer.parseInt( rate );
    >
    >
    > // multiply the numbers
    > sum = number1 * number2;
    >
    >
    > // display the check
    > JOptionPane.showMessageDialog( null, "Pay to the order of:
    >" +
    > name + sum, "PayCheck", JOptionPane.PLAIN_MESSAGE );
    >
    >
    > System.exit(0);
    > }
    >
    >
    > }
    >
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links