I am new to Java, and having problems with the use of DecimalFormat. When I compile the program it gives me an error so it doesn't work. I am not sure what I am doing wrong. I think that I am using the syntax correctly. When I take out the DecimalFormat it compiles and runs, but I would like the output with commas. What am I doing wrong here?
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class yeargas { public static void main(String[] args) { int tank, month; double year, yearx ,total; String input; DecimalFormat formatter=new DecimalFormat(0,000); //get the average cost to fill 1 tank of gas input=JOptionPane.showInputDialog("What is the average cost to fill 1 tank of gas? "); tank=Integer.parseInt(input); //get the x number of times you fill in a month input=JOptionPane.showInputDialog("What is the average number of times you fill your car in a month? "); month=Integer.parseInt(input); //calculate the cost for a month //multiply that by 1 year year=(tank*month)*12; //get the x number of years to calculate input=JOptionPane.showInputDialog("How many years do you want to calculate for? "); yearx=Integer.parseInt(input); total=yearx*year; //display the aproximate total cost for x JOptionPane.showMessageDialog(null,"Your average cost of gas for "+yearx+" is $"+(formatter.format(total))+".");//total+"."); System.exit(0); } }