Given the template of a class named ChickenEgg as follows: public class ChickenEgg private char grade;...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given the template of a class named ChickenEgg as follows: public class ChickenEgg private char grade; //A, B, C private int numEgg; //number of eggs //Methods: //constructors, mutators, accessors, processor a) Write the following method definition: i) Default constructor for the ChickenEgg class by assigning all attributes with the suitable initial values. (2 marks) ii) Mutator to be assigned each attribute that requires to be defined separately for the ChickenEgg class. (3 marks) iii) Processor method named calPrice () that calculates and returns the total price based on the grade and number of eggs bought. The following table shows the price for each grade of egg: Grade ABC Price/egg (RM) 0.35 0.25 0.20 (4 marks) b) Write the following statement(s) in the application program: i) Construct an object named egg using the default constructor. (1 mark) ii) Set the properties of the object egg using mutator that is defined in the class definition where the user has assigned 'B' for grade and 30 for the number of eggs bought (2 marks) iii) Display the information about the object by calling the accessor method of each attribute. (2 marks) iv) Print the suitable message and follow by the total price that need to be paid by calling the appropriate method (1 mark) Given the template of a class named ChickenEgg as follows: public class ChickenEgg private char grade; //A, B, C private int numEgg; //number of eggs //Methods: //constructors, mutators, accessors, processor a) Write the following method definition: i) Default constructor for the ChickenEgg class by assigning all attributes with the suitable initial values. (2 marks) ii) Mutator to be assigned each attribute that requires to be defined separately for the ChickenEgg class. (3 marks) iii) Processor method named calPrice () that calculates and returns the total price based on the grade and number of eggs bought. The following table shows the price for each grade of egg: Grade ABC Price/egg (RM) 0.35 0.25 0.20 (4 marks) b) Write the following statement(s) in the application program: i) Construct an object named egg using the default constructor. (1 mark) ii) Set the properties of the object egg using mutator that is defined in the class definition where the user has assigned 'B' for grade and 30 for the number of eggs bought (2 marks) iii) Display the information about the object by calling the accessor method of each attribute. (2 marks) iv) Print the suitable message and follow by the total price that need to be paid by calling the appropriate method (1 mark)
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
In the event of a default the forfait does not have recourse against the exporter in the event of a default by the importer. the forfait does have recourse against the exporter in the event of a...
-
I have a baseline historical defect rate of 1 0 % since I have started a process.. I make a change to the process and I get a defect rate of 8 % . What can I conclude?
-
which category of common equity shareholders are entitled to receive an additional dividend if the company profits exceed a pre- specified level
-
You are the senior auditor in charge of the December 31, 2018, year-end audit for Cleo Patrick Cosmetics Inc. (CPCI). CPCI is a large, privately held Canadian company that was founded in 1999 by one...
-
Evaluate each of the following, accurate to the nearest cent. 9500 (I9075)51 0.075
-
An annual report of Sprint Corporation contained a rather lengthy narrative entitled "Review of Segmental Results of Operation." The narrative noted that short-term notes payable and commercial paper...
-
Refer to the discussion about insider trading in this chapter to answer the following questions: 1. What does insider trading mean? 2. Why do you think insider trading is illegal in the United States...
-
Bravo Steel Company supplies structural steel products to the construction industry. Its plant has three production departments: cutting, grinding, and drilling. The estimated overhead cost and...
-
Find the present value of a continuous stream of income over 4 years when the rate of income is constant at $ 3 3 , 0 0 0 per year and the interest rate is 6 % . The present value is $ . ( Round to...
-
Determine the value of have due a K for which the system will percentage overshoot of approximately 10%. step input R($). to 9
-
1.Mass Balance company is manufacturing a new digital scale for use by a large chemical company. The order is 40 units. The first scale took 60 hours of Direct Labor.Learning rate is 80%. a.What is...
-
Churchill Products is considering updating its cost system to an activity-based costing system and is interested in understanding the effects. The company's cost accountant has identified three...
-
identify management processes currently being used in an MRO. What does their organizational structure look like? Is it effective? Why, or why not?
-
If you had to describe Newton's third law of "equal and opposite" to a friend that is not in a science class, how would you go about doing this? Have any good resources to help you explain it? (e.g.,...
-
Do you agree with HubSpot that the rules of marketing have changed? If so, how? Is inbound marketing the answer? Why or why not? (Suggestion: Identify the benefits and risks involved with inbound...
-
E5.5 (LO 3) Presented below are transactions related to LiGourmet. 1. On December 3, Li sold HK$580,000 of merchandise onaccount to South China Ltd. terms 1/10, n/30, FOB shipping point.The cost of...
-
Fill in each blank so that the resulting statement is true. 83 + 103 = ______ .
-
Calculate profitability and asset management ratios using sales and receivables data.} - Because sales revenue is such a key component of a company's success, analysts are interested in a large...
-
When is revenue generally considered earned?LO6
-
Explain the criteria for revenue recognition.LO3
Study smarter with the SolutionInn App