Write a program that creates Pet objects from data read from the keyboard. Store these objects into
Question:
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.
Listing 6.1
Transcribed Image Text:
/** Class for basic pet data: name, age, and weight. */ public class Pet { private String name; private int age; private double weight;//in pounds //in years public Pet () { Default constructor name "No name yet."; %3D age 0; weight = 0; } ipublic Pet (String initial Name, int initialAge, double initialWeight) name = initial Name; if ((initialAge < 0) || (initialWeight < 0)) { System.out.printin("Error: Negative age or weight."); System.exit (0); } else { age = initialAge; weight = initialWeight; } ipublic void setPet (String newName, int newAge, double newweight) name = newName; if ((newAge < 0) || (newWeight < 0)) { System.out.println("Error: Negative age or weight."); System.exit (0); } el se { age = newAge ; weight = newweight; }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 60% (10 reviews)
public class PetRecordsSortedByName public static void mainString args List pet new ArrayList char repeat y Input loop control Scanner keyboard new ScannerSystemin Enter PetRecords and add them to lis...View the full answer
Answered By
Mamba Dedan
I am a computer scientist specializing in database management, OS, networking, and software development. I have a knack for database work, Operating systems, networking, and programming, I can give you the best solution on this without any hesitation. I have a knack in software development with key skills in UML diagrams, storyboarding, code development, software testing and implementation on several platforms.
4.90+
63+ Reviews
152+ Question Solved
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Question Posted:
Students also viewed these Computer science questions
-
Write a program that creates a Random object with seed 1000 and displays the first 50 random integers between 0 and 100 using the nextInt(100) method.
-
Write a program that creates a Date object, sets its elapsed time to 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, and 100000000000, and displays the date and time using the...
-
Write a program that allows students to schedule appointments at either 1, 2,3,4,5, or 6, o'clock pm. Use an array of six strings to store the names for the time slots. Write a loop that iterates as...
-
What did Frederick Taylor, the proponent of scientific management, advocate for to achieve efficiency in manufacturing?
-
Combustion gases enter an adiabatic gas turbine at 1540F and 120 psia and leave at 60 psia with a low velocity. Treating the combustion gases as air and assuming an isentropic efficiency of 82...
-
What role did Steve Jobs' marketing skills play in his success? Did he plan to create disruptive or sustaining innovations? Pick one product he created and describe how his segmentation, targeting,...
-
The velocity potential for a certain inviscid flow field is \[ \phi=-\left(3 x^{2} y-y^{3} ight) \] where \(\phi\) has the units of \(\mathrm{ft}^{2} / \mathrm{s}\) when \(x\) and \(y\) are in feet....
-
Members of the board of directors of Control One have received the following operating income data for the year ended March 31, 2012: Members of the board are surprised that the industrial systems...
-
LJS Co. faces increasing needs for capital Fortunately it has an AA credit rating. The corporate tax rate is 40 percent The firm's financial manager is trying to determine the firm's current (2018)...
-
There are 2 shinobis with chakra levels 5 and 10 respectively and the desired sum of chakra levels is utmost 15 Starting with ke0, suy of chakra levels after attack max(5-0,0) + max(10- 0,0) 5+10 15....
-
Repeat Exercise 3 in Chapter 7, but use an instance of ArrayList instead of an array. Do not read the number of families, but read data for families until the user enters the word done. Exercise 3 in...
-
Repeat Exercise 2 in Chapter 7, but use an instance of ArrayList instead of an array. Do not read the number of values, but continue to read values until the user enters a negative value. Exercise 2...
-
Using Qualtrics, design an eight-question Internet survey that assesses how effective the introductory Marketing course at your school has been. Include a filter question that first asks respondents...
-
Smith Properties is a real estate partnership that focuses on the acquisition and management of commercial and residential real estate in the Southwestern United States. Edna Zapata has been a...
-
Hucklebee Partners had the following balance sheets at December 31: Marci is a 40 partner in the partnership. None of the partnership's assets constitute inventory or unrealized receivables. She is...
-
Sowder Partners has the following balance sheets: Chris has been approached by an unrelated third party with an offer to purchase his interest in the partnership. a. What is the appropriate selling...
-
Challenge Partners had the following balance sheets at December 31: On that date, it distributed Property 1 to Karen in complete liquidation of her interest in the partnership. a. Will Section 751...
-
Consider the monthly returns of a stock. Assume that the returns are normally distributed with mean = 1% and standard deviation = 9% (per month). How often would you expect to see a monthly return...
-
A car battery has a rating of 220 ampere hours (A h). This rating is one indication of the total charge that the battery can provide to a circuit before failing. (a) What is the total charge (in...
-
A. Select a recent issue (paper or online) of Report on Business Magazine, Canadian Business Magazine (online only), Bloomberg Businessweek, Fast Company, The Economist, or another business magazine....
-
In Figure 9.9, why is the destination hardware address all 0s in the ARP request message? Figure 9.9 System A System B N2 N1 L1 L2 (Not known by A) Ox0001 Ox04 Ox0800 06 Ox0001 ARP request L1 N1 All...
-
In the previous problem, assume Alice cannot find a direct flight from the Los Angeles to the Chicago. If she needs to change flights in Denver, a. Find the end-to-end addresses in this scenario. b....
-
In Figure 9.9, why is the destination hardware address of the frame from A to B a broadcast address? Figure 9.9 System A System B N2 N1 L1 L2 (Not known by A) Ox0001 Ox04 Ox0800 06 Ox0001 ARP request...
-
a) Give one reason why local Pakistan bus businesses could benefit from Pakistan's crisis. b) Give one reason why local bus businesses could be hurt by the Rupee crisis.
-
A P/E multiple could be high relative to the S&P 500 Index because its high growth rate justifies it. You notice a stock that has an assumed growth rate of 5.43% with a dividend payout ratio of 64.9%...
-
What would be the volume ( cm 3 ) of a piece of Styrofoam if it had a mass of 3 5 0 g , no matter its shape? Show calculation.
Study smarter with the SolutionInn App