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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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