Hey guys, I try to write my own Java software but I have big problem, can any one can help,
here my code:
My Main Class is:
package anproject2;
import javax.swing.JOptionPane;

public class Main {
public static void main(String[] args){
data1 d = new data1();
d.openFile();
int x =1;

do{
String price = JOptionPane.showInputDialog("input price:");
d.addRecords();
String unit = JOptionPane.showInputDialog("Input unit:");
d.addRecords();
try{
int num1 = Integer.parseInt(price);
int num2 = Integer.parseInt(unit);
int amount = num1*num2;


JOptionPane.showMessageDialog(null, "The total amount is: "+amount, "Program", JOptionPane.PLAIN_MESSAGE);
d.addRecords();
JOptionPane.showMessageDialog(null, "The total VAT is: "+amount*11/10, "Program", JOptionPane.PLAIN_MESSAGE);
d.addRecords();
d.closeFile();
x=2;
}
catch(Exception e){

JOptionPane.showMessageDialog(null, "error!");
}
}while(x==1);
}

}


and class:
package anproject2;

import java.util.*;
public class data1 {
String[] input = { "code", "lot","pallet","quantity"};
private Formatter x;

public void openFile(){
try{
x = new Formatter("data1.csv");
}
catch(Exception e){
System.out.println("error!");
}
}
public void addRecords(){
x.format("%s,%s,%s,%s\n", "code", "lot","pallet","quantity");
}

public void closeFile(){
x.close();
}
}


HERE IS THE PROBLEM:
whenever I try to put value from MessageDialog to databse, it not work it give 4 time like this:
code lot pallet quantity
code lot pallet quantity
code lot pallet quantity
code lot pallet quantity

I also try to continue add value to data when i start my progame, but it not, it generate exactly the same file...

can anyone show me how to fix it?