Question

Modify Names.java to have only one name variable name. Rewrite the swap() method so that it accepts a Names as a parameter anpublic static void main(StringIl args) /me and you are each an INSTANCE of the Name class Name me new Name(Alex); //

Modify Names.java to have only one name variable name. Rewrite the swap() method so that it accepts a Names as a parameter and swaps the value referenced by the parameter with the value referenced by the object used when the method is called For example the method AName.swap(BName) should switch the values contained in the objects AName and BName
public static void main(StringIl args) /"me" and "you" are each an "INSTANCE" of the Name class Name me new Name("Alex"); // calls explicit constructor Name younew Name("ELlen"); // calls explicit constructor ARGUMENTS the values that go into the PARAMETERS System.out.println("me"me); System.out.println("you-"you); me swap(you); System.out.print ln("me-"+me); System.out.println("youyou) /* Multiline commment that shows how program ran /Desktop/Spring17/CSIS24 $ java UseName meALex you-Ellen me = Ellen you Alex
0 0
Add a comment Improve this question Transcribed image text
Answer #1
void swap(Name other){
    String tmp = this.name;
    this.name = other.name;
    other.name = tmp; 
}
Add a comment
Know the answer?
Add Answer to:
Modify Names.java to have only one name variable name. Rewrite the swap() method so that it accepts a Names as a parameter and swaps the value referenced by the parameter with the value referenced by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT