Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago

Question

=+7 How has the COVID-19 pandemic impacted the operations of IHRM?

Answered: 1 week ago