Question: Please help me with correct indentation for this JAVA Code. If you could include a screenshot of the code, it would be a big help.

Please help me with correct indentation for this JAVA Code. If you could include a screenshot of the code, it would be a big help. Thanks so much...

//First function getMax() will get the max count per minute.

//Second function printAllinCountFiveOfMax(int max) takes max as an input parameters and prints all the lines that are within 5 counts of the max counts per minute.

//Code

package com.codility; import java.io.IOException; import java.io.FileReader; import java.io.BufferedReader;

public class RadiationSample {

public static int getMax() {

BufferedReader reader;

int max = 0;

try {

reader = new BufferedReader(new FileReader("C:\\Users\ p055222\\Documents\\RadiationSample.txt"));

String line = reader.readLine();

while (line != null) {

//Split the string by comma delimeter and store the elements in an array

String splitRad[] = line.split(",");

//If the current count is greater than max, update the max to current.

if (max < Integer.parseInt(splitRad[2]))

max = Integer.parseInt(splitRad[2]);

// read next line

line = reader.readLine();

}

reader.close();

} catch (IOException e) {

e.printStackTrace();

}

return max;

}

public static void printAllinCountFiveOfMax(int max) {

BufferedReader reader;

try {

reader = new BufferedReader(new FileReader("C:\\Users\ p055222\\Documents\\RadiationSample.txt"));

String line = reader.readLine();

while (line != null) {

//Split the string by comma delimeter and store the elements in an array

String splitRad[] = line.split(",");

//If the count is within 5 counts of the max, print the line

if (Integer.parseInt(splitRad[2]) + 5 >= max)

System.out.println(line);

// read next line

line = reader.readLine();

}

reader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

int max = getMax();

System.out.println("The max count is : " + max);

printAllinCountFiveOfMax(max);

}

}

//And this is the RadiationSample.txt

public class RadiationSample {

private String dateTime; private int countsPerMinute; public RadiationSample(String dt, int counts) { dateTime = dt; countsPerMinute = counts; } public String getDateTime() { return dateTime; } public int getCountsPerMinute() { return countsPerMinute; } public static void main(String[] args) { RadiationSample sample = new RadiationSample("4/6/2018 17:15",17); System.out.println("Date and Time : " + sample.getDateTime() + " Counts Per Minute: " + sample.getCountsPerMinute()); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!