Question: 1. Create three classes Data, Single, and List, as follows: a. Create an abstract class Data, which will contain no instance variables, no constructor,

1. Create three classes Data, Single, and List, as follows: a. Create an abstract class Data, which will contain no instance variables, no constructor, and only one method: double valueOf() which returns 0.0. b. Create a class Single which is a subclass of Data, and which will store one double value. Provide a constructor to initialize the value. Override the valueOf() method so that it returns this value. c. Create a class List which is a subclass of Data, and which will store a double[] array. Provide a constructor List (double[] a) which will initialize this array. Override the valueOf() method so that it returns the sum of all the doubles in the array. Note that this will always be a full array, not a partially full array. There will be no separate length variable. 2. Start with the Template Lab7.java file. It creates a list of Data objects (a mixture of Single and List) using a Data[] myData array. Take a look at it. Add a loop at the indicated position which will find and print the sum of every number that appears in myData, whether it appears in a Single or in a List, using valueOf(). It should print the line The sum of everything is 35.8 SILVER Creating a bigger class hierarchy 1. Add a length() method to the List class which returns the size of the list stored in the object. You are not allowed to add a length() method to the Data or Single classes. (This would be a logical thing to do, but it would destroy the purpose of the question.) 2. Add more code to the TemplateLab7.java file at the indicated position which will find and print the total number of values that appear anywhere in myData. It should print the line There are 7 values in total. as well as the output line from the Bronze exercise. 1. Create three classes Data, Single, and List, as follows: a. Create an abstract class Data, which will contain no instance variables, no constructor, and only one method: double valueOf() which returns 0.0. b. Create a class Single which is a subclass of Data, and which will store one double value. Provide a constructor to initialize the value. Override the valueOf() method so that it returns this value. c. Create a class List which is a subclass of Data, and which will store a double[] array. Provide a constructor List (double[] a) which will initialize this array. Override the valueOf() method so that it returns the sum of all the doubles in the array. Note that this will always be a full array, not a partially full array. There will be no separate length variable. 2. Start with the Template Lab7.java file. It creates a list of Data objects (a mixture of Single and List) using a Data[] myData array. Take a look at it. Add a loop at the indicated position which will find and print the sum of every number that appears in myData, whether it appears in a Single or in a List, using valueOf(). It should print the line The sum of everything is 35.8 SILVER Creating a bigger class hierarchy 1. Add a length() method to the List class which returns the size of the list stored in the object. You are not allowed to add a length() method to the Data or Single classes. (This would be a logical thing to do, but it would destroy the purpose of the question.) 2. Add more code to the TemplateLab7.java file at the indicated position which will find and print the total number of values that appear anywhere in myData. It should print the line There are 7 values in total. as well as the output line from the Bronze exercise.
Step by Step Solution
There are 3 Steps involved in it
Here is the implementation of the classes Data Single and List as described in the question java abs... View full answer
Get step-by-step solutions from verified subject matter experts
