- Joined
- Apr 22, 2019
- Posts
- 2,579
- Solutions
- 7
- Reaction
- 1,254
- Points
- 974
sino po may idiea yan na lang po kasi error sakin
eto po yung full code... online compiler lang po pinapagamit samin
import java.util.*;
import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
public class TaskPerf6 {
Scanner sc = new Scanner(System.in);
String filePath = "C:\\MERCADO\\Desktop\\records.txt";
public TaskPerf6(){
try {
System.out.println("Press R to Register for account");
System.out.println("Press L to Log in your account");
System.out.println("\nEnter a letter: ");
String UserInput = sc.nextLine();
if (UserInput.equals("R")){
registerAccount();
}else if(UserInput.equals("L")){
accountLogin();
}
}catch (Exception e) {
}
}
void accountLogin(){
try {
Path p1 = Paths.get(filePath.toString());
InputStream IS1 = Files.newInputStream(p1);
BufferedReader readerR = new BufferedReader(new InputStreamReader(IS1));
System.out.println("\nLog in to your account\n");
System.out.println("Enter your Username: ");
String username = sc.nextLine();
System.out.println("Enter your Password: ");
String password = sc.nextLine();
String n1 = "";
String accnt;
String pass;
boolean isAlphanumeric = false;
while ((n1 = readerR.readLine()) != null) {
String[] records =n1.split(",");
accnt = records[0];
pass = records[1];
if (accnt.equals(username) && pass.equals(password)){
isAlphanumeric = true;
}
}
if(isAlphanumeric == true){
System.out.println("Successfully Logged in!");
}else {
System.out.println("Incorrect username or password, please try again.");
}
}catch (Exception e){
System.out.println(e.getMessage());
}
}
void registrationAccount(){
try{
Path npath = Paths.get(filePath.toString());
OutputStream output = new BufferedOutputStream (Files.newOutputStream(npath, CREATE));
BufferedWriter wrtr = new BufferedWriter (new OutputStreamWriter(output));
System.out.println("\n Register an account please. \n");
System.out.println("Enter preffered Username: ");
String userName = sc.nextLine();
System.out.println("Enter preffered Password: ");
String passWord = sc.nextLine();
wrtr.write(userName + "," + passWord);
wrtr.newLine();
System.out.println("\nYour account has been Registered successfully!");
wrtr.close();
output.close();
new TaskPerf6();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main (String[] args){
new TaskPerf6();
}
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.