Question: QUESTION 2 Given the Fruit class with the following data members (attributes): Class name Fruit Attributes String name; Il fruit name String type; // local

QUESTION 2 Given the Fruit class with the following data members (attributes): Class name Fruit Attributes String name; Il fruit name String type; // local or imported double weight; // in kg double price; // price per kilogram : constructor, mutator, accessor, processor, printer Methods a) Write the definition of the following methods: i. A normal constructor that sets all data with values given through its parameter. (2 marks) ii. Accessor method for each attributes. (4 marks) ii. A processor method named islocal() that returns true if it is local fruit or returns false otherwise. (2 marks) iv. A processor method named calcTotalPrice () calculates and returns the total price of the fruit. In order to encourage the buyers to buy the local fruits, 3% discount is given on the total price. (4 marks) b) Assuming that there are objects of Fruit type in an array named fruitList. Write a program fragment for each of the followings: i. Display the name of local fruits which has the highest price. (4 marks) ii. Calculate total sale of the imported fruits. (4 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
