Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need Help with list in my Lab 3 Lab3: 1) Create data storage for each user with the attached Person.java file. 2) Implement the

I need Help with list in my Lab 3

Lab3:

1) Create data storage for each "user" with the attached "Person.java" file.

2) Implement the CompareTo() method from the "Comparable" interface inside the Person class.

3) Store all the users in an arrayList of "Person" objects.

4) Use an enhanced for loop to iterate through the arrayList of person objects and then compare the "temp" Person from the user input.

5) In this version, only return zero if the objects match (meaning password=password, username=username, and studentID=studentID)

This is my Person.java File

public class Person { private String username; private String password; private Long StudentID; public Person(String User, String Pass, Long ID) { this.username = User; this.password = Pass; this.StudentID = ID; } public String getPassword () { return this.password; } public String getUsername() { return this.username; } public Long getStudentID() { return this.StudentID; } }

This is my LOGIN.java file

import javax.swing.JFrame; import java.awt.BorderLayout; public class Login { public static void main(String[] args) { LoginGUI cuFrame = new LoginGUI(); cuFrame.setVisible(true); cuFrame.setTitle("Login"); cuFrame.setSize(300,150); cuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

This is my LOGINGUI.java

import java.awt.event.*;

import java.awt.event.KeyAdapter;

import java.awt.event.ActionListener; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.border.*; import javax.swing.*;

public class LoginGUI extends JFrame { private JTextField txtUser; private JTextField txtPass; private JTextField txtStuID; private JLabel lblUser; private JLabel lblPass; private JLabel lblStuID; private String keep = ""; private String finalPassword = ""; private JButton btnLogin; private JButton btnExit; private JPanel panel1; public LoginGUI() { setLayout(new BorderLayout(10,10)); panel1 = new JPanel(); panel1.setPreferredSize(new Dimension(250, 250)); txtUser = new JTextField(); txtUser.setPreferredSize(new Dimension(150,20)); txtPass = new JTextField(); txtPass.setPreferredSize(new Dimension(150,20)); txtPass.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent arg0) { JTextField textField = (JTextField) arg0.getSource(); keep += arg0.getKeyChar(); String pressedKey = arg0.getKeyText(arg0.getKeyChar()); String temp = ""; if (arg0.getKeyChar() == KeyEvent.VK_BACK_SPACE) { finalPassword = finalPassword.substring(0, finalPassword.length() - 1); for (int i = 0; i < finalPassword.length(); i++) { temp += "*"; } textField.setText(temp); } else if ("Enter".equals(pressedKey)) { System.out.println(finalPassword); } else { finalPassword += (String.valueOf(arg0.getKeyChar())); arg0.setKeyChar('*'); }} }); txtStuID = new JTextField(); txtStuID.setPreferredSize(new Dimension(150,20)); lblUser = new JLabel("Username: "); lblPass = new JLabel("Password: "); lblStuID = new JLabel("StudentID: "); btnLogin = new JButton("Login"); btnExit = new JButton("Exit"); panel1.add(lblUser); panel1.add(txtUser); panel1.add(lblPass); panel1.add(txtPass); panel1.add(lblStuID); panel1.add(txtStuID); panel1.add(btnLogin); panel1.add(btnExit); ActionListener LoginAction = new LoginListener(); btnLogin.addActionListener(LoginAction); ActionListener ExitAction = new ExitListener(); btnExit.addActionListener(ExitAction); add(panel1, BorderLayout.CENTER);

} class ExitListener implements ActionListener { public void actionPerformed(ActionEvent event) { System.exit(0); } } class LoginListener implements ActionListener { public void actionPerformed(ActionEvent event) { Validate V = new Validate(); //String pw = txtPass.getText() ; if (!keep.matches(".*[A-Z].*[0-9].*") && keep.length() < 10 ) { JOptionPane.showMessageDialog(null, "Your Password needs atleast one Captial Letter or One Number Your Password must contain atleast 10 Characters "); } else if (keep.contains(",") || keep.contains(" ")) { JOptionPane.showMessageDialog(null, "Your Password must not have Comma or Space"); } else if (V.Verify(txtUser.getText(), keep, txtStuID.getText())) { JOptionPane.showMessageDialog(null, "Your user account has been validated!"); } else { JOptionPane.showMessageDialog(null, "Your Username or Password is incorrect. Please try again"); } txtUser.setText(""); txtPass.setText(""); txtStuID.setText(""); } } }

This is my Validate.java file

import java.util.*; import java.io.*; import javax.swing.JOptionPane; class Validate { public Boolean Verify(String u, String p, String i) { try { Scanner FileScan = new Scanner(new File("USERDATA2.txt")); while (FileScan.hasNextLine()) { String S=FileScan.nextLine(); String[] Sa= S.split(","); if( (u.equals(Sa[0])) && (p.equals(Sa[1])) && (i.equals(Sa[2])) ) { FileScan.close(); return true; } } FileScan.close(); } catch(IOException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } return false; } }

This is my USERDATE2.txt if you need it

USER1, fBqj!P4B33, 900000003 USER2, 2Hmkq98NW+, 900000006 USER3, _SNT8wsz85, 900000009 USER4, 5LDz2H%t3t, 900000013 USER5, at!tbX92FC, 900000016 USER6, Kevin123456, 900

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago