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...

  • I'm having trouble getting this program to compile and run. It is in C++ Language and...

    I'm having trouble getting this program to compile and run. It is in C++ Language and being run with CodeBlocks. Problem Statement: create and manage a linked list. Program will loop displaying a menu of user operations concerning the management of a linked list. Included will be:       H create link at head       R remove link at head       T create link at tail       K remove link at tail       I remove link at ID          S search...

  • Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d();...

    Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...

  • 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...

  • Hi All, Can someone please help me correct the selection sort method in my program. the...

    Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • 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...

  • java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then...

    java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> {    LinkedList<T> list;       public Stack() {        list = new LinkedList<T>();    }       public boolean isEmpty() {        return list.isEmpty();   ...

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