Question


Your output should look as follows: DataSet = 10, 27, 32, 34, 35, 44, 48, 49 Descriptive Statistics: Minimum Maximum Range Si
a) Write a Java class named DataSet that follows the UML (Unified Modeling Language) diagram as described below: DataSet priv




the a) Write a Java class named Dataset that Language) diagram as described below: DataSet private datalist: ArrayList<Intege
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

The below code works perfectly.

I have also attached the output scrrenshot that I got by running the below program.

The code is error-free and yopu just simply compile & run the below program.

Output:

> C:Users\Public>javac DataSet Demo.java C:\Users\Public>java DataSet Demo DataSet = 22, 5, 2, 9, 18, 74, 19, 65, 70, 84, Des

***********************************************************************************************************************************

Code:

import java.io.*;
import java.util.*;
import java.lang.Math;

class DataSet
{
   private ArrayList<Integer> dataList;
  
   public DataSet()
   {
       dataList=new ArrayList<Integer>();
   }
  
   public void setValue(int value,int index)
   {
   dataList.add(index,value);
   }
  
   public int getValue(int index)
   {
   return dataList.get(index);
   }
  
   public void addValue(int value)
   {
   dataList.add(value);  
   }
  
   public boolean isEmpty()
   {
       if(dataList.size()==0)
           return true;
       else
           return false;
   }
  
   public int getSize()
   {
       return dataList.size();
   }
  
   public void sort(boolean ascending)
   {
       Collections.sort(dataList);
   }
  


public int binarySearch(int value)
{

int left=0;
int mid=0;
int right=dataList.size()-1;

while(left<=right)
{
   mid=(left+right)/2;
   if(dataList[mid] < value)
   {
       left=mid+1;
   }
   else if(dataList[mid]>value)
   {
       right=mid-1;
   }
   else
   {
       return mid;
   }
  
}

return -1;
}


  
   public int getMinimum()
   {
       int min_value=Integer.MAX_VALUE;
      
       for(int n : dataList)
       {
           if(n<min_value)
           {
               min_value=n;
           }
       }
      
       return min_value;
   }
  
   public int getMaximum()
   {
       int max_value=Integer.MIN_VALUE;
      
       for(int n : dataList)
       {
           if(n>max_value)
           {
               max_value=n;
           }
       }
      
       return max_value;
   }
  
   public int getRange()
   {
       int a=getMaximum();
       int b=getMinimum();
      
       return a-b;
   }
  
   public int getSum()
   {
       int sum=0;
       for(int n : dataList)
       {
           sum=sum+n;
       }
       return sum;
   }
  
   public double getMean()
   {
       int size=dataList.size();
       int sum=getSum();
      
       double result=(double)sum/size;
       return result;
   }
  
   public double getMedian()
   {
       int size=dataList.size();
      
       if(size%2==0)
       {
           int temp=size/2;
           int a=dataList.get(temp);
           int b=dataList.get(temp+1);
           double result=(double)(a+b)/2;
           return result;
       }
       else
       {
           int temp=size/2;
           double result=(double)dataList.get(temp);
           return result;
       }
          
   }
  
   public double getStandardDeviation()
   {
       double mean=getMean();
       int size=dataList.size();
       double sum=0;
       for(int n : dataList)
       {
           sum=sum+Math.pow((n-mean),2);
       }
         
       double result=Math.sqrt(sum/size);
         
       return result;
   }
  
   public int getVariance()
   {
   double mean=getMean();
       int size=dataList.size();
       double sum=0;
       for(int n : dataList)
       {
           double subtract=n-mean;
           sum=sum+(subtract*subtract);
       }
         
       int result=(int)sum/size;
         
       return result;
  
   }
   public double getMidRange()
   {
       int a=getMaximum();
       int b=getMinimum();
      
       double result=(double)(a+b)/2;
       return result;
   }      
  
   public void printDataSet()
   {
       for(int n: dataList)
       {
           System.out.print(n+", ");
       }
          
   }
}

