Write a main class with a main method that tests your method

Assignment Help JAVA Programming
Reference no: EM131028324

Question 1. Write static methods as follows:

• double sum(double[] a) - returns the sum of the entries in the array a.

• double[] fill(int n, double v) - returns an array of n doubles, all of whose values are v.

• double[] random (int n) - return an array of n random doubles.

• double min(double[] a) - returns the minimum element of the array a.

• double max(double[] a) - returns the maximum element of the array a.

• double average(double[] a) - returns the average (or mean) of the elements of the array a.

• double variance(double[] a) - returns the variance of the elements of the array a (note: this method should call your average method).

• double stdDev(double[] a) - returns the standard deviation of the elements of the array a (note: this method should call your variance method).

• double[] read() - reads an array from the keyboard and returns it (read the number of elements first, and then that many numbers).

• void print(double[] a) - prints an array, a, on a single line with commas between elements (do NOT use Arrays.toString()).

Write a Main class with a main method that tests your methods appropriately (i.e. by calling each method at least once with various inputs), and printing the results.

Question 2. Consider the following method and method call:

public static int inc(int a) {

a++;

return a;

}

int a = 10;

int b = inc(a + 12);

int c = inc(a);

System.out.println(a);

System.out.println(b);

System.out.println(c);

What is the output from this code? Carefully explain your answer (i.e. carefully show how the method

inc is called).

Question 3. Consider the following method and method call:

public static int[] inc(int[] a) {

a[0]++;

return a;

}

int[] a = { 10, 20, 30, 40 };

int[] b = inc(a);

System.out.println(b[0]);

System.out.println(a[0]);

What is the output from this code? Carefully explain your answer (i.e. carefully show how the method

inc is called).

Question 4. Consider the following code:

int[] a = { 10, 20, 30, 40 };

int[] b = a;

int[] c = { 10, 20, 30, 40 };

System.out.println(a == b);

System.out.println(a == c);

What is the output from this code? Carefully explain your answer.

Reference no: EM131028324

Questions Cloud

How many choices are possible to find solution : If who selected which choice is ignored (as a chef would). Analyze this part by the number of different choices made.
Build an application based upon temperature converter app : e purpose of this assignment to confirm that sub routines and functions can be used within Visual Basic programs. Build an application based upon the Temperature Converter application demonstrated in this week's Presentation.
How is political independence embedded in role of fed chair : An article in the Wall Street Journal commented that despite Perry's remarks: " Bernanke is willing to embrace the political independence embedded in his role to do what Fed officials think the economy needs." How is "political independence" embed..
Constructor functions for your button events : constructor functions for your button events as outlined. This application simulates a vending machine that dispenses soft drinks.
Write a main class with a main method that tests your method : Write a Main class with a main method that tests your methods appropriately (i.e. by calling each method at least once with various inputs), and printing the results.
How the statistical devices can be used in business : How the following statistical devices can be used in business today? Describe their usefulness and how businessman can be benefit, or how to help them in making sound decisions. (Explain individually)
How many distinct ways can the assignments be made : Once all of the students have had their training, they will be assigned to 3 teams with 4 workers on each team and team duties will be assigned.
How many different orders can the song be arranged : A disk jockey can play 7 songs during his program. If there are 13 songs to chose from, in how many different orders can the song be arranged?
Statements for kohls corporation for the 2010 fiscal year : Financial statements for Kohl's Corporation for the 2010 fiscal year ending January 29, 2011. Under the term Groupings Filter, change the term All Forms to Annual Filings using the drop-down arrow and press Search.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Development of a simple menu driven program

Identify all of the lines of code within the program that are associated with obtaining user input. This can be done by either copying the lines into your answers or highlighting the lines within the code.

  Write java program that calculates total order for customer

Write a Java program that calculates the total order for a customer. The order should include the details of buying several products. For each product (item), there should be a product code, product price, product description, and product icon.

  Program that prompts the user to enter the year and display

Write a program that prompts the user to enter the the year and first day of the year and displays the calendar table for the year on the console. For example , if the user entered the year 2013, and 2 for tuesday, January 1, 2013, your program shoul..

  Sense a slightly negative attitude

While executing a project, you sense a slightly negative attitude in your team.Which type of document do you now need, among others, to better understand and then be able to improve the situation?

  Debug a program with a jframe

Design, implement, test, and debug a program with a JFrame that allows the user to enter a series of contacts' names, ages, e-mail addresses, and cell phone numbers, and creates a file from the entered data

  What is the average response time for this system?

A web server receives a request every 50ms and processes web requests every 8 ms. Using queuing theory, 1. What is the average response time for this system?

  Compute the average grades

Write a program that allows a teacher to compute the average grades for EACH student in his or her class (NOT a single average for the entire class)

  What are the benefits of using javascript

Write a 150-word synopsis on how JavaScript is used to add functionality to a website. What are the benefits of using JavaScript for this application?

  Create a new child class and new driver program

In this assignment you will create a new child class and new driver program. Please review that example before continuing with this assignment. You should fully understand the shape program above

  Write a program that asks for purchase price

Write a program that asks for purchase price and to calculate, state sales tax, county sales tax and then display purchase price, both sales tax amount and then the total.

  Write an application bmicalc

Write an application (BMICalc) that reads the user's weight in poinds and height in inches, then calculates the Body Mass Index.

  Write a java program that plays the game of craps

Write a Java program that plays the game of Craps using the rules stated above so that it simulates a game without human input

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