Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE MAKE ALL 6 OF THESE METHODS AS INSTRUCTED!!! Write a Java class with meth

ID: 3886435 • Letter: P

Question

PLEASE MAKE ALL 6 OF THESE METHODS AS INSTRUCTED!!!

Write a Java class with methods that perform various operations on an array of doubles.

Follow the instructions carefully. In particular, write methods where directed; do not stuff main() with code that should be elsewhere.

Write a method that creates an array of ten doubles, initializes it with ten values taken from console input (ie, a Scanner from System.in), and returns a reference to the array.

Write a method that uses Math.sqrt() to find the square root of each value in an array of doubles and shows each result. This method should not change the values in the array.

Write a method that replaces any value exceeding 500 in an array of doubles with the value 500. This method should be void; in other words it should not return anything. Be sure you understand how array references are sent to methods.

Write a method that copies an array of doubles, replaces each value with its reciprocal (that is, replaces x with 1/x) and returns the new array. Be sure you understand the difference between copying an array and copying an array reference, or you will not do this part correctly.

Write a method that prints out all the values in an array of doubles

main() should call the input method, then send the array to the print method, then run each of the other methods, using the print method to print the current values after each method is done. After running the method that creates a new array, print out both the original array and the one returned by the method.

RULES

(Use Array Lists of capital-D Doubles instead of arrays of doubles.)

(In the method that takes user input, ask the user how many Doubles should be in the list, take input for that number of Doubles, and add the values to the list.)

Explanation / Answer

//Main.java

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;

class Program{

List<Double> a = new ArrayList<Double>();   

public List<Double> Create(){

   Scanner s = new Scanner(System.in);

   for(int i=0;i<10;i++)
   a.add(s.nextDouble());

   return a;
}

public void find_SQRT(){

   double[] target = new double[10];

   for (int i = 0; i < 10; i++) {
  
   target[i] = a.get(i);
    System.out.println(" The square root of "+target[i]+" is "+Math.sqrt(target[i]));
   }
}

public void replace(){

   double[] target = new double[10];

   for(int i=0;i<10;i++){

   target[i] = a.get(i);

   if(target[i]>500)
   target[i] = 500;

   System.out.println(target[i]);
   }
}

public double[] new_Array(){

   double[] target = new double[10];

   for(int i=0;i<10;i++){
   target[i] = a.get(i);
   target[i] = 1/target[i];
   System.out.println(target[i]);
   }
   return target;
}

public void print_Array(){
   System.out.println(" The array elements are : ");
   System.out.println(a);
}
}

public class Main{

public static void main(String[] args){

   List<Double> a = new ArrayList<Double>();   
  
   Program obj = new Program();
  
   System.out.println(" Enter the elements of an array : ");
   a = obj.Create();
   System.out.println(" Square root of the elements of an array : ");
   obj.find_SQRT();
   System.out.println(" Elements of an array after replace: ");
   obj.replace();
   System.out.println(" The elements of an array after inverting: ");
   obj.new_Array();
   obj.print_Array();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote