Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-16-2007, 06:53 PM
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
Correct Number formatting
I have tried to figure out how to implement the java.text.DecimalFormat import, but I couldn't figure out the correct syntax to apply it to my numbers. This program is for an entry level programming class. The application require it actually be formatted, but I want to know how to anyway.

I have an employee ID number that I need formatted without any decimal places, the dollar amounts to have two decimals places, and the employee hours to only have decimal places.
Can anyone maybe explain the syntax for any particular variable I am using

Here's what I have:

Code:
import java.util.Scanner; public class FigureWages { public static void main(String[] args) { double employeeNumber; double payRate; double wagesTotal; // Total wages of all employees double amountEarned; double hoursWorked; double formTotal; //loop counter String employeeTotalString; double employeeTotal; Scanner input = new Scanner(System.in); do{ System.out.print("\n Please enter the total number of employees: "); employeeTotalString = input.nextLine(); employeeTotal = Double.parseDouble(employeeTotalString); }while (employeeTotal <= 0);// end do-while loop for (formTotal = employeeTotal, amountEarned = 0, wagesTotal = 0; formTotal > 0; formTotal--, employeeTotal--) { System.out.print("\n\n Please enter your employee number:"); employeeNumber = input.nextDouble(); System.out.print("\n Please enter your base rate of pay per hour: "); payRate = input.nextDouble(); System.out.print("\n Please enter your number of hours worked: "); hoursWorked = input.nextDouble(); //overtime calculations if (hoursWorked <= 40){ amountEarned = payRate * hoursWorked; wagesTotal += amountEarned; } else if (hoursWorked > 40 && hoursWorked <=60){ amountEarned = (40 * payRate) + ((hoursWorked - 40) * (payRate * 1.5)); wagesTotal += amountEarned; } else if (hoursWorked >= 60){ amountEarned = (40 * payRate) + ((hoursWorked - 40) * (payRate * 1.5)) + (hoursWorked * 2); wagesTotal += amountEarned; } System.out.print("\n\n\tEmployee ID#: " + employeeNumber); System.out.print("\n\tTotal hours worked: " + hoursWorked); System.out.print("\n\tPay rate: "+ payRate + " (per hour)"); System.out.print("\n\tTotal wages earned by employee: " + "$" + amountEarned + "\n\n\n"); }// end for loop System.out.print("\n\t Total wages earned by all employees: " + "$" + wagesTotal + "\n\n\n"); } }
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 06:59 AM
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
You could try the printf method. PrintStream (Java 2 Platform SE 5.0)

Something like...
Code:
System.out.printf("\n\t Total wages earned by employee: $ %.2f \n\n\n", amountEarned);
I not sure the above is proper syntax and I don't have the means to check at the moment.

Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting a number to currency Java Tip java.text 0 04-17-2008 12:59 AM
Is my Pseudocode correct? Clemenza1983 New To Java 0 01-29-2008 06:07 AM
formatting.. sireesha New To Java 10 01-07-2008 09:51 AM
formatting String bugger New To Java 1 11-16-2007 09:27 PM
Formatting the date yuchuang New To Java 5 05-07-2007 08:08 PM


All times are GMT +3. The time now is 11:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org