I'm doing a simple program to learn java. I have the input and math parts right. It just isn't displaying right. It outputs a list of about 11 things-- with the format "string $ xx.xx"
In each line the '$'s should be aligned and the decimal point should be aligned.
This is what it currently shows-
In each line the '$'s should be aligned and the decimal point should be aligned.
This is what it currently shows-

Code:
package excercise6;
import java.swing.*;
/**
*
* @author dye1107
*/
public class Main {
/* @param args the command line arguments
*/
public static void main(String[] args) {
String str, name;
Double gross, net;
Double fed, state, ss, medicare, pension;
final Double health=75.00;
name = JOptionPane.showInputDialog("What is your name: ");
str = JOptionPane.showInputDialog("What is your gross pay: ");
gross = Double.parseDouble(str);
fed = gross*0.15;
state = gross*0.035;
ss = gross*0.0575;
medicare = gross*0.0275;
pension = gross*0.05;
net = gross-fed-state-ss-medicare-pension-health;
JOptionPane.showMessageDialog(null, name + "\n" + String.format("%-40s", "Gross Amount:")+ "$" + String.format("%10.2f", gross) + "\n" + String.format("%-40s", "Federal Tax:") + "$" + String.format("%10.2f", fed) + "\n" + String.format("%-40s", "State Tax:") + "$"+ String.format("%10.2f", state) + "\n" + String.format("%-40s", "Social Security Tax:") + "$"+ String.format("%10.2f", ss) + "\n" + String.format("%-40s", "Medicare/Medicade Tax:") + "$"+ String.format("%10.2f", medicare) + "\n" + String.format("%-40s", "Pension Plan:") + "$"+ String.format("%10.2f", pension) + "\n" + String.format("%-40s", "Health Insurance:") + "$"+ String.format("%10.2f", health));
}
}
Comment