I am trying to write the information into a textfile after the user has input all their fields. My text file have a already some information in it.
Anthony Ducan;anthony;a123;55 Peter Street;3321444;VISA;3213504011223 Barry Blake;barry;a999;456 George Street;23239876;VISA;435677779876 Claire Rerg;clare;c678;925 Edward Lane;67893344;MASTERCARD;223344556677
I want to enter them into as a string into my textfile, and each line has multiple items seprated by ;
.
Do I need to open my file , read what it contains before adding new information , or I can just simply add into it?
I have set up a constructor for inputting values, but how do I use it? Do i need to make a new method for my main to call it?
import java.io.*;
import java.util.*;
public class newCust{
String name,username,password,address,contact,creditType,creditNum;
Scanner input = new Scanner(System.in);
public newCust(String name , String username, String password, String address, String contact, String creditType, String creditNum){
this.name= name;
this.username= username;
this.password = password;
this.address = address;
this.contact = contact;
this.creditType = creditType;
this.creditNum = creditNum;
System.out.println("Welcome to Kreg Hotel Booking System");
System.out.println("==============================================");
System.out.println("Please enter your name: ");
name = input.nextLine();
System.out.println("Please enter your login username: ");
username = input.nextLine();
System.out.println("Please enter your login password: ");
password = input.nextLine();
System.out.println("Please enter your address: ");
address = input.nextLine();
System.out.println("Please enter your contact: ");
contact = input.nextLine();
System.out.println("Please enter your credit card type: ");
creditType = input.nextLine();
System.out.println("Please enter your credit card number: ");
creditNum = input.nextLine();
try{
PrintWriter fileout = new PrintWriter("customerinfo");
newCust info = new newCust(name,username,password,address,contact,creditType,creditNum);
fileout.print(info);
}
catch(IOException ex){
}
}
public static void main(String[] args){
}
}