Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LoginFormTester.java public class LoginFormTester { public static void main(String[] args) { LoginForm form = new LoginForm(tim.mcinerney, abc123); form.input(tim.mcinerney); form.input(abc123); form.click(Submit); if (form.loggedIn()) System.out.println(Successful Login); else

LoginFormTester.java


public class LoginFormTester
{
public static void main(String[] args)
{
LoginForm form = new LoginForm("tim.mcinerney", "abc123");

form.input("tim.mcinerney");
form.input("abc123");

form.click("Submit");

if (form.loggedIn())
System.out.println("Successful Login");
else
System.out.println("Incorrect user name or password");
System.out.println("Expected:Successful Login");


form.input("tim.mcinerney");
form.input("ab123");

form.click("Submit");

if (form.loggedIn())
System.out.println("Successful Login");
else
System.out.println("Incorrect user name or password");
System.out.println("Expected:Incorrect user name or password");
}
}

LoginForm.java (has todo)

/**
A class for simulating a login form.
*/
public class LoginForm
{
private String username;
private String password;

private String currentUsername;
private String currentPassword;

private boolean logged;
private boolean firstInput;

/**
Setup a new login form.
*/
public LoginForm(String username, String password)
{
this.username = username;
this.password = password;
reset();
}

// Uses text parameter and sets the current username and current password
public void input(String text)
{
  //-----------Start below here. To do: approximate lines of code = 5
  // if this is the first input (Hint: use the firstInput variable) , must be the username so set currentUsername = text
  // and set firstInput to false. Otherwise, must be the password so set currentPassword
 
 
 
 
 
 
 
 
 
  //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

private boolean checkLogin()
{
  //-----------Start below here. To do: approximate lines of code = 5
  // if username not equal to currentUsername, return false
  // if password not equal to currentPassword return false
  // otherwise return true
 
 
 
 
 
  //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

// Called after user enters username and password
// button parameter is either "Submit" or "Reset"
public void click(String button)
{
  //-----------Start below here. To do: approximate lines of code = 7
  // if button is "Submit" then
  //         call checkLogin()
  //         if checkLogin() returns true, set logged to true
  //         else call reset()
  //       else if button equals "Reset"
  //         call reset()
 
 
 
 
 
 
 
 
 
 
 
 
  //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

private void reset()
{
currentUsername = "";
currentPassword = "";
logged = false;
firstInput = true;
}

public boolean loggedIn()
{
return logged;
}
}


p.S: Include screenshot of output so we know it is working perfectly

A class for simulating a login form. See the following files: LoginFormTester.java * LoginForm.java (has todo) Approximate total lines of code required: 17

Step by Step Solution

3.39 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

LoginFormTesterjava public class LoginFormTester public static void mainString args LoginForm form new LoginFormtimmcinerney abc123 forminputtimmciner... 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

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions

Question

*Q.1 The major product formed in the following reaction is (A) (B)

Answered: 1 week ago