Nero Swallowtail
Honorary Poster
so ganto kase dapat, ata, ewan ko kung possible to sa java, gumagawa po kase kami ng log in at sign up interface, bale pag nag sign up ka, ma i store ung i iinput mo sa isang file using IO Class, ang problema ko is kapag dalawang accounnt yung ginawa di tapos tinype ko ung naunang account na naka store sa txtfile di nababasa ni java, ung latest account lang ang na sa save, di ko kase kabisado tong IOClasses so di ko alam ibabato kong condition para mabasa nya ung file, pa help po please, kanina pa po kase deadline nakiusap nalang ako sa sir namin hehe
eto po ung code:
eto po ung code:
Java:
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.text.DecimalFormat;
import static java.nio.file.StandardOpenOption.*;
public class TaskPerf6 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Path filePath = Paths.get("C:\\Users\\Asta\\Desktop\\Record.txt");
File newFile = new File("C:\\Users\\Asta\\Desktop\\Record.txt");
int n = 0;
String Info, RegUserName = null, RegPassWord = null, LogUserName, LogPassWord, Select, Option;
do{
System.out.print("Do you want to Log in or Sign up? \nEnter \"L\" to Login in, Enter \"S\" to Sign up \nEnter your Response here: " );
Select = scan.nextLine();
try {
OutputStream output = new BufferedOutputStream(Files.newOutputStream(filePath, CREATE));
BufferedWriter writer = new BufferedWriter (new OutputStreamWriter(output));
FileReader read = new FileReader(newFile);
BufferedReader BR = new BufferedReader(read);
if(Select.equalsIgnoreCase("S")) {
System.out.print("Enter your desired Username: ");
RegUserName = scan.nextLine();
System.out.print("Enter your password: ");
RegPassWord = scan.nextLine();
Info = RegUserName +"\n" + RegPassWord;
writer.write(Info);
writer.flush();
writer.close();
System.out.println("Succesfully Signed up");
}
else if(Select.equalsIgnoreCase("L")) {
System.out.print("Enter your Username: ");
LogUserName = scan.nextLine();
System.out.print("Enter your Password: ");
LogPassWord = scan.nextLine();
if(LogUserName.equals(RegUserName) && LogPassWord.equals(RegPassWord)) {
System.out.println("Succesfully Logged in\n");
}
else {
System.out.println("Incorrect Username or Password");
}
System.out.print("Enter \"X\" to Exit or \"S\" to Sign up for another account:");
Option = scan.nextLine();
if(Option.equalsIgnoreCase("X")){
n++;
}
else if(!Option.equalsIgnoreCase("S") || !Option.equalsIgnoreCase("X")) {
throw new InvalidLetterException();
}
else {
continue;
}
}
else {
if(!Select.equalsIgnoreCase("S") || !Select.equalsIgnoreCase("L")) {
throw new InvalidLetterException();
}
}
}
catch(IOException e) {
System.out.println("Warning: " + e.getMessage());
}
catch(InvalidLetterException e) {
System.out.println("\nWarning: " + e.getMessage());
}
}while(n == 0);
}
}