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: 66% (9 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+
60+ Reviews
144+ 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...
-
Find the unknown side length of the right triangle using the Pythagorean Theorem or a Pythagorean triple. X 60 68
-
How can social media aid in developing a questionnaire?
-
McIver's Swimwear Distributors is a relatively small, privately held swimwear distribution company that operates in the Midwest and handles several product lines, including footwear, clothing, and...
-
Departing partners should grant the other partners the "right of first refusal" to purchase their partnership shares. One valuation methodology is to base the value of shares on the business' assets...
-
Assume an algorithm that takes log 2 n microseconds to solve a problem. Find the largest input size n such that the algorithm solves the problem in time in 24 days. a) 2 140000 b) 2 1440000 c) 2...
-
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...
-
Return on investment and residual income Required Supply the missing information in the following table for TolbertCompany. $264,000 Sales ROI Operating assets Operating income Turnover Residual...
-
QUESTION 3 A user can request a quiz for the system. The system picks a set of questions from its database and compose them together to make a quiz. It rates the user's answers and gives hints if the...
-
Stock price Exercise price Interest rate Dividend yield Time to expiration Standard deviation of stock's returns Call value $ $ 48.00 $ 46.00 5.00% 3.00% 0.7500 49.00%
-
Required: Use the Black-Scholes formula to find the value of a call option based on the following inputs. Refer Cumulative normal distribution Table. (Do not round intermediate calculations. Round...
-
Pat has a home based business. He uses the basement area for his business. The basement area is approximately 18% of the total square feet of floor space in the house. Pat provides you with the...
-
Determine the payback period to the nearest year for the following project: Cash Flow First cost Annual maintenance costs Overhaul costs Salvage value at the end of useful life Uniform benefits...
-
Light Sweet Petroleum, Inc., is trying to evaluate a generation project with the following cash flows: Year _____________Cash Flow 0 .................... -$45,000,000 1 .........................
-
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 client walks into your office to prepare a TY 2 0 2 0 return for federal and state. He has some charitable expenses worth $ 1 , 0 0 0 , which is not enough to itemize. So , he wants to take $ 3 0 0...
-
A taxpayer spends six months in the year working and living in the state. They move across the border, but keep the same job. For all intents and purposes, they are now domiciled in this other state...
-
Andre wants to make charitable contributions for the tax year to maximize the impact on his State return without needing to adjust for conformity issues. His AGI is $ 7 5 , 0 0 0 . What is the...
Study smarter with the SolutionInn App