package april_2;
public class New {
/*
* fillArrayWithRandomNumbers(), fills the given array
with random values
* @param a 1-d array of double type
*/
public static void fillArrayWithRandomNumbers(double
[] list)
{
for(int i = 0 ; i < list.length
; i++)
{
list[i] =
Math.random() * 100;
}//end of for loop
} //end of fillArrayWithRandomNumbers method
/*
* printArray(), prints the given array
* @param a 1-d array of double type
*/
public static void printArray(double []list)
{
//print header
System.out.println("\n\n\n\t Index
\t Value \n");
System.out.println("===================================");
for(int i = 0 ; i < list.length
; i ++)
{
System.out.printf("\t %d \t %6.2f\n",i, list[i]);
}//end of for loop
}//end of printArray method
/*
* getArrayAverage(), returns the average of the
elements
* @param a 1-d array of double type
* @return a double value
*/
public static double getArrayAverage(double []
list)
{
double avg = 0.0;
double total = 0.0;
for(int i = 0 ; i < list.length
; i ++)
total +=
list[i];
avg = total / list.length;
return avg;
}//end of method getArrayAverage
/*
* getMax(), returns the maximum of the elements
* @param a 1-d array of double type
* @return a double value
*/
public static double getMax(double[] list)
{
double max = 0.0;
max = list[0];
for(int i = 1; i < list.length ;
i ++)
{
if(list[i] >
max)
max = list[i];
}// end of for loop
return max;
} //end of getMax method
/*
* getMin(), returns the maximum of the elements
* @param a 1-d array of double type
* @return a double value
*/
public static double getMin(double[] list)
{
double min = 0.0;
min = list[0];
for(int i = 1; i < list.length ;
i ++)
{
if(list[i] >
min)
min = list[i];
}// end of for loop
return min;
} //end of getMin method
public static void main(String[] args) {
double[] exam1 = new
double[35];
double average, largest,
smallest;
fillArrayWithRandomNumbers(exam1);
printArray(exam1);
average =
getArrayAverage(exam1);
System.out.printf(" Average Exam 1
score is %6.2f \n", average);
largest = getMax(exam1);
System.out.printf(" Largest Exam 1
score is %6.2f \n", largest);
smallest = getMax(exam1);
System.out.printf(" Smallest Exam 1
score is %6.2f \n", smallest);
double[] exam2 = new
double[20];
double average2, largest2,
smallest2;
fillArrayWithRandomNumbers(exam2);
printArray(exam2);
average2 =
getArrayAverage(exam2);
System.out.printf(" Average Exam 2
score is %6.2f \n", average2);
largest2 = getMax(exam2);
System.out.printf(" Largest Exam 2
score is %6.2f \n", largest2);
smallest2 = getMax(exam2);
System.out.printf(" Smallest Exam 2
score is %6.2f \n", smallest2);
}
}


With arays of varius sizes: Write the follawing methuds and test the { public static double getMa...
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
Part 1. Primitive Types, Sorting, Recursion for Homework.java a) Implement the static method initializeArray that receives as a parameter an array of integers. Use a for loop and an if statement to put 0s in the odd positions of the array and 5s in the even positions. b) Implement the static method printArray that receives as a parameter an array of integers. Use a for statements to print all the elements in the array. c) Implement the static method insertionSort...
public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
public class Permutations
{
// Helper method for outputting an array.
private static void PrintArray(string[] array)
{
foreach (string element in array)
{
Console.Write($"{element} ");
}
Console.WriteLine();
}
// Helper method for invoking Generate.
private static void Generate(string[] array)
{
Generate(array.Length, array);
}
public static void Main(string[] args)
{
}
}
procedure generate(k : integer, A : array of any):
if k = 1 then
output(A)
else
// Generate permutations with kth unaltered
// Initially k == length(A)
generate(k -...
I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...
AP computer science: please do not use other advanced ways to
solve this problem, it is just an AP class in high school. Thank
you so much!
publie class ArrayMethods public class Array Methods // precondition: anArray is not null. target is an element in the array // postcondition: absolute value of difference between target and average of // precondition: anArray is not null // postcondition: anArray is output anArray is returned. public static void PrintArray (int [0 anArray) public...
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...
I need to change the following code so that it results in the
sample output below but also imports and utilizes the code from the
GradeCalculator, MaxMin, and Student classes in the com.csc123
package. If you need to change anything in the any of the classes
that's fine but there needs to be all 4 classes. I've included the
sample input and what I've done so far:
package lab03;
import java.util.ArrayList;
import java.util.Scanner;
import com.csc241.*;
public class Lab03 {
public...