Knowee
Questions
Features
Study Tools

Which of the following methods can be added to the UserAccount class in the tutorial to change the password?a.)public void setPassword(String password) { this.password = password;}b.)public int getPassword() { return password;}c.)public void setPassword(int 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 change the password?a.)public void setPassword(String password) { this.password = password;}b.)public int getPassword() { return password;}c.)public void setPassword(int 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 method to add to the UserAccount class to change the password would be:

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

This method is correct because it is a public method (meaning it can be accessed from outside the class), it does not return any value (void), and it takes a String as an argument, which is the appropriate data type for a password. It then assigns the value of the input argument to the class's password field.

The other methods are incorrect because:

b.) This is a getter method, not a setter method. It's used to return the value of the password, not to set or change it.

c.) This method is incorrect because it takes an integer as an argument, while a password should be a String.

d.) This is also a getter method, not a setter. It's used to return the value of the password, not to set or change it.

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");

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");

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.

Given the following class, what sets of statements would have the end result of the myCustomer instance having the customername as AB1002 password as test as testpassword and then outputting the customername and password?public class Customer { private String customerName; private String password; public Customer(String customerName, String password) { this.customerName = customerName; this.password = password; } public String getCustomerName() { return customerName; } public String getPassword() { return password; } public void setCustomerName(String customerName) { this.customerName = customerName; } public void setPassword(String password) { this.password = password; }}Customer myCustomer = new Customer("AB1002","testpassword");System.out.println("Customer: " + myCustomer.customername());System.out.println("Password: " + myCustomer.password());Customer myCustomer = new Customer();myCustomer.setCustomerName("AB1002");myCustomer.setPassword("testpassword");System.out.println("Customer: " + myCustomer.getCustomerName());System.out.println("Password: " + myCustomer.getPassword());Customer myCustomer = new Customer("AB1002","testpassword");System.out.println("Customer: " + myCustomer.getCustomerName());System.out.println("Password: " + myCustomer.getPassword());Customer myCustomer = new Customer("AB1002","testpassword");System.out.println("Customer: " + myCustomer.customername);System.out.println("Password: " + myCustome

Question 2In the Computer Management tool in Windows, what setting can an administrator enable if a user’s password was compromised and they need to update it?1 pointUser must change password at next logon.Password must be changedUser cannot change passwordPassword never expires

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.