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

Problem #2: Fun with Flies (40 points) Create a Driver program which: . Reads in

ID: 3710836 • Letter: P

Question

Problem #2: Fun with Flies (40 points) Create a Driver program which: . Reads in the data from a file called: numbers.txt The numbers from the file should be stored into an ArrayList... A sample version of this file has been provided, but the one belng tested with may have between 1 and 10000 numbers. . Count every number in the ArrayList greater than 50 and every number in the ArrayList "less than or equal to" 50 (must . Count every true and every false in the array (must have loop that goes through the array to receive full credit); you . Print the ratio of trues to falses (true counter / false counter) [MUST BE A DOUBLEJ and the ratio of numbers greater than Generate 1000 random boolean values. These numbers should be stored in an array. have loop that goes through the ArrayList to receive full credit); you should have TWO counters for this! should have TWO counters for this! 50 to the numbers "less than or equal to" s0 [MUST BE A DOUBLE]. Also printthe EXACT correct message from below: o If both ratios are greater than 5, print The Truth is Strong o If both ratios are below .5, print "The Truth is Weak" o In all other cases, print "There is much Gray" Grading Breakdown: 8 Reading data into the ArrayList correctly and completely 8-Correctly and completely generating numbers in the correct range and storing those numbers in an array 8-Correctly and completely using a loop to determine the ratio requested using the ArrayLi . Correctly and completely using a loop to determine the ratio requested using the array 8 -Correctly and completely providing the required output of the program Problem #3: Houses (40 Points) For this problem, you will be creating a derived class one to test with. A UML diagram for this problem has been provided to assist you. House Class: , base class and an interface. No Driver is required, but I have attached . Attribute: o Number of Windows

Explanation / Answer

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

public class FunWithFiles {

   // Declare Array List of 1000 elements
   static ArrayList<Integer> numbers = new ArrayList<>(1000);

   static Boolean[] values = new Boolean[1000];

   /**
   * @param args
   */
   public static void main(String[] args) {

       // Fill Array With File Data
       // First Read the File , parse and Add each number to Array list
       readFile();

       fillArray();

       // Count numbers
       int count1 = 0, count2 = 0;

       for (Integer number : numbers) {
           if (number !=null && number > 50) {
               count1++;
           } else {
               count2++;
           }
       }

       // count booleans
       int countBoolean1 = 0, countBoolean2 = 0;

       for (Boolean value : values) {
           if (value) {
               countBoolean1++;
           } else {
               countBoolean2++;
           }

       }
      
       double ratio1=countBoolean1/countBoolean2;
       double ratio2=count1/count2;
       //Print Ratio
       System.out.println("ratio of True and False Is : "+ratio1);
       System.out.println("Ratio of Numbers>50 and Numbers<50 is = "+ratio2);
      
      
      
       if(ratio1>0.5 && ratio2>0.5)
       {
           System.out.println("The Truth is Strong ");
       }
      

       else if(ratio1<0.5 && ratio2<0.5)
       {
           System.out.println("The Truth is Weak ");
       }
       else
       {
           System.out.println("There is much Grey....");
       }
   }

   // Read the file
   private static void readFile() {
       try {
           Scanner sc = new Scanner(new File("./numbers.txt"));
           while (sc.hasNextLine()) {
               Integer number = Integer.parseInt(sc.nextLine());
               numbers.add(number);
           }
       } catch (FileNotFoundException e) {
           System.out.println("File Not Found");
       }
   }

   // generate random booleans and fill in the array
   public static void fillArray() {
       for (int i = 0; i < 1000; i++) {
           values[i] = Math.random() > 0.5;
       }
   }

}

Output:

The Truth is Weak

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