Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The correct set of statements that would result in the myCustomer instance having the username as XC1001 and the password as testpass is option b.

Here's how it works:

  1. First, a new Customer object is created with the customerCode as "username" and password as "password". This is done using the Customer class constructor that takes two parameters.
Customer myCustomer = new Customer("username","password");
  1. Then, the setCustomerCode method of the myCustomer object is called with the argument "XC1001". This method changes the customerCode of the myCustomer object to "XC1001".
myCustomer.setCustomerCode("XC1001");
  1. Finally, the setPassword method of the myCustomer object is called with the argument "testpass". This method changes the password of the myCustomer object to "testpass".
myCustomer.setPassword("testpass");

So, at the end of these statements, the myCustomer object has the customerCode as "XC1001" and the password as "testpass".

This problem has been solved

Similar Questions

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

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.

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;}

Choose the appropriate return type for the getters and setters provided below. class Test{private int value;public setValue(int value){//some code}public getValue(){//some code}}

public class MyClass{private int value;public void setValue(int i){ / code / }// Other methods…}The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue?Question 3Answera.value=iandthis.value = i;b.value = i; c.this.value = i;d.value == i;

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.