Henry E.

asked • 10/21/20

Help me complete the code please. PLEASE

import java.io.*;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import javax.swing.JOptionPane;

import java.io.File;



public class TestCSV3

{


public static BufferedReader br;

public static void main(String[] args) throws IOException

{

br = new BufferedReader(new InputStreamReader(System.in));

Display.menu();

System.out.print("\n-> ");

short choice = Short.parseShort(br.readLine());

switch(choice)

{

case 1:

register();

break;

case 2:

login();

break;

}

}

public static void register() throws IOException

{

// File f1 = new File("C:\\Users\\hp\\Just a folder\\Dayo\\Sou.txt");

// String fileName1 = f1.getName();

// System.out.println("The file's name is: " + fileName1);

br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("FIRST NAME: ");

String fname = br.readLine();

System.out.print("MIDDLE NAME: ");

String mname = br.readLine();

System.out.print("LAST NAME: ");

String lname = br.readLine();

System.out.print("DATE OF BIRTH: ");

String dob = br.readLine();

System.out.print("EMAIL ADDRESS: ");

String email = br.readLine();

System.out.print("USERNAME: ");

String uname = br.readLine();

System.out.print("PASSWORD: ");

String pword = br.readLine();

System.out.print("CONFIRM PASSWORD: ");

String cword = br.readLine();

/*

String fname = "Ark";

String mname = "Ship";

String lname = "Royal";

String dob = "4/13/1937";

String email = "[email protected]";

String uname = "Ark";

String pword = "Royal";

String cword = "Royal";

String fpath = "C:\\Users\\hp\\Desktop\\Dayo.txt";

*/

try

{

File file = new File("C:\\Users\\hp\\Desktop\\Dayo.txt");

if(!file.exists())

{

file.createNewFile();

}

PrintWriter pa = new PrintWriter(file);

pa.println(fname+","+mname+","+lname+","+dob+","+email+","+uname+","+pword+","+cword);

pa.close();

JOptionPane.showMessageDialog(null,"Record Saved!");

String fpath = "C:\\Users\\hp\\Desktop\\Dayo.txt";

saveRecord(fname,mname,lname,dob,email,uname,pword,cword,fpath);

}

catch(IOException X)

{

JOptionPane.showMessageDialog(null,"Record Not Saved!");

}

}


public static void saveRecord(String fname,String mname,String lname,String dob,String email,String uname,String pword,String cword,String fpath)

{

try

{

FileWriter ar = new FileWriter(fpath,true);

BufferedWriter bw = new BufferedWriter(ar);

PrintWriter pr = new PrintWriter(bw);

System.out.println(fname+","+mname+","+lname+","+dob+","+email+","+uname+","+pword+","+cword+"\n");

pr.flush();

pr.close();

Display.menu4();

Display.menu5();

System.out.print("\n-> ");

short choice3 = Short.parseShort(br.readLine());

switch(choice3)

{

case 1:

register();

break;

case 2:

login();

break;

}

// login();

}

catch(IOException E)

{

JOptionPane.showMessageDialog(null,"Record Not Saved!");

}

}

public static void login() throws IOException

{

System.out.print("USERNAME: ");

String uname2 = br.readLine();

System.out.print("PASSWORD: ");

String pword2 = br.readLine();

// String uname = jTextField1.getText();

// String pword = new String (jPasswordField1.getPassword());

if(uname2.equals("Ark") && pword2.equals("Royal"))

{

// new Home().setVisible(true);

Display.menu2();

System.out.print("\n-> ");

short choice1 = Short.parseShort(br.readLine());

switch(choice1)

{

case 1:

Display.menu();

System.out.print("\n-> ");

short choice = Short.parseShort(br.readLine());

switch(choice)

{

case 1:

register();

break;

case 2:

login();

break;

}

break;

}

}

else

{

Display.menu3();

System.out.print("\n-> ");

short choice1 = Short.parseShort(br.readLine());

switch(choice1)

{

case 1:

Display.menu();

System.out.print("\n-> ");

short choice = Short.parseShort(br.readLine());

switch(choice)

{

case 1:

register();

break;

case 2:

login();

break;

}

break;

}

}

}

public static void displayprofile() throws IOException

{

// Options #1 - Display Profile’s functions are optional. No need to code it for the meantime.

}

public static void resetpassword() throws IOException

{

// Options #2 - Reset Password’s functions are optional. No need to code it for the meantime.

System.out.print("USERNAME: ");

String uname1 = br.readLine();

while(true)

{

System.out.print("PASSWORD: ");

String pword1 = br.readLine();

System.out.print("CONFIRM PASSWORD: ");

String cword1 = br.readLine();

Display.menu2();

System.out.print("-> ");

short choice1 = Short.parseShort(br.readLine());

switch(choice1)

{

case 1:

displayprofile();

break;

case 2:

resetpassword();

break;

case 3:

logout();

break;

}

break;

}

if(false)

{

System.out.println("INCORRECT USERNAME!");

resetpassword();

}

}

public static void logout() throws IOException

{

Display.menu();

System.out.print("\n-> ");

short choice = Short.parseShort(br.readLine());

switch(choice)

{

case 1:

register();

break;

case 2:

login();

break;

}

}

}



Henry E.

This is the continuation Different class public class Display { public static void menu() { System.out.println("===== WELCOME DAYO! =====\n\n" + "[1] Register\n" + "[2] Login"); } public static void menu4() { System.out.println("YOU ARE NOW REGISTERED!\n\n"); } public static void menu5() { System.out.println("" + "[1] Register\n" + "[2] Login"); } public static void menu1() { System.out.println("YOU ARE NOW REGISTERED!\n\n" + "[1] Display Profile\n" + "[2] Reset Password\n" + "[3] Log-out\n"); } public static void menu2() { System.out.println("SUCCESSFUL!\n\n" + "[1] Display Profile\n" + "[2] Reset Password\n" + "[3] Log-out"); } public static void menu3() { System.out.println("\nINCORRECT USERNAME or INCORRECT PASSWORD\n\n" + "[1] Back to menu\n"); } }
Report

10/21/20

1 Expert Answer

By:

Patrick B. answered • 10/22/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Henry E.

Thank you so so much!!!!!!!!!!
Report

10/22/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.