Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Information for class Chicken and its subclass, Spicy is given below. public class Chicken ( private String chickenType; private int quantity; public final double
Information for class Chicken and its subclass, Spicy is given below. public class Chicken ( private String chickenType; private int quantity; public final double CHICKEN PRICE = 10.00; public Chicken (String chickenType, int quantity) { this.chickenType - chickenType; this.quantity quantity; } public int getQuantity(){ return quantity; public void getChickenType () 1 return chickenType; H public String toString() ( return "Chicken Type: "+chickenType +", Quantity: quantity", "; public class Spicy extends Chicken { private boolean discount Coupon; // if value is true give 5% off public final double ADDON_PRICE 3.10; // add on the price // define normal constructor public boolean isDiscount Coupon () { return discount Coupon; public double calculatePrice () { // calculate the price the customer has to pay } // gives 5% off, if customer has discount coupon. public String toString(){ ( return super.toString() + "Discount Coupon:" discount Coupon; a) Write Java program segments to do the following: i. Define normal constructor for Spicy class. (2 marks) ii. Define the method calculate Price () for Spicy. Price per unit is CHICKEN PRICE plus the ADDON PRICE. 5% discount is given if the customer has a discount coupon. (3 marks) b) In the main method: i. Create an array of objects with type Chicken named chickens. The array size is 100. (1 mark) Assume that 100 Spicy objects have been stored inside the array chickens. Print the quantity and type of chicken for each object. (2 marks) Using the same array, calculate the total price of all the Spicy chickens. (2 marks)
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