public class DataSetDemo
{
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);
       DataSet d=new DataSet();
      
       String c="y";
      
       while(c.equals("y") || c.equals("Y"))
       {
      
       for(int i=0;i<10;i++)
       {
           double r=Math.random()*(100-1)+1;
           d.addValue((int)r);
      
       }
      
       System.out.println("\n\nDataSet = ");
       d.printDataSet();
      
       System.out.println("\n\nDescriptive Statistics:");
       System.out.println("==================================");
      
       System.out.println("\nMinimum = "+d.getMinimum());
       System.out.println("\nMaximum = "+d.getMaximum());
       System.out.println("\nRange = "+d.getRange());
       System.out.println("\nSize = "+d.getSize());
       System.out.println("\nSum = "+d.getSum());
       System.out.println("\nMean = "+d.getMean());
       System.out.println("\nMedian = "+d.getMedian());
       System.out.println("\nStandard Deviation = "+d.getStandardDeviation());
       System.out.println("\nVariance = "+d.getVariance());
       System.out.println("\nMid Range = "+d.getMidRange());
      
       System.out.println("\n\nEnter a integer value to be set in the DataSet: ");
       int num=sc.nextInt();
       System.out.println("\n\nEnter a valid index from the DataSet: ");
       int index=sc.nextInt();
      
       d.setValue(num,index);
       d.sort(true);
       System.out.println("\n\nDataSet = ");
       d.printDataSet();
      
       System.out.println("\n\nValue "+num+" has been set and sorted in the DataSet.");
      
       System.out.println("\n\nEnter a value to be searched in the DataSet: ");
       num=sc.nextInt();
      
       int temp=d.binarySearch(num);
      
       if(temp==-1)
       {
           System.out.println("\n\nElement Not Found !!!");
       }
       else
       {
           System.out.println("\n\nValue "+num+" is found at index "+temp+" in the DataSet.");
       }
      
       System.out.println("\n\nDo you want to repeat (Y-yes or N-no) ? ");
       c=sc.next();
      
       }
      
      
      
   }
}

> C:Users\Public>javac DataSet Demo.java C:\Users\Public>java DataSet Demo DataSet = 22, 5, 2, 9, 18, 74, 19, 65, 70, 84, Descriptive Statistics : Minimum = 2 Maximum 84 Range = 82 Size = 10 Sum = 368 Mean = 36.8 Median = 46.5 Standard Deviation = 30.648980407184837 Variance = 939 Mid Range = 43.0 Enter a integer value to be set in the DataSet:

Add a comment
Know the answer?
Add Answer to:
Your output should look as follows: DataSet = 10, 27, 32, 34, 35, 44, 48, 49...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Money Lab using arraylists in Java Using the Coin class below create a program with the...

    Money Lab using arraylists in Java Using the Coin class below create a program with the following requirements Create an arraylist that holds the money you have in your wallet. You will add a variety of coins(coin class) and bills (ones, fives, tens *also using the coin class) to your wallet arraylist. Program must include a loop that asks you to purchase items using the coins in your wallet. When purchasing items, the program will remove coins from the arraylist...

  • Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in....

    Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in. The main method prompts for a salary, then uses a TaxTableTools method to get the tax rate. The program then calculates the tax to pay and displays the results to the user. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. a. Modify the TaxTableTools class...

  • JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on 4. Based on the implementation of ArrayIntlist or ArrayList, write a class Sor...

    JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on 4. Based on the implementation of ArrayIntlist or ArrayList, write a class SortedIntList or SortedList that provides most of the same operations but maintains its elements in sorted order. When a new value is added to the sorted list rather than appending it to the end of the list, it is placed in the appropriate index to maintain sorted order of...

  • This has to be extremely precise, thank you for your time. ols Window Help U +...

    This has to be extremely precise, thank you for your time. ols Window Help U + 1 /write a class meeting the following specifications: 3 //The class is declared as public. 4 //The class is named Country. 5 //The class has a field of type String named anger. 6 //The class has a field of type int named stretch. 7 //The class has a field of type double named film. 8 //The class has a exactly one constructor. 9 //The...

  • Please use public class for java. Thank you. 1. (10 points) Write a method that computes...

    Please use public class for java. Thank you. 1. (10 points) Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula futurelnvestmentValue numberOfYears 12 investmentAmount X ( monthlyInterestRate) Use the following method header: public static double futurelnvestmentValue( double investmentAmount, double monthlyInterestRate, int years) For example, futureInvestmentValue 10000, 0.05/12, 5) returns 12833.59. Write a test program that prompts the user to enter the investment...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • this is for java class Define a utility class for displaying values of type double. Call...

    this is for java class Define a utility class for displaying values of type double. Call the class DoubleOut. Include all the methods from the class DollarFormat in Listing 6.14, all the methods from the class OutputFormat of Self-Test Question 30, and a method called scienceWrite that displays a value of type double using e notation, such as 2.13e–12. (This e notation is also called scientific notation, which explains the method name.) When displayed in e notation, the number should...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • 10.3 Example. When you first declare a new list, it is empty and its length is...

    10.3 Example. When you first declare a new list, it is empty and its length is zero. If you add three objects—a, b, and c—one at a time and in the order given, to the end of the list, the list will appear as a b c The object a is first, at position 1, b is at position 2, and c is last at position 3.1 To save space here, we will sometimes write a list’s contents on one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT