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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 2 of 2

Thread: Help with formatting and creating a user defined class.

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

    Default Help with formatting and creating a user defined class.

    Hi all, I'm new to the forum and Java and was hoping I could get some help with a project I'm working on. I'm creating a wages calculator. I have the program working fine, but I want to step it up further by formatting the output and having the program run by using a user defined class. Here's my code:

    import java.util.Scanner;
    public class WagesCalculator {
        public static void main(String [] args){
     
            int H;
     
              Scanner hours = new Scanner (System.in);
        System.out.println("Number of hours worked in a week:");
     
            H = hours.nextInt();
            double G = H*23.67;
            double F = G*.1218;
            double M = G*.0145;
            double S = G*.042;
            double NYS = G*.0355;
            double NYC = G*.0228;        
            double T = 10.00+F+M+S+NYS+NYC;
            double N = G-T;
     
        System.out.println("Calculating gross pay and witholdings...");
        System.out.println("Gross Pay:            $     " + G);
        System.out.println("Fed income tax:       $     " + F);
        System.out.println("Medicare:             $     " + M);
        System.out.println("Social Security:      $     " + S);
        System.out.println("NYS income tax:       $     " + NYS);
        System.out.println("NYC income tax:       $     " + NYC);
        System.out.println("Union due:            $     10.00");
        System.out.println("                            -------------");
        System.out.println("Net-Take home pay:    $     " + N);
        }
    }

    I would like my output to look like this:

    Screen Shot 2014-10-01 at 2.09.37 PM.jpg

    Currently I have it looking like this:

    Screen Shot 2014-10-01 at 2.16.20 PM.png

    Any help is greatly appreciated.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with formatting and creating a user defined class.

    This is the first result for googling "java format number" and contains exactly what you're looking for: Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. To creating user defined packages
    By vishvaD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 1st, 2014, 03:40 PM
  2. User defined classes and loops
    By Spanky_10 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 22nd, 2013, 03:20 PM
  3. User Defined Criteria
    By SimonTemplar in forum Java Theory & Questions
    Replies: 0
    Last Post: February 20th, 2013, 07:02 PM
  4. User-Defined Methods
    By ZippyShannon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 28th, 2011, 10:23 PM
  5. User Defined Methods
    By mgutierrez19 in forum Object Oriented Programming
    Replies: 11
    Last Post: October 20th, 2009, 06:57 PM

Tags for this Thread