Implement a class SubmitInfo that simulates a form to receive information about
ID: 3567196 • Letter: I
Question
Implement a class SubmitInfo that simulates a form to receive information about a commodity.
Supply methods:
public void enter(String text)
public void submit(String button)
public boolean registered()
The first input is the name, the second input is the code. The submit method can be called with
arguments "Register" and "Clear". When a user has successfully provided the information and
clicked the register button, the registered method returns true and further input has no effect.
When a user tries to register with an invalid name and code, the form is cleared. Use a
constructor with the expected name and code.
you can use this tester:
Explanation / Answer
public class SubmitInfo
{
private String name;
private String pass;
private String nameEntered;
private String passEntered;
public SubmitInfo(String n, String p)
{
name = n;
pass = p;
nameEntered = "";
passEntered = "";
}
public void enter(String text)
{
if(nameEntered == "")
nameEntered = text;
else
passEntered = text;
}
public void submit(String button)
{
if(button == "Register")
{
}
if(button == "Clear")
{
nameEntered = "";
passEntered = "";
}
}
public boolean registered()
{
if(name == nameEntered && pass == passEntered)
return true;
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.