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

  Can linear search algorithm be encoded using recursion

Determine the average amount of time people spend waiting for tables and provide examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements

  The program should ask the user to enter the student'' answer

Your program should store these correct answers in an array. (Store each question's correct answer in an element of a string array.) the program should ask the user to enter the student's answers for each of the 20 questions, which should be stored i..

  Program to find maximum-minimum of sequence of values

Common task which should be done in loop is to find maximum and minimum of sequence of values. File Temps.java contains program which reads in sequence of hourly temperature readings over 24- hour period.

  Create four classes

Create four classes: Account.java, Checking.java, Savings.java, and AccountArray.java.

  Develop java applet that will help elementary school student

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers.

  Javascript validation - cgi program

CGI mailer script form-mail.pl to your server's cgi-bin directory, and change the permissions on the script to make it executable - BMIS 310

  Java program which demonstrates cellular automata

Using the internet, locate a Java program (or Java applet) which demonstrates "Cellular Automata", in particular "the Game of Life".

  Given an array with 100,000 entries to sort

Sorting  given an array with 100,000 entries to sort. Under what circumstances would you use each of the following: insertion sort,mergesort'quicksort

  Write java program that writes names to text file

Create an empty text file called myfile.txt. Write a Java program that writes your names to the text file created. If the file does not exist, include an exception handler for that error.

  Picky publishing house publishes stories

Picky Publishing House publishes stories in three categories and has strict require- ments for page counts in each category. Create an abstract class named Story that includes a story title, an author name, a number of pages, and a String message. In..

  Java program simulate a network

Java program simulate a network

  Write a program that asks a user for a file name and prints

Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.

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