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 3 of 3

Thread: Question about formatting output

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    55
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default Question about formatting output

    In the following program the output is being written all on one line. I added line separators "/n". Why are they not working?


    import javax.swing.*;
    import java.io.*;
     
    public class Monthly_pay
    {
    	static final double FED_TAX = .15;
    	static final double STATE_TAX = .035;
    	static final double SS_TAX = .0575;
    	static final double MEDICARE = .0275;
    	static final double PENSION = .05;
    	static final double HEALTH_INS = 75.00;
     
    	public static void main(String[] args)
    	{
    		String name, grossPay;
    		double netPay, dGrossPay, fedTax, stateTax, ssTax, medicare, pension, healthIns;
     
    		JOptionPane jop = new JOptionPane();
     
    		name = jop.showInputDialog("Please enter the employee name: ");
    		grossPay = jop.showInputDialog("Please enter the employee's gross pay: ");
     
    		dGrossPay = Double.parseDouble(grossPay);
     
    		fedTax = dGrossPay * FED_TAX;
    		stateTax = dGrossPay * STATE_TAX;
    		ssTax = dGrossPay * SS_TAX;
    		medicare = dGrossPay * MEDICARE;
    		pension = dGrossPay * PENSION;
    		netPay = dGrossPay - (fedTax + stateTax + ssTax + medicare + pension + HEALTH_INS);
     
     
    		jop.showMessageDialog(null, "Here is the break down of" + " "  + name + "'s" + " " +
    									"monthly pay. " + "/n"
    									+ "Gross pay: $" + String.format("%.2f", dGrossPay) + "/n"
    									+ "Federal Tax: $" + String.format("%.2f", fedTax) + "/n"
    									+ "State Tax: $" + String.format("%.2f", stateTax) + "/n"
    									+ "Social Security Tax: $" + String.format("%.2f", ssTax) + "/n"
    									+ "Medicare / Medicade: $" + String.format("%.2f", medicare) + "/n"
    									+ "Pension Plan: $" + String.format("%.2f", pension) + "/n"
    									+ "Health Insurance: $" + String.format("%.2f", HEALTH_INS) + "/n"
    									+ "Net Pay: $" + String.format("%.2f", netPay));
     
    		System.exit(0);
     
     
    	}
    }

    Thanks in advance!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Question about formatting output

    Do the /n characters print on the output? That would mean that they are ordinary characters and not the escaped newline character. The escape character is \

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    55
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default Re: Question about formatting output

    LOL DUH?
    Thanx!!!! or should I say thanx \\\\\\\\\\\\\\

Similar Threads

  1. Gson Formatting
    By techwiz24 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 07:48 PM
  2. Help with formatting spacing on a calender grid please!
    By bulx0001 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 27th, 2011, 12:53 AM
  3. HSSF cell date formatting in java
    By masepogurajesh in forum Java SE APIs
    Replies: 1
    Last Post: March 15th, 2011, 08:45 AM
  4. Formatting output of a Double
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2010, 04:20 PM
  5. Replies: 3
    Last Post: August 19th, 2009, 11:30 AM