Question

Written in Java I have an error in the accountFormCheck block can i get help to...

Written in Java

I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well

Collector.java

package userCreation;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.event.ActionEvent;
import javafx.fxml.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.text.Text;
import javafx.stage.*;
public class Controller implements Initializable{

    @FXML
    private PasswordField Password_text;
    @FXML
    private PasswordField Confirm_text;
    @FXML
    private TextField FirstName_text;
    @FXML
    private TextField LastName_text;
    @FXML
    private TextField Username_text;
    public Text UsedUsername_text;
    public Text ServerError_text;
    public Text NoMatchPass_text;
    public Text PatternError_text;
    public Text SubmitError_text;

    UserConnector userConnector = new UserConnector();

    @FXML
    private void handleBacktoLog_ButtonAction(ActionEvent event) throws IOException{
        System.out.println("Switch to login UI");

        Parent newuser_ui = FXMLLoader.load(getClass().getResource("/inv_manager/LoginUIDocument.fxml"));
        Scene newuser_scene = new Scene(newuser_ui);

        Stage app_stage = (Stage) ((Node)event.getSource()).getScene().getWindow();
        app_stage.setScene(newuser_scene);
        app_stage.show();
    }

    @FXML
    private void handleSubmit_ButtonAction(ActionEvent event) throws IOException{
        resetErrorMessage();

        if(accoutFormCheck()){
            if(Password_text.getText().equals(Confirm_text.getText())){
                System.out.println("The Password match");
                userConnector.setUserCreationData((FirstName_text.getText().substring(0,1).toUpperCase() + FirstName_text.getText().substring(1)),
                        (LastName_text.getText().substring(0,1).toUpperCase() + LastName_text.getText().substring(1)),
                        UsedUsername_text.getText(), Password_text.getText());

                if(!userConnector.UserCheckConnector() || !userConnector.Server_Error){
                    System.out.println("No matching username was found");
                    System.out.println("Creating new user now");
                    userConnector.UserCreationConnector();
                }else{
                    if(userConnector.Server_Error){
                        ServerError_text.setVisible(true);
                    }else{
                        System.out.println("A matching username was found");
                        Username_text.setVisible(true);
                    }
                }
            }else {
                System.out.println("Passwords didn't match");
                NoMatchPass_text.setVisible(true);
            }
        }
        else{
            System.out.println("Pattern Error");
        }
    }
    private boolean accoutFormCheck() {
        boolean pass = true;
        Pattern userpattern = Pattern.compile("^[a-zA-Z]([a-zA-z0-9.]){4,11}$");
        Pattern namepattern = Pattern.compile("^[a-zA-Z]{2,16}$");
        Pattern passwordPattern = Pattern.compile("^(?=.*[0-9])(?=.*[a-z)(?=.*[A-Z])(?=.*[!@#$%^&+=])(?=\\S+$).{8,16}$");
        Matcher matcher = namepattern.matcher((FirstName_text.getText()));

        if (!matcher.matches()) {
            pass = false;
            System.out.println("Firstname field was blank or didn't match a name pattern");
            FirstName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red");
        } else {
            FirstName_text.setStyle(null);
        }

        matcher = namepattern.matcher(LastName_text.getText());
        if (!matcher.matches()) {
            pass = false;
            System.out.println("Lastname filed was blank or didn't match a name pattern");
            LastName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
        } else {
            LastName_text.setStyle(null);
        }

        matcher = userpattern.matcher((Username_text.getText()));
        if (!matcher.matches()) {
            pass = false;
            Username_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
            System.out.println("Username field was blank or didn't match a username pattern");
        } else {
            Username_text.setStyle(null);
        }

        matcher = passwordPattern.matcher((Password_text.getText()));
        if (!matcher.matches()) {
            pass = false;
            Password_text.setStyle(" -fx-text-box-border: red; -fx-focus-color: red;");
            Confirm_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
            System.out.println("Password field was blank or didn't match a password pattern");
            PatternError_text.setVisible(true);
        } else {
            Password_text.setStyle(null);
            Confirm_text.setStyle(null);
        }

        if (!pass)
            SubmitError_text.setVisible(true);
        else
            SubmitError_text.setVisible(false);
        return pass;
    }


