Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java class named Total, see Hint 1. The class contains a data field, a constructor and two methods. The field is an array

Create a Java class named Total, see Hint 1. The class contains a data field, a constructor and two methods. The field is an array of numbers, the array type can be any of the six numeric types of Java, see Hint 2. The constructor takes an argument to initialize the field. Method computeTotal( ) computes the sum total of all array elements. The return type is double (see Hint 3) . Method compareTotals( ) checks if the computeTotal() return values obtained for two Total objects agree or not; returns true/false accordingly. Create an Application class having the main method. The working type is determined here. Test the Total class methods running them on four different arrays of types float, int, long and byte; compare each pair and print the results to the console.

Hints

Make the Total class generic, use the type parameter in wherever needed in field declarations and/or method definitions. Number is a class in the Java library and it serves as a superclass for all numeric wrapper classes. Number has a method doubleValue( ) implemented by each numeric subclass and the method returns the double type version of the numeric value. Use Number as a bound for the generic types (notice the analogy to Person in the Fitness project). See if you need a wildcard in the definition of compareTotals( ). Comment on your experience.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago