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

Please Use Java to answer the following quesiton: For each of the questions you

ID: 3801813 • Letter: P

Question

Please Use Java to answer the following quesiton:

For each of the questions you need to write your approach. Else 50% points will be deducted.

For each of the following, you need to write the program and run the program.

The best way would be to run the program and copy the code in the pdf.

Insert the screen-shot of the output in the pdf file, in which you are writing the program. This carries major points. (30% of the points for each question)

For the question 1,2,4,5 you also need to provide the input files on which you have tested.

2. Write a program that reads a list of speed of runners in a marathon from the file Marathon.txt (which contains the speed of the runner per line) and then displays a histogram of those numbers, divided into the ranges 0–9, 10–19, 20–29, and so forth, up to the range containing only the value 100. If, for example, Marathon.txt contains the data shown as below, your program should then be able to generate a histogram that looks as much as possible like the following:

(A). Input:-10,5,8,7,20,50,45,60,70,75,73,65,17,23,25,26,24

(B). Output:-

0-9 : * * *

10-19: * *

20-29: * * * *

30-39: NULL

And so on…

Explanation / Answer

/* MarathonRace.java */

import java.io.BufferedReader;
import java.io.FileReader;


public class MarathonRace {

   public static void main(String[] args) {
       try{
           FileReader fr = new FileReader("F:\Marathon.txt");
           BufferedReader br = new BufferedReader(fr);
           int counters[] = new int[10];
           for(int i=0;i<counters.length;i++)
               counters[i] = 0;
           String range[] = {"0-9","10-19","20-29","30-39","40-49","50-59","60-69","70-79","80-89","90-100"};
           String line = null;
           while((line = br.readLine())!=null){
               String a[] = line.split(",");
               for(String s : a){
                   int num = Integer.parseInt(s);
                   for(int i=0;i<range.length;i++){
                       String r[] = range[i].split("-");
                       int r1 = Integer.parseInt(r[0]);
                       int r2 = Integer.parseInt(r[1]);
                       if(num>=r1 && num <=r2){
                           counters[i]++;
                           break;
                       }
                   }
               }
           }
           br.close();
           fr.close();
           for(int i=0;i<counters.length-1;i++){
               System.out.print(" "+range[i]+":");
               if(counters[i] == 0)
                   System.out.print("NULL");
               for(int j=0;j<counters[i];j++)
                   System.out.print("* ");
           }
       }
      
       catch(Exception e){
           e.printStackTrace();
       }
   }
}


/* Sample Input and Output */
_______________________

/* Marathon.txt */ (Input )

10,5,8,7,20,50,45,60,70,75,73,65,17,23,25,26,24

/* Sample Output */

0-9:* * *
10-19:* *
20-29:* * * * *
30-39:NULL
40-49:*
50-59:*
60-69:* *
70-79:* * *
80-89:NULL

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