    private void resetErrorMessage() {
        ServerError_text.setVisible(false);
        NoMatchPass_text.setVisible(false);
        Username_text.setVisible(false);
        PatternError_text.setVisible(false);
        SubmitError_text.setVisible(false);
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

    }
}

UserConnector.java

package userCreation;

import java.sql.*;

public class UserConnector {
    private String firstname;
    private String lastname;
    private String username;
    private String password;
    private String permissions;
    public boolean Server_Error = false;

    public void setUserCreationData(String first, String last, String user, String pass){
        firstname = first;
        lastname = last;
        username = user;
        password = pass;
    }

    public void UserLogData(String user, String pass){
        username = user;
        password = pass;
    }

    public void setPermissions(String userPerm){
        permissions = userPerm;
    }
    public String getPermissions(){
        return permissions;
    }
    public String getUsername(){
        return username;
    }

    public boolean UserCheckConnector() {
        boolean pass = false;
        Server_Error = false;
        try {
            Connection con = DriverManager.getConnection("jdk:mysql://localhost:3306/users", "UserCreator", "password");

            Statement myStmt = con.createStatement();

            ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY UserName= '" + username + "';");

            while(rs.next()){
                if(rs.getString("Username") !=null){
                    pass = true;
                }
            }

            rs.close();
            myStmt.close();
            con.close();
        }
        catch (SQLException exc){
            System.out.println(exc);
            Server_Error = true;
            pass = true;
        }

        return pass;
    }

    public void UserCreationConnector() {
        Server_Error = false;
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "Usercreation", "password");
            Statement myStmt = con.createStatement();
            myStmt.executeUpdate("INSERT INFO app_users (Username, FirstName, LastName, Pass) VALUES ('"
                    + username + "', "
                    + firstname + "' , '"
                    + lastname + "',MD5('"
                    + password + "'));");

            myStmt.close();
            con.close();
        } catch (SQLException exc) {
            System.out.println(exc);
        }
    }

    public boolean LoginConnector(){
        boolean pass = false;
        Server_Error = false;
        try{
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "app_control", "password");

            Statement myStmt = con.createStatement();

            ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY Username= '" + username + "' AND Pass=MD5('"+password+"'");

            while ((rs.next())){
                if(rs.getString("Permissions") !=null){
                    pass=true;
                    setPermissions(rs.getString("Permissions"));
                }
            }

            if(pass){
                myStmt.executeUpdate("UPDATE app_users SET LastLogin=NOW() WHERE BINARY UserName= '" +username +"' AND PASS = MD5('"+password+"'");
            }

            con.close();
            myStmt.close();
            rs.close();
        }
        catch (SQLException exc){
            System.out.println(exc);
            Server_Error = true;
        }

        return pass;
    }
}

What it needs to do

Write a program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first out system for filling orders. This means that the newest widget are the first ones sent out to satisfy an order. This method of inventory can be represented by a stack. The Push procedure will insert an incoming shipment while a Pop should be called for a shipment out. Each data record in the text file warehouse.txt will consist of one shipment per line with fields (separated by white space of)

I or O (char) shipment coming IN or shipment going OUT

# (integer) quantity of the shipment

Cost (float) cost per widget of the shipment (Incoming only)

Vendor (String) name of the company sending or receiving the shipment

Write the necessary procedures to store the shipments received and to process the orders. The output for an order consists of the quantity and the total costs of the widget in the order. Each widget price is 50% higher than its cost.   The widgets used to fill an order may come from multiple shipments with different costs. If there are not sufficient widgets in inventory, use all the remaining and bill accordingly.

