JAVA This should be easy I have this data.txt: 4 40 80 52 41 72 61 71 60 50 52 61 77 41 61 70 79 41 67 60 50 61 76 and this code:   // THIS IS THE ONE YOU ARE LOOKING FORE import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner; //https://www.chegg.com/homework-help/questions-and-answers/program-1-histogram-takes-integer-n-two-integers-left-right-uses-stddraw-plot-histogram-co-q30777519?trackid=e3045eb02494&strackid=cc33c4210bce&ii=1// D:/documents/TESU/000_courses/COS-111 Intro to Programming (-OL009)/eclipse-workspace/COS_111/src/data.txt   public class zzz{ public static void main(String[] args) throws FileNotFoundException{ File file = new File("D:\\documents\\TESU\\000_courses\\COS-111 Intro to Programming (-OL009)\\eclipse-workspace\\COS_111\\src\\data.txt");Scanner scanner = new Scanner(file);// get the first 3 conditions// n = categoriseint n = scanner.nextInt();int left = scanner.nextInt();int right = scanner.nextInt();// find catigories// count storse number of values in each categor7int[] counts = new int[n]; // what are the categoriesdouble intervalWidth = (double)(right-left) / n;// find the bounds// get left most value// for each category// increment leftdouble[] bounds = new double [n+1];for (int i=0; i<= n;i++) {bounds[i]=left+intervalWidth*i;} // while has next int // depending on n// check if there is another integer// if integerwhile(scanner.hasNextInt()){// store that int as tempint temp = scanner.nextInt(); // check the bounds against tempfor (int i = 0;i<=bounds.length;i++) {// if temp is within bounds add to that countif (bounds[i]<temp && temp < bounds[i+1]) {// found out where temp belongs and add it to it's countcounts[i]++;}break;}}for (int i = 0; i < counts.length ; i++) {System.out.println(counts[i]);} }}   my output is: 3000 I need it to be: 3476 more explanation: reads integers from a file and puts them into categories 40-50,50-60,..etc to 80 each count[] should have the value of however many integers fit within these categories possible problems I think the problem is my for loop section. thank you!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

JAVA

This should be easy

I have this data.txt:

4 40 80

52 41 72 61

71 60 50 52 61

77 41 61 70 79 41

67 60 50 61 76

and this code:

 


// THIS IS THE ONE YOU ARE LOOKING FORE

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

//https://www.chegg.com/homework-help/questions-and-answers/program-1-histogram-takes-integer-n-two-integers-left-right-uses-stddraw-plot-histogram-co-q30777519?trackid=e3045eb02494&strackid=cc33c4210bce&ii=1
// D:/documents/TESU/000_courses/COS-111 Intro to Programming (-OL009)/eclipse-workspace/COS_111/src/data.txt

 

public class zzz
{

public static void main(String[] args) throws FileNotFoundException
{
File file = new File("D:\\documents\\TESU\\000_courses\\COS-111 Intro to Programming (-OL009)\\eclipse-workspace\\COS_111\\src\\data.txt");
Scanner scanner = new Scanner(file);

// get the first 3 conditions
// n = categorise
int n = scanner.nextInt();
int left = scanner.nextInt();
int right = scanner.nextInt();


// find catigories
// count storse number of values in each categor7
int[] counts = new int[n];
// what are the categories
double intervalWidth = (double)(right-left) / n;
// find the bounds
// get left most value
// for each category
// increment left
double[] bounds = new double [n+1];
for (int i=0; i<= n;i++) {
bounds[i]=left+intervalWidth*i;
}



// while has next int
// depending on n

// check if there is another integer
// if integer
while(scanner.hasNextInt())
{
// store that int as temp
int temp = scanner.nextInt();

// check the bounds against temp
for (int i = 0;i<=bounds.length;i++) {
// if temp is within bounds add to that count
if (bounds[i]<temp && temp < bounds[i+1]) {
// found out where temp belongs and add it to it's count
counts[i]++;}

break;
}

}
for (int i = 0; i < counts.length ; i++) {
System.out.println(counts[i]);
}



}
}

 

my output is:

3
0
0
0

I need it to be:

3
4
7
6

more explanation:

reads integers from a file and puts them into categories 40-50,50-60,..etc to 80

each count[] should have the value of however many integers fit within these categories

possible problems

I think the problem is my for loop section.

thank you!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY