fix
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package org.Exceptions;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FileService {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("Enter you first name: ");
|
||||
String firstName = scanner.nextLine();
|
||||
|
||||
System.out.println("Enter you last name: ");
|
||||
String lastName = scanner.nextLine();
|
||||
|
||||
System.out.println("Enter your national code: ");
|
||||
Long nationalCode = scanner.nextLong();
|
||||
scanner.nextLine();
|
||||
|
||||
System.out.println("Enter your email: ");
|
||||
String email = scanner.nextLine();
|
||||
|
||||
System.out.println("Enter your phone number: ");
|
||||
Long phoneNumber = scanner.nextLong();
|
||||
scanner.nextLine();
|
||||
|
||||
System.out.println("Enter your dateOfBirth: ");
|
||||
String dateOfBirth = scanner.nextLine();
|
||||
|
||||
UserEntity user = null;
|
||||
|
||||
user = new UserEntity(firstName, lastName, nationalCode, email, phoneNumber, parseDate(dateOfBirth));
|
||||
|
||||
System.out.println(user.toString());
|
||||
|
||||
System.out.println(writeFile(user));
|
||||
readFile();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String writeFile(UserEntity user) {
|
||||
//TODO: Uncomment the lines below.
|
||||
//TODO: Use your knowledge of exception handling to make the code work as expected
|
||||
|
||||
/* Uncomment this section
|
||||
//TODO: handle the exception
|
||||
FileWriter fw = new FileWriter("userInformation.txt", true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
|
||||
bw.write(user.toString());
|
||||
bw.close();
|
||||
*/
|
||||
return "user information written to file";
|
||||
}
|
||||
|
||||
|
||||
public static void readFile() {
|
||||
//TODO: Uncomment the lines below.
|
||||
//TODO: Use your knowledge of exception handling to make the code work as expected
|
||||
|
||||
/* Uncomment this section
|
||||
FileReader file = new FileReader("userInformation.txt");
|
||||
|
||||
BufferedReader fileInput = new BufferedReader(file);
|
||||
|
||||
for (int counter = 0; counter < 3; counter++)
|
||||
System.out.println(fileInput.readLine());
|
||||
|
||||
fileInput.close();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
public static Date parseDate(String date) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
Date dob = null;
|
||||
|
||||
//TODO: Uncomment this line.
|
||||
//TODO: Use your knowledge of exception handling to make the code work as expected
|
||||
//dob = formatter.parse(date);
|
||||
|
||||
return dob;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user