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

  Show running versions of the program

Show three running versions of the program in a single screen shot with 3 different size stop signs - Make the circle a red filled circle. Add 4 buttons below the Left-Right-Up-Down buttons with Red and any three other colours.

  Programming languages for example pascal

Some programming languages for example Pascal have used the semi colon to seperate statements while java uses it to terminate the statements. which of them in your opinion is most natural and least likely to result in syntax errors? support your a..

  Make a program in java language with classes

Make a program, in JAVA language with classes, that simulates health attending in one business day, according to the information just given.

  Create the benefit class

create the Benefit class

  Write a program that takes cents as an integer and converts

Write a program that takes cents as an integer and converts it to dollars and cents and the conversion should be done in a function called NormalizeMoney.

  Develop a solution for bookstore inventory management system

Develop an object oriented solution for Bookstore Inventory Management System. Identify the necessary objects and actions that are required to produce your solutions.

  Implement a card game in java

In this assignment, you will be asked to implement a card game. You will need to make several design decisions for your code. It will be expected that all classes you write will utilize the principle of encapsulation.

  A regular polygon is an n-sided polygon

A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree(i.e the polygon is both equilateral and equiangular).

  Evaluate the rtas resource requirements

Design and implement a set of classes and interfaces and use them to evaluate the RTA's resource requirements.

  Create java applet to input miles driven and gallons used

Create the Java applet which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display miles per gallon obtained for each tankful.

  Method to store the product of the two arrays in third array

Write a method to store the product of the two arrays in the third array

  Write a java gui application to calculate total resistance

Write a Java GUI application to calculate total resistance, current, and power in a circuit.

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