Write a program that creates Pet objects from data read from the keyboard. Store these objects into an instance of ArrayList. Then sort the Pet objects into alphabetic order by pet name, and finally display the data in the sorted Pet objects on the screen. The class Pet is given in Chapter 6, Listing 6.1.

This Project has the potential for being more difficult than the Practice Programs since it uses a list of elements other than Strings, which the author states can lead to subtle problems. The PetRecord variable nextPet must be declared inside the while-loop so it is created fresh each iteration. It must be redeclared each time to ensure that PetRecords previously added to the list are not overwritten with data entered on the next iteration. If nextPet is created only once, outside the while-loop (before entering it), the new values entered are written to same address each time and all the PetRecords in the list will end up with identical data, the values entered in the last iteration.


See the code in PetRecordsSortedByName.java. Uses PetRecord.java.

Computer Science & Information Technology

You might also like to view...

Draw a class diagram representing the application domain facts below, and map it to a relational schema.

• A project involves a number of participants. • Participants can take part in a project either as project manager, team leader, or developer. • Within a project, each developer and team leader is part of at least one team. • A participant can take part in many projects, possibly in different roles. For example, a participant can be a developer in project A, a team leader in project B, and a project manager in project C. However, the role of a participant within a project does not change.

Computer Science & Information Technology

What configuration setting determines the maximum screen resolution and number of colors for a VM?

A. RAM B. PAE/NX C. Video RAM D. PRAM

Computer Science & Information Technology

Changing the original text to a secret message using cryptography is known as ____.

A. ciphertext B. decryption C. encryption D. plaintext

Computer Science & Information Technology

A network technician has been asked to retrieve device statistics, information, and errors. Which of the following tools would the technician likely use?

A. TFTP B. Packet sniffer C. SNMP D. SMTP

Computer Science & Information Technology