Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in
Question:
Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in Section 5.2. The new version should include accessor and mutator methods. Also define an equals method for the class that returns true if the dog’s name, age, and breed match the same variables for the other object that is being compared. Include a main method to test the functionality of the new Dog class.
Listing 5.1
Transcribed Image Text:
public class Dog { public String name; public String breed; public int age; public void writeOutput () { System.out.printin("Name: " + name); System.out.println("Breed: " + breed); System.out.println("Age in calendar years: Later in this chapter we will see that the modifier public for instance variables should be replaced with private. age); System.out.println("Age in human years: getAgeInHumanYears ()); %3D + System.out.printin(); } public int getAgeInHumanYears () { int humanAge if (age <= 2) { humanAge = 0; = age * 11; else { humanAge = 22 + ((age-2) 5): return humanAge; } }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 55% (9 reviews)
public class Dog private String name private String breed private int age Accessors an...View the full answer
Answered By
Shubhradeep Maity
I am an experienced and talented freelance writer passionate about creating high-quality content. I have over five years of experience working in the field and have collaborated with several renowned companies and clients in the SaaS industry.
At Herman LLC, an online collective of writers, I generated 1,000+ views on my content and created journal content for 100+ clients on finance topics. My efforts led to a 60% increase in customer engagement for finance clients through revamping website pages and email interaction.
Previously, at Gerhold, a data management platform using blockchain, I wrote and published over 50 articles on topics such as Business Finance, Scalability, and Financial Security. I managed four writing projects concurrently and increased the average salary per page from $4 to $7 in three months.
In my previous role at Bernier, I created content for 40+ clients within the finance industry, increasing sales by up to 40%.
I am an accomplished writer with a track record of delivering high-quality content on time and within budget. I am dedicated to helping my clients achieve their goals and providing exceptional results.
5.00+
1+ Reviews
10+ 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
-
A new postsurgical treatment is being compared with a standard treatment. Seven subjects receive the new treatment, while seven others (the controls) receive the standard treatment. The recovery...
-
A new drug is being compared with a standard drug for treating a particular illness. In the clinical trials, a group of 200 patients was randomly split into two groups, with one group being given the...
-
A new post-surgical treatment is being compared with a standard treatment. Seven subjects receive the new treatment, while seven others (the controls) receive the standard treatment. The recovery...
-
Use the accompanying graph of y = f(x). Does exist? If it does, what is it? lim f(x)
-
An air conditioner removes heat steadily from a house at a rate of 750 kJ/min while drawing electric power at a rate of 6 kW. Determine (a) The COP of this air conditioner and (b) The rate of heat...
-
Implement the Statistician class from Project 2 on page 95, but include a new method that returns the median value of all the numbers. The median is a number that is greater than or equal to at least...
-
An automobile engine will work best when the back pressure at the interface of the exhaust manifold and the engine block is minimized. Show how reduction of losses in the exhaust manifold, piping,...
-
A diesel-powered tractor with a cost of $215,000 and estimated residual value of $27,000 is expected to have a useful operating life of 80,000 hours. During October, the generator was operated 380...
-
A "metric" in this context is a system of related measures that helps us quantify characteristics or qualities. Any individual or enterprise needs to be able to quantify risk before they can decide...
-
Consider a cricketer's database with information about their batting. Compute the following query to get a desired result: Country = "India" and Batting type = "Right handed" and Year of Retirement =...
-
Consider a class Time that represents a time of day. It has attributes for the hour and minute. The hour value ranges from 0 to 23, where the range 0 to 11 represents a time before noon. The minute...
-
Consider a Java class that you could use to get an acceptable integer value from the user. An object of this class will have the attributes Minimum accepted value Maximum accepted value Prompt string...
-
Transatlantic air travel in business class has an estimated elasticity of demand of 0.40 less than transatlantic air travel in economy class, with an estimated price elasticity of 0.62. Why do you...
-
On January 1, 2014, McKeown, Inc., issued \$275,000 of 8\%, 9-year bonds for \(\$ 242,854\), which implies a market (yield) rate of 10\%. Semiannual interest is payable on June 30 and December 31 of...
-
Lundholm, Inc., reports financial statements each December 31 and issues \(\$ 600,000\) of \(9 \%\), 15-year bonds dated May 1, 2014, with interest payments on October 31 and April 30. Assuming the...
-
Assume that 90-day U.S. securities have a 3.5% annualized interest rate, whereas 90-day Canadian securities have a 4% annualized interest rate. In the spot market, 1 U.S. dollar can be exchanged for...
-
What is an average-risk stock? What is the beta of such a stock? An investor has a two-stock portfolio with $25,000 invested in Stock X and $50,000 invested in Stock Y. Xs beta is 1.50, and Ys beta...
-
On January 1, Piotroski, Inc., borrowed \(\$ 800,000\) on a \(12 \%\), 15-year mortgage note payable. The note is to be repaid in equal semiannual installments of \(\$ 58,119\) (payable on June 30...
-
A defibrillator is used during a heart attack to restore the heart to its normal beating pattern (see Section 19.5). A defibrillator passes 18 A of current through the torso of a person in 2.0 ms....
-
The overall reaction and equilibrium constant value for a hydrogenoxygen fuel cell at 298 K is 2H 2 (g) + O 2 (g) 2H 2 O(l) K = 1.28 10 83 a. Calculate E cell and G 8 at 298 K for the fuel cell...
-
Multimedia applications can be classified into three categories. Name and describe each category.
-
Recall the simple model for HTTP streaming shown in Figure 9.3. Suppose the client application buffer is infinite, the server sends at the constant rate x, and the video consumption rate is r with r...
-
Suppose an analog audio signal is sampled 16,000 times per second, and each sample is quantized into one of 1024 levels. What would be the resulting bit rate of the PCM digital audio signal?
-
Work out which number line below shows the values that x can take if 3 x 2. - A +12345678910 8 9 10 B D 5 6 7 8 9 10 6 7 8 E 2 F 3 4 7 8 9 10 1 2 3 4 5 6 7 8 9 10
-
Application Case Coffee Shop is a company dedicated to the commercialization of "signature coffee", a category of high quality coffee that is grown, processed and prepared with a high degree of...
-
The issuing company Zapatos y Bolsas Veloz, SAB de C.V., dedicated to the manufacture and sale of vinyl leather bags for more than 25 years under the Bolsas Finas brand, the company obtained in the...
Study smarter with the SolutionInn App