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

ion: (5 points)Writ a program named ArrayRandom.java. This program defines 10 el

ID: 3843885 • Letter: I

Question

ion:
 (5 points)Writ a program named ArrayRandom.java. This program defines 10 elements integer array, then assign random numbers between 60 and 100 to each of the element, then perform the following tasks: 1. find the smallest number, 2. find the largest number 3. calculate average  Then printout the the three numbers as follows:  The smallest number: 65 The largest number: 99 Average: 85   (5 points)Writ a program named ArrayRandom2.java. This program defines 10 elements integer array, then assign random numbers between 0 and 100 to each of the element, then perform the following tasks: 1. find how many of them are divisible by 3, 2. find how many of them are divisble by 21,   Then printout array elements and the result as follows:  [69, 33, 21, 66, 21, 15, 48, 15, 89, 9]  9 numbers in this array are divisible by 3  2 numbers in this array are divisible by 21   (5 points)Write a program (named Gradebook.java) that reads the final grades for a class. The final grades are saved in a data file. After reading in the data, calculate average grade for the whole class, find the lowest and highest, then printout the 3 numbers in a nice format. A sample data file (gradebook.txt) and output are given for testing purpose.  Data file: 86  89  78  100  76   Sample output:   Average:   87.80   Lowest:    76.00    Highest:  100.00  (5 points)Design a programming named CharDistribution.java, which counts how many times each of the alphabetic characters (convert lower case to upper case) appears in the data file. Then print the result as follows:  A - 65 B - 99 C - 5 D - 0 ... Z - 2 
ion:
  (5 points)Writ a program named ArrayRandom.java. This program defines 10 elements integer array, then assign random numbers between 60 and 100 to each of the element, then perform the following tasks:  1. find the smallest number,  2. find the largest number  3. calculate average    Then printout the the three numbers as follows:    The smallest number: 65  The largest number: 99  Average: 85      (5 points)Writ a program named ArrayRandom2.java. This program defines 10 elements integer array, then assign random numbers between 0 and 100 to each of the element, then perform the following tasks:  1. find how many of them are divisible by 3,  2. find how many of them are divisble by 21,      Then printout array elements and the result as follows:    [69, 33, 21, 66, 21, 15, 48, 15, 89, 9]   9 numbers in this array are divisible by 3   2 numbers in this array are divisible by 21     (5 points)Write a program (named Gradebook.java) that reads the final grades for a class. The final grades are saved in a data file. After reading in the data, calculate average grade for the whole class, find the lowest and highest, then printout the 3 numbers in a nice format. A sample data file (gradebook.txt) and output are given for testing purpose.    Data file:  86  89  78  100  76     Sample output:    Average:   87.80    Lowest:    76.00     Highest:  100.00    (5 points)Design a programming named CharDistribution.java, which counts how many times each of the alphabetic characters (convert lower case to upper case) appears in the data file. Then print the result as follows:    A - 65  B - 99  C - 5  D - 0  ...  Z - 2  

Explanation / Answer

Find the programs below.

1.

import java.util.Random;

public class ArrayRandom {

   public static void main(String[] args) {
       Random r = new Random();
       int[] fiveRandomNumbers = r.ints(10, 60, 100).toArray();
       int small = fiveRandomNumbers[0];
       int big = fiveRandomNumbers[0];
       int sum=0,avg;
       for (int i = 0; i < fiveRandomNumbers.length; i++) {
           if(small > fiveRandomNumbers[i]){
               small = fiveRandomNumbers[i];
           }
           if(big < fiveRandomNumbers[i]){
               big = fiveRandomNumbers[i];
           }
           sum += fiveRandomNumbers[i];
       }
       avg = sum/10;
       System.out.println("The smallest number: " +small);
       System.out.println("The largest number: " +big);
       System.out.println("Average: " +avg);
   }
}

output:

The smallest number: 60
The largest number: 95
Average: 75

2.

import java.util.Random;

public class ArrayRandom2 {

   public static void main(String[] args) {
       Random r = new Random();
       int[] tenRandomNumbers = r.ints(10, 0, 100).toArray();
       int count3=0;
       int count21=0;
       System.out.print("[");
       for (int i = 0; i < tenRandomNumbers.length; i++) {
           if(tenRandomNumbers[i] % 3 == 0){
               count3++;
           }
           if(tenRandomNumbers[i] % 21 == 0){
               count21++;
           }
           System.out.print(tenRandomNumbers[i] + " ");
       }
       System.out.println("]");
       System.out.println(count3 + " numbers in this array are divisible by 3");
       System.out.println(count21 + " numbers in this array are divisible by 21");
   }

}

output:

[18 27 88 92 70 6 91 83 26 12 ]
4 numbers in this array are divisible by 3
0 numbers in this array are divisible by 21

3.

import java.io.File;

import java.io.FileNotFoundException;
import java.util.Scanner;

public class Gradebook {

   public static void main(String[] args) {
       try {
   int[] data = new int[10];
   int i = 0;
   File file = new File("filename");
   Scanner scanner = new Scanner(file);
   while (scanner.hasNextLine()) {
   data[i++] = scanner.nextInt();
   }
   scanner.close();
   int highest = data[0];
   int lowest = data[0];
          int sum=0,avg;
          for (i = 0; i < data.length; i++) {
              if(lowest > data[i]){
                  lowest = data[i];
              }
              if(highest < data[i]){
                  highest = data[i];
              }
              sum += data[i];
          }
          avg = sum/data.length;
          System.out.println("Average:" + avg);
          System.out.println("Lowest: " +lowest);
          System.out.println("Highest: " +highest);
   } catch (FileNotFoundException e) {
   e.printStackTrace();
   }
   }

}

4.

import java.io.File;

import java.io.FileNotFoundException;
import java.util.Scanner;

public class CharDistribution {

   public static void main(String[] args) {
       try {
           String data = null;
           int count;
           String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   File file = new File("fileName");
   Scanner scanner = new Scanner(file);
   while (scanner.hasNextLine()) {
   data = String.join(" ", scanner.nextLine());
   }
   scanner.close();
   String[] arr = alpha.split("(?!^)");
   final int len = arr.length;
   final int dataLen = data.length();
   for (int i = 0; i < len; i++) {
       count = 0;
       String c = arr[i];
       for (int j = 0; j < dataLen; j++) {
           if (c.equalsIgnoreCase(arr[j])) {
               count++;
       }
               }
   System.out.println(c + "-" + count);
   }
   } catch (FileNotFoundException e) {
   e.printStackTrace();
   }
   }

}