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");
Question
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");
Solution
The correct set of statements is option b. Here's the step by step explanation:
b.) User myUser = new User("username","password"); This line creates a new instance of the User class, with the username set as "username" and the password set as "password".
myUser.setUserName("testuser"); This line changes the username of the myUser instance to "testuser".
myUser.setPassword("testpassword"); This line changes the password of the myUser instance to "testpassword".
So, at the end of these statements, the myUser instance will have the username as "testuser" and the password as "testpassword".
Option a is incorrect because the username and password are swapped in the newUser method. Option c is incorrect because the User class doesn't have a default constructor. Option d is incorrect because it changes the username and password to "user" and "pass" after setting them to "testuser" and "testpassword".
Similar Questions
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");
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;}
Given the following set of classes, what needs to be fixed to make the program produce the output Name: Java?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 c1 = new Customer("user","pass"); c1.setUserName("Java"); outputName(); } public static void outputName(){ System.out.println("Name: " + c1.getUserName()); }} a.)The c1 should be returned as a return value from outputName().b.)The c1 should be passed into the outputName() method as a parameter.c.)The instance c1 is not in scope in the method outputName(). The instance c1 needs to be declared in outputName()d.)The instance c1 is not in scope in the method outputName(). The c1 should be globally in CustomerTest to be accessed in the outputName() method.
Which of the following are output by the following code? (Choose all that apply)public class StringBuilders { public static StringBuilder work(StringBuilder a, StringBuilder b) { a = new StringBuilder("a"); b.append("b"); return a; } public static void main(String[] args) { StringBuilder s1 = new StringBuilder("s1"); StringBuilder s2 = new StringBuilder("s2"); StringBuilder s3 = work(s1, s2); System.out.println("s1 = " + s1); System.out.println("s2 = " + s2); System.out.println("s3 = " + s3); } }*A. s1 = aB. s1 = s1C. s2 = s2D. s2 = s2bE. s3 = aF. s3 = nullG. The code does not compile.
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.