Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

=+e) What is the equation of the regression line?

Answered: 1 week ago