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

So I am trying to complete this Java project but i am stuck. Here is my code - -

ID: 3769355 • Letter: S

Question

So I am trying to complete this Java project but i am stuck. Here is my code -

-----

import java.util.*;
import java.io.*;

public class FinalExam
{
    public static void main(String[] args) throws FileNotFoundException
{
        int scores;
       
       
        int[] scoreLimit = {24, 49, 74, 99, 124, 149, 174, 200};
        int[] inRange = {0, 0, 0, 0, 0, 0, 0, 0};
       
        Scanner inFile = new Scanner(new FileReader("data.txt"));

       
        while(inFile.hasNext())
{
            scores = inFile.nextInt();
                   
            for(int i = 0; i < scoreLimit.length; i++)
{
                if(scores <= scoreLimit[i])
{
                    inRange[i] = inRange[i] + 1;
                    break;
}
}
           
}
       
        for (int i = 0; i < scoreLimit.length; i++)
{
            System.out.println("Scores stored in range " + scoreLimit[i] + " is " + inRange[i]);
            System.out.println();
}
}
}

My Output is

Scores stored in range 24 is 1

Scores stored in range 49 is 2

Scores stored in range 74 is 0

Scores stored in range 99 is 6

Scores stored in range 124 is 1

Scores stored in range 149 is 3

Scores stored in range 174 is 5

Scores stored in range 200 is 8

--

*** HOW DO I GET IT TO SAY FOR EXAMPLE "Scores stored in range 0-24" instead of "Scores stored in range 24"

Explanation / Answer

I have printed your program as it is after commenting it.

After that you will see some text that you have to read and then you will find the modified program.

As desired by you, you will find the output.

import java.util.*;
import java.io.*;
public class FinalExam
{
public static void main(String[] args) throws FileNotFoundException
{
int scores;


int[] scoreLimit = {24, 49, 74, 99, 124, 149, 174, 200};
int[] inRange = {0, 0, 0, 0, 0, 0, 0, 0};

Scanner inFile = new Scanner(new FileReader("data.txt"));


while(inFile.hasNext())
{
scores = inFile.nextInt();

for(int i = 0; i < scoreLimit.length; i++)
{
if(scores <= scoreLimit[i]) // here you are checking the score with the range.
{
inRange[i] = inRange[i] + 1;
break;
}
}

}

for (int i = 0; i < scoreLimit.length; i++)
{   
System.out.println("Scores stored in range " + scoreLimit[i] + " is " + inRange[i]);
System.out.println();
}
}
}

You are checking the range where I commented.
In fact you are checking the range from 0-24, 25-49,50-74,75-99,100-124,125-149,150-174 and 175-200.
But you are printing only the upper range as scores stored in range 24.
The following program prints the entire range as output.
import java.util.*;
import java.io.*;
public class FinalExam
{
public static void main(String[] args) throws FileNotFoundException
{
int scores;


int[] scoreLimit = {24, 49, 74, 99, 124, 149, 174, 200}; // line 1.
int[] inRange = {0, 0, 0, 0, 0, 0, 0, 0}; // line 2.
int lolimit=0;

Scanner inFile = new Scanner(new FileReader("data.txt"));


while(inFile.hasNext())
{
scores = inFile.nextInt();

for(int i = 0; i < scoreLimit.length; i++)
{
if(scores <= scoreLimit[i]) // here you are checking the score with the range.
{
inRange[i] = inRange[i] + 1;
break;
}
}

}

for (int i = 0; i < scoreLimit.length; i++)
{   

System.out.println("Scores stored in range " + lolimit + " to " + scoreLimit[i]+ " is " + inRange[i]);

// The above line is changed to get your output as desired.
lolimit = lolimit + 25;
System.out.println();
}
}
}

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