I have this being performed on a button click event The employee class has a toString method which would display everything that it took to make that object. Once it gets to print the zipcode using FileWriter though, the first 0 in place doesn't show up.
private class ButtonListenerSubmit implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
int phone, zipcode;
double pay;
String phoneString, zipcodeString, payString;
phoneString = phoneNumberTF.getText();
zipcodeString = zipcodeTF.getText();
payString = payRateTF.getText();
phone = Integer.parseInt(phoneString);
zipcode = Integer.parseInt(zipcodeString);
pay = Double.parseDouble(payString);
Employee one = new Employee(fNameTF.getText(), lNameTF.getText(), addressTF.getText(), townTF.getText(), stateTF.getText(), zipcode, phone, pay);
try {
PrintWriter out = new PrintWriter(new FileWriter(one.lastName + one.firstName + ".txt"));
out.println(one);
out.close();
} catch(IOException e) {
}
}
}
Problem is that your
zipcode
is anint
integers won't hold012345
they'll automatically truncate it to12345
.Try a string.