Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Get accurate and detailed answers to your questions from a dedicated community of experts on our Q&A platform. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

Code in Java:
1) Assume there is a class named Animal with an attribute named name of type String and a get method named getName. Assume there are two objects a1 and a2 of type Animal already declared and their names are already set. Write a java expression that checks if the names of the Animal objects a1 and a2 are equal.
2) Assume there is a class named Car with an attribute named model of type String and a get method named getModel. Assume there is an object c1 of type Car already declared and its model already set. Write a java statement that sets the variable ch of type char ( already declared) to the third character of the c1's model.
3) Assume there is a class Lamp having a private attribute named status of type boolean. Write a method named whatIsStatus for the Lamp class that accepts a Lamp object as its parameter and returns a text value based on the status of the passed object as follows:
if the status is true return "ON" , if the status is false return "OFF" , otherwise return "ERROR".

Sagot :

Answer:

Explanation:

The following expressions are written in Java and require the rest of the "assummed code" to run correctly, but can be pasted to that code and it has already been tested to be working and be bug free.

1)  boolean areEqual = (a1.getName() == a2.getName());

2) ch = c1.getModel().charAt(2);

3)  public static void whatIsStatus(Lamp myLamp) {

       if (myLamp.status == true) {

           return "ON";

       } else if (myLamp.status == false) {

           return "OFF";

       } else {

           return "ERROR";

       }

   }

We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.