Question 1 A programmer creates the Java class shown on the facing page, representing a numeric dataset read from a file. The class has a constructor that creates an object containing the data from the file, given the name of that file as a string. It also has a method called mean that returns the arithmetic mean value of the stored data. The questions that follow concern this class. You may include small fragments of code in your answers if appropriate, but you should not reimplement the class. Keep in mind that full marks can be obtained with purely descriptive answers. (a) The class as shown here will not compile. The compiler identifies two issues that need to be fixed, one occurring in the constructor and the other within the mean method. Explain what the issues are and describe how you would fix them. (b) Another programmer who is reviewing the code describes line 6 as 'dangerous'. What possible reason might there be for this comment, and how could you modify the code to fix the problem? (c) Explain the problems with the error handling done on lines 26–29, and describe a better and more flexible way of indicating an error. (d) Imagine that the creator of this class later finds that it would be useful to add more values to the dataset, after a Data object has been created. Explain why the class cannot support this in its current form and describe that changes that you would need to make in order to provide this feature.
Question 1 A programmer creates the Java class shown on the facing page, representing a numeric dataset read from a file. The class has a constructor that creates an object containing the data from the file, given the name of that file as a string. It also has a method called mean that returns the arithmetic mean value of the stored data. The questions that follow concern this class. You may include small fragments of code in your answers if appropriate, but you should not reimplement the class. Keep in mind that full marks can be obtained with purely descriptive answers. (a) The class as shown here will not compile. The compiler identifies two issues that need to be fixed, one occurring in the constructor and the other within the mean method. Explain what the issues are and describe how you would fix them. (b) Another programmer who is reviewing the code describes line 6 as 'dangerous'. What possible reason might there be for this comment, and how could you modify the code to fix the problem? (c) Explain the problems with the error handling done on lines 26–29, and describe a better and more flexible way of indicating an error. (d) Imagine that the creator of this class later finds that it would be useful to add more values to the dataset, after a Data object has been created. Explain why the class cannot support this in its current form and describe that changes that you would need to make in order to provide this feature.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education