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: 63% (11 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+
97+ Reviews
194+ 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...
-
Problem 16-49 Partial Operational and Financial Productivity; Medical Practice (LO 16-2] Family Medical Care (FMC) is a family medical practice with 5 physicians, a nursing staff of 7 to 9 nurses,...
-
We can read, but can we count? The Census Bureau once gave a simple test of literacy in English to a random sample of 3400 people. The New York Times printed some of the questions under the headline...
-
Entry-level auditing staff often inspects client records and documentation supporting accounting transactions in order to gain evidence about the appropriate application of the applicable financial...
-
Indicate whether a debit or credit decreases the normal balance of each of the following accounts
-
Answer the following questions. Hint: Use the accounting equation. a. On January 1, Lumia Companys liabilities are $60,000 and its equity is $40,000. On January 3, Lumia purchases and installs solar...
-
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...
-
Solve the given systems of equations graphically by using a calculator. Find all values to at least the nearest 0.1. 4x + 25y 2 = 21 10y = 31 9x
-
Write a function that takes as input a non-negative integer in the range 0 to 99 and returns the English word(s) for the number as a string. Multiple words should be separated by a space. If the...
-
The Event Manager sighed as the festival approached and she had only five crafts vendors who had committed to taking part in the marketplace. She and her assistant were frantic. They had been...
-
the systematic recording, analysis, and interpretation of costs incurred by a business. Its significance extends beyond mere financial tracking; it plays a pivotal role in aiding management...
-
1.What is your process for ensuring that all your work is correct? 2.What do you mean by Batch Costing ? 3.Explain the accounting procedure for Batch Costing 4.State the applicability of Job Costing...
-
The increasing occurrence of freak weather incidents will have both local and global effects. Even in cases where production has been re-localized, freak weather can still greatly impact local...
-
In Problem, perform the indicated operations and simplify. (x 3 + 5x 2 6) (x 2 2)
-
Given the table below, about how much force does the rocket engine exert on the 4.0 kg payload? Distance traveled with rocket engine firing (m) Payload final velocity (m/s) 500 320 490 310 1020 450...
-
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...
-
Problem Set Time Value of Money 1. In 10 years, what is the value of $100 invested today at an interest rate of 8% per year, compounded annually? 2. In 10 years, what is the value of $100 invested...
-
The Blending Department of Luongo Company has the following cost and production data for the month of April. Costs: Work in process, April 1 Direct materials: 100% complete $120,000 Conversion costs:...
-
Q3 plz answer correctly and check work Builtrite's upper management has been comparing their books to industry standards and came up with the following question: Why is our operating profit margin...
Study smarter with the SolutionInn App