Write a constructor that takes arguments for the candys


Write a class named Candy

1. The Candy class should have private fields for holding the candy's name and calories per serving (an integer).2. Create overloaded constructors consisting of2a. a no-arg constructor that supplies default values for the candy's attributes and2b. a constructor that takes an argument for each of the fields on a candy object.3. Include mutator and accessor methods for the class's fields.II. Next, write a class named SourCandy, which extends the Candy class.1. The SourCandy class should have an integer field indicating the degree of sourness with possible values ranging from 1 (not very sour) to 10 (extremely sour).2. Write a constructor that takes arguments for the candy's name, it's calories per serving, whether it contains peanuts, and it's sourness.3. Write appropriate accessor and mutator methods for the class's field including input validation where appropriate.III. Demonstrate an object of the SourCandy class in a simple program.

 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Write a constructor that takes arguments for the candys
Reference No:- TGS0645100

Expected delivery within 24 Hours