public class Customer { private String firstName; private String lastName; private int ID; private int numberPhone; priv
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
public class Customer { private String firstName; private String lastName; private int ID; private int numberPhone; priv
public int getNumberOfReadBook() { return numberOfReadBook; } public void setNumberOfReadBook(int numberOfReadBook) ( this.numberOfReadBook numberOfReadBook; } public int getNumberPhone() { return numberPhone; } public void setNumberPhone (int numberPhone) { this.numberPhone numberPhone; } public String getPassword() { return password; } public void setPassword(String password) { this.password password; } public String getAddress() { return address; } public void setAddress (String address) { this.address address; } @Override public String toString() ( return "firstName= + firstName + "\nlastName= " + lastName + "\nID=" + ID + "\nnumberPhone numberPhone + "\npassword="+password + "\naddress= " + address + "\nnumberOfReadBook + numberOfReadBook; } public String toPrint() { return "firstNames + firstName + "\nlastName= " + lastName + "\nID="ID + "\nnumberPhone= " + numberPhone + "\naddress=" + address; } // a function to create new file with number of customer then // save her/his information to the file public void SaveToFile() throws FileNotFoundException { File file = new File(numberPhone + ".txt"); Printwriter pw = new PrintWriter(file); pw.println(this); pw.close(); } // a function to get if user can login // to his account or not by number phone and password public boolean Login() { File file = new File(numberPhone + ".txt"); // if there is not any account with this number then cannot loggin if (!file.exists()) {
} // a function to get if user can login // to his account or not by number phone and password public boolean Login() { File file = new File(numberPhone + ".txt"); // if there is not any account with this number then cannot loggin if (!file.exists()) { return false; } else {//else try { Scanner scanner = new Scanner (file); //read information from file String fName = scanner.nextLine().split("= ")[1]; String 1Name = scanner.nextLine().split("= ")[1]; int ID = Integer.valueOf(scanner.nextLine().split(" ")[1]); int numberPhone = Integer.valueOf (scanner.nextLine().split("= ")[1]); String password = scanner.nextLine().split("= ")[1]; String address = scanner.nextLine().split("= ")[1]; int numberOfReadBook = Integer.valueOf (scanner.nextLine().split("= ")[1]); // if number phone and password are matched // then can loggin if (numberPhone == this.numberPhone && password.equals(this.password)) setFirstName (fName); setLastName (1Name); setID(ID); setAddress (address); set NumberOfReadBook (numberOfReadBook); return true; } catch (FileNotFoundException ex) { } // there is not any matched values return false;