Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / homework help / questions and answers / engineering / computer science /

ID: 654401 • Letter: H

Question

home / homework help / questions and answers / engineering / computer science / in the first part of this assignment, you will ...

Question

In the first part of this assignment, you will design and write a class that represents a real-world object formed around a collection of numeric values. The collection can be any type of collection you wish except for any used in class or the textbook examples.

In the second part, you will write a program that demonstrates the use of the class.

In the third part, you will write java doc style comments for the Part I class you wrote.

Part I:

Select a "real-world" object that has not been used in class lecture and/or the textbook.

The class that you choose to represent the object must minimally meet the following requirements:

The "data part must declare the attributes correctly consisting of:

A miniumum of the two attributes of :

An array that represents a collection of items of the same type.

A counter that represents the number of items in the collection.

The "operations" part must include a minimum of methods that perform the following when called:

A no-arg constructor method that creates an object with reasonable defaults for the initial state, which in this case is an empty collection of numeric values.

adds a user supplied value to the collection.

returns the count of items in the collection.

returns the sum of the values in the collection.

returns the minimum value in the collection.

returns the maximum value in the collection.

returns the average of the values in the collection.

searches for the parameter target value, returning true if found and false otherwise.

prints all of the values stored in the array.

The set and get methods for each attribute.

Bonus 1 : An additional constructor that takes an array of initial values for the object's array as a parameter.

Bonus 2 : Add a method to this class that returns the median value of the collection.

Bonus 3 : Add a method to this class that returns the mode of the collection.

Part II: Write a "client" class that demonstrates the use of the object. Examples from class: Sales which uses class SalesData & CalcAverage which uses Grader.

Note that the examples are "similar" but not identical to your assignment.

Part III: Javadoc is a tool that generates html documentation from Javadoc comments in the code.

To use javadoc

add Javadoc style comments for the class heading and method headings.

run the javadoc program with the source file as an argument.

The javadoc program will create a file named index.html and "several" other documentation files in the same directory as the input file.

When you double-click on index.html, the browser will display the documentation created by javadoc for your class as a web page such as those you have viewed for the Scannner class or the Random class from the Java API.

Here is an example to use for #1.

Explanation / Answer

Part 1

import java.io.*;

class a
{
   int book[10];
   int n;
   a()
   {
       n=10;
   }

   void add()
   {
       DataInputStream o = new DataInputStream(System.in);

       for(i=0;i<10;i++)
       {
           System.out.println("Enter No");
           book[i] = Integer.parseInt(o.readLine());

       }

   }

   int get_count()
   {
       return book.length();
   }

   int max()
   {
       int i,l=book[0];
       for(i=0;i<10;i++)
       {
           if(book[i]>l)
           {
               l=book[i];
           }
       }
       return l;
   }

   int min()
   {
       int i,s=book[0];
       for(i=0;i<10;i++)
       {
           if(book[i]<s)
           {
               s=book[i];
           }
       }
       return s;
   }

   int avg()
   {
       int i,sum=0;
       for(i=0;i<10;i++)
       {
           sum=sum+a[i];
       }
       return (sum/10);
   }
  

   void print()
   {
       int i;
       for(i=0;i<10;i++)
       {
           System.out.println(a[i]);
       }
      
   }  
}

Part 2

class CalcAverage extends Grader
{
}

class SalesData extends CalcAverage
{
}

class Sales extends SalesData
{
}  

class client
{
   public static void main(String args[])
   {
       Sales o = new Sales();
   }
}