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

Need help editing code to make it look like expected output /** * Lab 5a * To pr

ID: 3600290 • Letter: N

Question

Need help editing code to make it look like expected output

/**
* Lab 5a
* To pracic various array skills such as initializing, setting individual values, summing, copying, and displaying
* 107-2
* 24-Oct-2017
* @author
*/
import java.util.*;
public class Lab5a {
public static void main(String[] args) {
// System.out.println("Program 5, , mascxxxx"); // Replace with your name and mascID

//--------------------------------------------------------------------------------
//1. Display the value of element 6 of array f
//--------------------------------------------------------------------------------
int[] f = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
  
//TODO: Print element 6 of array f
  
System.out.println(f[2]); //The element 6 is at index 2 in f.
  
//--------------------------------------------------------------------------------
// 2. Initialize each element of g to 8
//--------------------------------------------------------------------------------
int[] g = new int[7];
for (int i=0; i < g.length; ++i)
// TODO: Fill array g
g[i] = 8; //Every element of g is initialized to 8.

for (int i=0; i < g.length; ++i)
System.out.println("g[" + i + "] is " + g[i]);
System.out.println();

//--------------------------------------------------------------------------------
// 3. Total 100 elements of floating point array c filled with values 1 to 100
//--------------------------------------------------------------------------------
float[] c = new float[100];
double total = 0.0;
  
//TODO: Fill and sum array c
for(int i = 0; i < 100; i++)
c[i] = i+1; //Fills the elements of float array c with values 1 to 100.
  
for(int i = 0; i < 100; i++)
total += c[i]; //Sums the array c elements.  
  
System.out.println("Total is " + total);
System.out.println("Average is " + (total / c.length));
System.out.println();
  
//--------------------------------------------------------------------------------
// 4. Copy 11-element array c into the first 11 positions of 34-element array b.
//--------------------------------------------------------------------------------
  
// TODO: create array b and copy c's elements into it
float[] b = new float[34]; //Creates a 34-element float array b.
for(int i = 0; i < 11; i++) //Copies first 11 elements from c into b.
b[i] = c[i];
  
for (int i=0; i < b.length; ++i)
System.out.print(b[i] + " ");
System.out.println();
System.out.println();
  
//--------------------------------------------------------------------------------
// 5. Determine and print the largest and smallest values contained in 99-element
// floating-point array w
//--------------------------------------------------------------------------------
Random rand = new Random(1025L);
  
//TODO: Declare array w with 99 elements
float[] w = new float[99]; //Declares w, a float array of size 99.
  
double min = 5001;
double max = -5001;
// Filling array w with random numbers between -5000 and +5000
for (int i=0; i < w.length; ++i)
w[i] = (float)rand.nextDouble() * 10000 - 5000 ;
// TODO: Find min and max
for(int i = 0; i < w.length; i++)
{
if(w[i] < min)
min = w[i];
if(w[i] > max)
max = w[i];  
}
  
System.out.println("Smallest value is " + min);
System.out.println("Largest value is " + max);
}
}

5.3 Lab 5b Due Oct-24 Objectives In this lab you will practice using for loops with arrays and comparing double values, using a threshold, to see if two sets of numbers are the same. Background Reading ZyBooks Chapter 5 Task The first comment of your main method should be your identification comment: //Lab5b, [Name], [mascID] You will need to then: Create and populate the two sets of double values, in which the number of elements and the elements themselves are specified by the user. (i.e. the user will state how many numbers are in the first set, give the values for that set and then move on to the second set of numbers). Iterate through the sets and compare the values. For the purposes of this lab, we will say that the order matters in determining if the sets are the same. (HINT: This also means that the lengths of the arrays must be the same) If the arrays are the same in both length and values, print set one and set two are equal. Otherwise, print set one and set two are not equal · · Comparing double values using a threshold Recall that floating-point numbers may differ in a very small value. For example, 1.0 might actually be stored as 0.9999999... or 1.0000000002. When comparing these values, we often use a tolerance" level that says, "if the difference is smaller than some amount, then it is negligible and the numbers can be thought of as the same. We can achieve this by comparing the absolute value of the difference of the elements to the tolerance. For example, if Math.abs( arrayl [0]array210]> 0.001 System.out.println ("The values of arrayl [0] and array2 10] are not equal" LAB ACTIVITY 5.3.1: Lab 5b Due Oct-24 0/12

Explanation / Answer

Please find my implementation.

/**

* Lab 5a

* To pracic various array skills such as initializing, setting individual values, summing, copying, and displaying

* 107-2

* 24-Oct-2017

* @author

*/

import java.util.*;

public class Lab5a {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter size of first set of double values: ");

       int n1 = sc.nextInt();

       float[] set1 = new float[n1];

       System.out.println("Enter "+n1+" float values: ");

       for(int i=0; i<n1; i++)

           set1[i] = sc.nextFloat();

       System.out.print("Enter size of second set of double values: ");

       int n2 = sc.nextInt();

       float[] set2 = new float[n2];

       System.out.println("Enter "+n2+" float values: ");

       for(int i=0; i<n2; i++)

           set1[i] = sc.nextFloat();

       sc.close();

       if(n1 != n2) {

           System.out.println("set one and set two are not equal");

       }else{

           // creating boolean value

           boolean[] flag = new boolean[n1];

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

               for(int j=0; j<n2; j++) {

                   if((Math.abs(set1[i] - set2[j]) <= 0.001) && flag[j] != true) {

                       flag[j] = true; // this element has matched with set 1

                       break;

                   }

               }

           }

           // check all the flag values

           int i = 0;

           while(i<n1) {

               if(flag[i] == false) {

                   break;

               }

               i++;

           }

           if(i == n1) {

               System.out.println("set one and set two are equal");

           }else{

               System.out.println("set one and set two are not equal");

           }

       }

   }

}

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