Consider the following class. public class Person (private String name; public Person(String name) { this.name =...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following class. public class Person (private String name; public Person(String name) { this.name = } name; @Override public String tostring() { return this.getClass().getName() + "[name=" + this.name + "]"; } } If we have a Person object whose attribute name is a reference to the String object "Alice", calling toString() on this object will return the String: "Person[name=Alice]" Now consider the following class. public class Customer extends Person { private int balance; } In your answer to the parts below, do not modify the class Person. You may only use the parts of the classes Person and Customer shown above. (a) Override the method public String toString() in the class Customer so that 5 marks it returns a String that contains the word "Customer", the name, and the balance. For example, calling toString!) on a Customer with name "Alice" and balance 1200 is supposed to return the following String: "Customer[name=Alice][balance=1200]" (b) Write two public constructors for the class Customer: 11 marks The first constructor has two parameters of types String and int with the name and the balance. It initialises the instance variables with the values of the corresponding parameters. Consider the following class. public class Person (private String name; public Person(String name) { this.name = } name; @Override public String tostring() { return this.getClass().getName() + "[name=" + this.name + "]"; } } If we have a Person object whose attribute name is a reference to the String object "Alice", calling toString() on this object will return the String: "Person[name=Alice]" Now consider the following class. public class Customer extends Person { private int balance; } In your answer to the parts below, do not modify the class Person. You may only use the parts of the classes Person and Customer shown above. (a) Override the method public String toString() in the class Customer so that 5 marks it returns a String that contains the word "Customer", the name, and the balance. For example, calling toString!) on a Customer with name "Alice" and balance 1200 is supposed to return the following String: "Customer[name=Alice][balance=1200]" (b) Write two public constructors for the class Customer: 11 marks The first constructor has two parameters of types String and int with the name and the balance. It initialises the instance variables with the values of the corresponding parameters.
Expert Answer:
Answer rating: 100% (QA)
a To override the toString method in the Customer class youll need to call the supe... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
Define the contextual-equivalence relation ` M =ctx M0 : for pairs of PCF terms M, M0 , PCF types , and PCF type environments . [3 marks] (ii) For PCF terms M and N with respective typings ` M : and...
-
Building a Case Study Analysis on Outsourcing, Find a minimum of three news articles discussing this issue, prepare the case study report that has three main parts: Summary and Overview of the issue...
-
The Globe Fishery packs shrimp that weigh more than 1.91 ounces each in packages marked "Large" and shrimp that weigh less than 0.47 ounces each into packages marked "small", the remainder are packed...
-
Suppose N electrons can be placed in either of two configurations. In configuration 1, they are all placed on the circumference of a narrow ring of radius R and are uniformly distributed so that the...
-
What reasons might an entity provide for adopting ESG practices?
-
A firm wishing to evaluate interest rate behavior has gathered data on the nominal rate of interest and on inflationary expectations for five U.S. Treasury securities, each having a different...
-
The Power of Trade and Comparative Advantage: Work It Out 3 ? Here's another specialization and exchange problem. This problem is wholly made-up, ? so that you won't be able to use your intuition...
-
Company A unlevered value is $100 million. The tax rate is 30%. The debt cost ofcapital is 3% and the asset cost of capital is 6%. i. What is company A's value if debt/assets is raised to 25% after...
-
Consider the case of a regulator and a single polluter. Suppose the regulator knows the marginal damage from pollution but is unsure about the firm's marginal savings from emitting. The regulator...
-
You couldnt be more excited about being on your first financial statement audit as you launch into your new professional accounting career. Having recently graduated with a Master of Accountancy...
-
Using real-world examples, evaluate the arguments for protectionism.
-
Evaluate \(x\left(0^{+} ight)\)by using the IVT. \(X(s)=\frac{s(s+4)^{2}}{(s+1)(s+2)(s+3)^{2}}\)
-
Evaluate \(x\left(0^{+} ight)\)by using the IVT. \(X(s)=\frac{s^{2}+1}{\left(\frac{1}{2} s+1 ight)\left(9 s^{2}+6 s+2 ight)}\)
-
The CSF flows through the: a. Dura mater b. Choroid plexus c. Pia mater d. Arachnoid space
-
Prairie Outfitters, Inc., a retailer, accepts paymnent through credit cards. During August, credit card sales amounted to $12,000. The processor charges a 3% fee. Assuming that the credit card...
-
Develop a Java application that determines the total tax for each of three citizens. The tax rate is 15% for earnings up to 30,000 USD earned by each citizen and 20% for all earnings in excess of...
-
Write up to two lines of code that perform each of the following tasks: a) Specify that class Orange inherits from class Fruit. b) Declare that you are going to override the toString method from...
-
A right triangle can have sides whose lengths are all integers. The set of three integer values for the lengths of the sides of a right triangle is called a Pythagorean triple. The lengths of the...
-
In the FRED database, find a variable that is available in both a seasonally adjusted form and a not seasonally adjusted form. Plot both over time and describe how large the seasonal variation in the...
-
An economic variable is persistent if declines in the variable tend to be followed by more declines, and increases by more increases. This question asks you to study the persistence of the civilian...
-
It has been argued that the stock market predicts recessions. Using quarterly data since 1961, plot the real value of the stock market index (the Wilshire 5000 index in the last month of the quarter...
Study smarter with the SolutionInn App