When the simulation terminates display the total amount owed to each of the suppliers (incoming), the number of widgets on hand and the total profit.  

The total profit is the difference between the total shipment prices from the cost of the shipments. It ignores the unsold inventory still in the warehouse.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
I have made some necessary changes. I have debugged and it should work fine now. Just copy and paste the following codes into respective files and run.

If you still face the issue, kindly let me know what the error exactly is. Thank you

Code

Collector.java

package userCreation;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.event.ActionEvent;
import javafx.fxml.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.text.Text;
import javafx.stage.*;
public class Controller implements Initializable{

@FXML
private PasswordField Password_text;
@FXML
private PasswordField Confirm_text;
@FXML
private TextField FirstName_text;
@FXML
private TextField LastName_text;
@FXML
private TextField Username_text;
public Text UsedUsername_text;
public Text ServerError_text;
public Text NoMatchPass_text;
public Text PatternError_text;
public Text SubmitError_text;

UserConnector userConnector = new UserConnector();

@FXML
private void handleBacktoLog_ButtonAction(ActionEvent event) throws IOException{
System.out.println("Switch to login UI");

Parent newuser_ui = FXMLLoader.load(getClass().getResource("/inv_manager/LoginUIDocument.fxml"));
Scene newuser_scene = new Scene(newuser_ui);

Stage app_stage = (Stage) ((Node)event.getSource()).getScene().getWindow();
app_stage.setScene(newuser_scene);
app_stage.show();
}

@FXML
private void handleSubmit_ButtonAction(ActionEvent event) throws IOException{
resetErrorMessage();

if(accountFormCheck()){
if(Password_text.getText().equals(Confirm_text.getText())){
System.out.println("The Password match");
userConnector.setUserCreationData((FirstName_text.getText().substring(0,1).toUpperCase() + FirstName_text.getText().substring(1)),
(LastName_text.getText().substring(0,1).toUpperCase() + LastName_text.getText().substring(1)),
UsedUsername_text.getText(), Password_text.getText());

if(!userConnector.UserCheckConnector() || !userConnector.Server_Error){
System.out.println("No matching username was found");
System.out.println("Creating new user now");
userConnector.UserCreationConnector();
}else{
if(userConnector.Server_Error){
ServerError_text.setVisible(true);
}else{
System.out.println("A matching username was found");
Username_text.setVisible(true);
}
}
}else {
System.out.println("Passwords didn't match");
NoMatchPass_text.setVisible(true);
}
}
else{
System.out.println("Pattern Error");
}
}
private boolean accountFormCheck() {
boolean pass = true;
Pattern userpattern = Pattern.compile("^[a-zA-Z]([a-zA-z0-9.]){4,11}$");
Pattern namepattern = Pattern.compile("^[a-zA-Z]{2,16}$");
Pattern passwordPattern = Pattern.compile("^(?=.*[0-9])(?=.*[a-z)(?=.*[A-Z])(?=.*[!@#$%^&+=])(?=\\S+$).{8,16}$");
Matcher matcher = namepattern.matcher((FirstName_text.getText()));

if (!matcher.matches()) {
pass = false;
System.out.println("Firstname field was blank or didn't match a name pattern");
FirstName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red");
} else {
FirstName_text.setStyle(null);
}

matcher = namepattern.matcher(LastName_text.getText());
if (!matcher.matches()) {
pass = false;
System.out.println("Lastname filed was blank or didn't match a name pattern");
LastName_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
} else {
LastName_text.setStyle(null);
}

matcher = userpattern.matcher((Username_text.getText()));
if (!matcher.matches()) {
pass = false;
Username_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
System.out.println("Username field was blank or didn't match a username pattern");
} else {
Username_text.setStyle(null);
}

matcher = passwordPattern.matcher((Password_text.getText()));
if (!matcher.matches()) {
pass = false;
Password_text.setStyle(" -fx-text-box-border: red; -fx-focus-color: red;");
Confirm_text.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
System.out.println("Password field was blank or didn't match a password pattern");
PatternError_text.setVisible(true);
} else {
Password_text.setStyle(null);
Confirm_text.setStyle(null);
}

if (!pass)
SubmitError_text.setVisible(true);
else
SubmitError_text.setVisible(false);
return pass;
}


private void resetErrorMessage() {
ServerError_text.setVisible(false);
NoMatchPass_text.setVisible(false);
Username_text.setVisible(false);
PatternError_text.setVisible(false);
SubmitError_text.setVisible(false);
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

}
}
UserConnector.java

