Writing a java program that provides simple statistics

Assignment Help JAVA Programming
Reference no: EM13165147

You will be writing a Java program that provides simple statistics about the input data. The method stubs are given below. This assignment will give you experience with methods, arrays and exceptionhandlin in Java. As always, include comments in your program whereve appropriate.

1. double[] getUserInput()

This method obtains X numbers from the user, where X is also specified by

the user. Use exception-handling to catch input mismatch errors during the

user input. Store the user provided values into an array of doubles, and return

this array to the main method.

2. double arithmeticMean(double[] nums)

This method returns the arithmetic mean of the numbers provided by the input

parameter. Use exception-handling to catch for arithmetic errors.

3. double geometricMean(double[] nums)

This method returns the geometric mean of the numbers provided by the input

parameter. Use exception-handling to catch for arithmetic errors.

4. double[] minAndmax(double[] nums)

This method returns the smallest number and the largest number in the input

parameter. You don't need to return the location of the min and max.

5. double[] scaleUp(double[] nums, int factor)

This method multiplies every number provided by the first input parameter

with a scaling factor (the second parameter). Use exception-handling to catch

for illegal argument error. Specifically, for valid scaling-up operation the

factor has to be at least 1.

6. double[] scaleDown(double[] nums, int factor)

This method divides every number provided by the first input parameter with

a scaling factor (the second parameter). Use exception-handling to catch for

divide-by-zero error.

7. main method:

In this method, first obtain the numbers from the user, and then provide the

user with 5 possible choices (each corresponding to one of the methods above,

except for getUserInput), and prompt the user to pick one. Check the user

input for its validity, it has to be a number between 1 and 5. Then perform the

requested operation, and output the corresponding statistic(s).

i have this so far, and i only need help with 4,5,6,7.

package simplestatistics;
import java.util.Scanner;
public class SimpleStatistics {

public static double[] getUserInput()
{
double [] array;
Scanner input = new Scanner(System.in);
System.out.println("Enter the how many numbers:");
int num = input.nextInt();
array = new double[num];
if (num < 0){
throw new ArithmeticException("value cannot be less than one");
}

try {
for(int i=0; i < num ;i++){
System.out.println("Enter number:");
double userfinalinput = input.nextDouble();
array [i] = userfinalinput;
}
  
}
catch(ArithmeticException ex){
System.out.println("Exception:the value"+"cannot be less than one");
}
System.out.println("Execution continues...");
return array;
}

public static double arithmeticMean(double []array)
{
double mean = 0;
for(int i=0; i < array.length;i++){
mean += array[i];
}
mean = mean / array.length;

if (mean < 0){
throw new ArithmeticException("value cannot be negative number");
  
}
try {
for(int i=0; i < array.length;i++){
mean += array[i];
  
}
mean= mean/ array.length;
System.out.println("the arithmetic mean value is"+mean);
}
  
catch(ArithmeticException ex){
System.out.println("Exception:the mean value"+"cannot be negative number");
}
System.out.println("Execution continues...");
return mean;
  
}
public static double geometricMean (double[]array)
{
double geo_mean = 1;
for(int i=0; i< array.length;i++){
geo_mean *= array[i];
  
}
geo_mean = Math.pow(geo_mean,1/array.length);
  
//do try and catch for this
}

public static double minAndmax (double []array)
{
  
}
public static void main(String[] args) {
double [] array = getUserInput();
      
}

}      
}

Reference no: EM13165147

Questions Cloud

True or false on computer science : True or False 1. If a computer uses hardwired control, the microprogram determines the instruction set for the machine.
Create an employee class : Create an employee class, including two data: an employee number (type int ) and the employee's compensation (in dollars; type float). The member data should comprise an int for storing the employee number and a float for storing the employee's co..
Create dict letter frequencies that reads the file : createDictLetterFrequencies that reads the file and also takes a parameter n. This method should return a dictionary of dictionaries. The outer dictionary associates the previous n letters of a word with an inner dictionary, which indicates the frequ..
Calculate the overhead cost per account : What is the price if a markup of 35% on total cost is used to determine the price and calculate the overhead cost per account for the Money Market Checking.
Writing a java program that provides simple statistics : You will be writing a Java program that provides simple statistics about the input data. The method stubs are given below. This assignment will give you experience with methods
An infix to postfix method for my java program. : an infixToPostFix method for my java program. The method must work with stacks and it should take a string as parameter. The method should be able to convert to postfix mathematic expressions such as: (12 + 4) - 23(9-6)/12. Treat the parenthesis as l..
Creates pet objects from data read from the keyboard : The assignment is to write a program that creates Pet objects from data read from the keyboard. Store these objects into an instance of ArrayList.
Find the first occurrence, the last occurrence : If numbers in a list aren't unique and therefore the largest number could occur more than once would the algorithm find the first occurrence, the last occurance? Every occurance?
State the acid-catalyzed dehydration of heopentyl : The major product of the acid-catalyzed dehydration of heopentyl(2,2-dimethyl-1-propanol) has a different carbon skeleton than that of the starting alcohol

Reviews

Write a Review

JAVA Programming Questions & Answers

  A java program that will prompt the user to input a file

Write a Java program that will prompt the user to input a file (document) in order to count the frequency of each word. This program will display the frequency of each word sorted alphabetically or by frequency (depending on the preference of the use..

  Multiple choice java programming questions

Determine which of the following may be a violation of information hiding if inserted for the comment above?

  Develop java package comprising of class using encapsulation

Develop the Java package comprising of Class and Student with the given requirements. Encapsulation, Method to print student details alone.

  Write a java program that declares an array alpha of 50

Write a Java program that declares an array alpha of 50 elements of type double. Initialize the array so that the first 25 elements are equal to the square of the index variable, and the last 25 elements are equal to three times the index variable. O..

  Write method called median that accepts an array of integer

Write a method called median that accepts an array of integers as its parameter and returns the median of the numbers in the array.

  The williamsburg women''s club

The Williamsburg Women's Club offers scholarships to local high school students who meet any of several criteria. Write an application that prompts the user for a student's numeric high school grade point average (for example, 3.2), the student's num..

  Robot preparing for competition

Create an event so that the skateboard can be controlled by game player

  Create a driver class in java

Your project is to create a driver class that uses SuperJavaIceCreamClass.

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  When the user presses a button

When the user presses a button, get the text from text field. Now extract the words from the text one at a time and find the largest word of length 4 or more. Let's call this largest word X for now. In response, create a question based on the length ..

  Write program in java to calculate interest

Write a program in java to do the following : the following data is stored for each customer in the bank: account number,average balance and number of transaction for each customer it is required to calculate the interest earn

  Identify the 5 code elements

Identify the 5 code elements for a Password class. Things like: class, instance, and final variables, accessor and mutator method, public and private specifiers for methods and member variables.i need to provide detail and descriptions for each code ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd