Answer to Question #321438 in Java | JSP | JSF for elel

Question #321438

Create a class called Register with three instance variables: username, email, and password. These three pieces of information are all String. Your class should have a constructor that initializes the three instance variables and assumes that the provided values are correct. For each instance variable, provide a set and a get method. Create a displayInformation method in order to display the username, email, and password, separated by a comma ( , ). Create a test application called RegistrationInfoTest that demonstrates the Register class.


1
Expert's answer
2022-05-18T15:25:53-0400
public class Register {

    private String username;
    private String email;
    private String password;

    public Register(String username, String email, String password) {
        this.username = username;
        this.email = email;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String displayInformation() {
        return String.format("%s, %s, %s", username, email, password);
    }
}


import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class RegistrationInfoTest {

    private static final String USERNAME = "Mark";
    private static final String EMAIL = "mark@gmail.com";
    private static final String PASSWORD = "qwerty12";

    @Test
    void shouldInitializeObjectAndDisplayInformation() {
        Register register = new Register(USERNAME, EMAIL, PASSWORD);

        String expected = String.format("%s, %s, %s", USERNAME, EMAIL, PASSWORD);
        String actual = register.displayInformation();

        Assertions.assertEquals(expected, actual);
    }
}

Test application is using org.junit.jupiter version 5.8.2


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS