Knowee
Questions
Features
Study Tools

Which of the following methods can be added to the UserAccount class in the tutorial to access the password?a.)public void setPassword(int password) { this.password = password;}b.)public int getPassword() { return password;}c.)public void setPassword(String password) { this.password = password;}d.)public String getPassword() { return password;}

Question

Which of the following methods can be added to the UserAccount class in the tutorial to access the password?a.)public void setPassword(int password) { this.password = password;}b.)public int getPassword() { return password;}c.)public void setPassword(String password) { this.password = password;}d.)public String getPassword() { return password;}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct methods to add to the UserAccount class to access the password would depend on the data type of the password.

If the password is of type int, then the methods would be: a.) public void setPassword(int password) { this.password = password;} b.) public int getPassword() { return password;}

If the password is of type String, then the methods would be: c.) public void setPassword(String password) { this.password = password;} d.) public String getPassword() { return password;}

These methods are known as getter and setter methods in Java. The setter method (setPassword) is used to set the value of the password, and the getter method (getPassword) is used to retrieve the value of the password.

This problem has been solved

Similar Questions

Given the following class, what sets of statements would have the end result of the myUser instance having the username as testuser and the password as testpassword?public class User { private String userName; private String password; public User(String userName, String password) { this.userName = userName; this.password = password; } public String getUserName() { return userName; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public void setPassword(String password) { this.password = password; }}a.)User myUser = newUser("testpassword","testuser");b.)User myUser = newUser("username","password");myUser.setUserName("testuser");myUser.setPassword("testpassword");c.)User myUser = new User();myUser.setUserName("testuser");myUser.setPassword("testpassword");d.)User myUser = newUser("testuser","testpassword");myUser.setUserName("user");myUser.setPassword("pass");

Given the following set of classes, what would need to be fixed to make the program work?public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }} class CustomerTest { public static void main(String[] args) { Customer testAcct = new Customer("user","pass"); testAcct.setPassword("Java"); resetAcct(); } public static void resetAcct(Customer acct){ acct.setPassword(""); acct.setUserName(""); }}The instance testAcct is not in scope in the method resetAcct(). The instance testAcct needs to be declared in resetAcct()The testAcct should be returned as a return value from resetAcct().The testAcct should be declared at the class level to be accessed in the resetAcct() method.The testAcct should be passed into the resetAcct() method as a parameter.

hich type of method would include "Something you know", such as a password?1 pointAuthenticationAccountabilityIdentificationAuthorization

Given the following set of classes:public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }} class CustomerTest { public static void main(String[] args) { Customer testAcct = new Customer("user","pass"); testAcct.setPassword("Java"); System.out.println(testAcct.toString()); }}What does the toString() method need to look like to result in the following output:UserName: userPassword: Javaa.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return state;}b.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return password;}c.)public String toString() { String state = "UserName: " + userName + "\n"; state = "Password: " + password + "\n"; return state;}d.)public String toString() { String state = "username: " + userName + "\n"; state += "password: " + password + "\n"; return state;}

Demonstrate ability to set and change the values of object properties.Given the following class, what sets of statements would have the end result of the myCustomer instance having the username as XC1001 and the password as testpass?public class Customer { private String customerCode; private String password; public Customer(String customerCode, String password) { this.customerCode = customerCode; this.password = password; } public String getCustomerCode() { return customerCode; } public String getPassword() { return password; } public void setCustomerCode(String customerCode) { this.customerCode = customerCode; } public void setPassword(String password) { this.password = password; }}a.)Customer myCustomer = newCustomer("testpass","XC1001");b.)Customer myCustomer = new Customer("username","password");myCustomer.setCustomerCode("XC1001");myCustomer.setPassword("testpass");c.)Customer myCustomer = newCustomer("XC1001","testpass");myCustomer.setCustomerCode("user");myCustomer.setPassword("pass");d.)Customer myCustomer = new Customer();myCustomer.setCustomerCode("XC1001");myCustomer.setPassword("testpass");

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.