package userCreation;

import java.sql.*;

public class UserConnector {
private String firstname;
private String lastname;
private String username;
private String password;
private String permissions;
public boolean Server_Error = false;

public void setUserCreationData(String first, String last, String user, String pass){
firstname = first;
lastname = last;
username = user;
password = pass;
}

public void UserLogData(String user, String pass){
username = user;
password = pass;
}

public void setPermissions(String userPerm){
permissions = userPerm;
}
public String getPermissions(){
return permissions;
}
public String getUsername(){
return username;
}

public boolean UserCheckConnector() {
boolean pass = false;
Server_Error = false;
try {
Connection con = DriverManager.getConnection("jdk:mysql://localhost:3306/users", "UserCreator", "password");

Statement myStmt = con.createStatement();

ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY UserName= '" + username + "';");

while(rs.next()){
if(rs.getString("Username") !=null){
pass = true;
}
}

rs.close();
myStmt.close();
con.close();
}
catch (SQLException exc){
System.out.println(exc);
Server_Error = true;
pass = true;
}

return pass;
}

public void UserCreationConnector() {
Server_Error = false;
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "Usercreation", "password");
Statement myStmt = con.createStatement();
myStmt.executeUpdate("INSERT INFO app_users (Username, FirstName, LastName, Pass) VALUES ('"
+ username + "', "
+ firstname + "' , '"
+ lastname + "',MD5('"
+ password + "'));");

myStmt.close();
con.close();
} catch (SQLException exc) {
System.out.println(exc);
}
}

public boolean LoginConnector(){
boolean pass = false;
Server_Error = false;
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "app_control", "password");

Statement myStmt = con.createStatement();

ResultSet rs = myStmt.executeQuery("SELECT * FROM app_users WHERE BINARY Username= '" + username + "' AND Pass=MD5('"+password+"'");

while ((rs.next())){
if(rs.getString("Permissions") !=null){
pass=true;
setPermissions(rs.getString("Permissions"));
}
}

if(pass){
myStmt.executeUpdate("UPDATE app_users SET LastLogin=NOW() WHERE BINARY UserName= '" +username +"' AND PASS = MD5('"+password+"'");
}

con.close();
myStmt.close();
rs.close();
}
catch (SQLException exc){
System.out.println(exc);
Server_Error = true;
}

return pass;
}
}

Add a comment
Know the answer?
Add Answer to:
Written in Java I have an error in the accountFormCheck block can i get help to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • *JAVA* Can somebody take a look at my current challenge? I need to throw a different...

    *JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> {    private int top, size;    private E arrS[];    private static final int MAX_STACK_SIZE = 10;    public ArrayStack() {        this.arrS = (E[]) new Object[MAX_STACK_SIZE];        this.top = size;        this.size = 0;...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • What causes an assertion error in JAVA on this? Code: public class Student extends Staff {...

    What causes an assertion error in JAVA on this? Code: public class Student extends Staff {        private String s1;        private String s2;        public Student (String firstName, String lastName, String s1, String s2) {              this.s1 = s1;              this.s2 = s2;        }        public boolean equals(Person s){              if (s == null) return false;                          return ((this.s1).equals(this.s2));        } } Test Case:        public void areTheyEqualTest() {              Student             s1     = new Student( FIRST_NAME, LAST_NAME);             ...

  • complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class...

    complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */    public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT