Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given the template of a class named ChickenEgg as follows: public class ChickenEgg private char grade; //A, B, C private int numEgg; //number of
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)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started