Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with correct indentation for this JAVA Code. Thanks so much... //First function getMax() will get the max count per minute. //Second function

Please help me with correct indentation for this JAVA Code. 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);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions