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+
77+ Reviews
166+ 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...
-
Shiraz Company invested $12,100 in a mutual fund on August 1. By December 31, the value of the mutual fund had declined to $8,800, and the company did not sell any portion of the mutual fund during...
-
On the Internet, locate the U.S. Dept. of Jus- tice, "Education and Training in Fraud and Forensic Accounting: A Guide for Education- al Institutions, Stakeholder Organizations, Faculty, and...
-
Wiengot Antennas, Inc., produces and sells a unique type of TV antenna. The company has just opened a new plant to manufacture the antenna, and the following cost and revenue data have been provided...
-
G and L form a limited partnership. G, the general partner, contributes $10,000 and L, the limited partner, contributes $90,000. The partnership purchases a building on leased land, paying $100,000...
-
1. What is your assessment of the financial performance of Nelson Nurseries? 2. Do you agree with Christine Barton?s accounts-payable policy? 3. What explains the erosion of the cash balance? 4. What...
-
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...
-
When a standard deck of cards is purchased, the deck usually includes 2 jokers. This means if the jokers are included, the deck contains 54 cards. Teresa is playing a game in which she is dealt 8...
-
Given the function: 8x+3 x < 0 f(x) = 8x+6 x 0 Calculate the following values: f(-1) = = f(0) = f(2) =
-
Three balls, with charges of +q, -2q, and +3q, are placed at the corners of a square measuring L on each side, as shown in the figure. The value of q is 1.80 10-6 C, and L = 40.0 cm. Assume this set...
-
85,000 and that the price p is a P Suppose that the demand function for a product is given by D(p) = function of time given by p= 1.7t+7, where t is in days. a) Find the demand as a function of time...
-
Solve for x and any extraneous roots: 4 x = 3 + 1 8 ( 4 - x )
-
Simplify: T- 6 r 36
-
Alaris Spaceships has cash of $2,400 and accounts receivable of $5,700. The inventory cost $6,500 and can be sold today for $8,100. The fixed assets were purchased at a cost of $50,700 of which...
-
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...
-
FinTech Solutions, an innovative financial technology company, acquired an advanced data processing center on 1 January 20X1 for $1,500,000. The data center has an estimated residual value of...
-
QUESTION 36 A contract of position. adhesion is a contract containing clauses with unfavorable terms supporting a party seen as holding a superior bargaining QUESTION 37 A written contract or...
-
Central Airlines offers a series discount of 5/5/5 for frequent flyers. If a round-trip airline ticket is $569, what is the net cost after the series discount? Round to the nearest cent. OA. $81.15...
Transformations Some Of The Math Used In Power Management 1st Edition - ISBN: 154468097X - Free Book
Study smarter with the SolutionInn App