
import java.util.*;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
//For taking inputs
Scanner in = new Scanner(System.in);
ArrayList<Integer> daysEntered = new ArrayList<Integer>();
// For storing dangerous reading value
int dangerous;
// Ask and input the reading that is considered dangerous
System.out.print("Enter dangerous reading: ");
dangerous = in.nextInt();
// To write in file
FileWriter myWriter = new FileWriter("report.txt");
// To store day of the month
int day = 1;
// To store the three readings in a day
int first_reading, second_reading, third_reading;
// Loops until user input 0 as day
while(day != 31) {
// Ask and input day of the month
System.out.print("Enter day of the month ( 1 to 31 ): ");
day = in.nextInt();
// If readings for the entered day has already entered
if(daysEntered.contains(day)) {
System.out.println("Readings for this day has already been entered. ");
}
// Else
else {
daysEntered.add(day);
// If day entered is valid
if(day >= 1 && day <= 31) {
// Ask and input three daily readings
System.out.println("Enter the three readings: ");
first_reading = in.nextInt();
second_reading = in.nextInt();
third_reading = in.nextInt();
// Find the peak flow reading of the day
int maximum_reading = Math.max(Math.max(first_reading, second_reading), third_reading);
// If peak flow reading is below dangerous reading
if(maximum_reading < dangerous) {
// Tell user he/she needs to go to hospital
System.out.println("--- You need to go to hospital immediately ---");
}
// Write the day and peak flow reading in a file separated with comma (CSV)
myWriter.write(day+","+maximum_reading+"\n");
}
}
}
// Close myWriter
myWriter.close();
}
}
Explain briefly in your own words (separately from the code, in the box provided) how one important method of your

Step by stepSolved in 3 steps with 2 images

- import java.util.Arrays; import java.util.Random; public class Board { /** * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. That some of the possible moves * don't actually change what the board looks like. * * @param moves the number of moves to make when generating the board. */ public Board(int moves) { throw new RuntimeException("Not implemented"); } The board is 5 X 5. You can add classes and imports like rand.arrow_forward*JAVA* complete method Delete the largest valueremoveMax(); Delete the smallest valueremoveMin(); class BinarHeap<T> { int root; static int[] arr; static int size; public BinarHeap() { arr = new int[50]; size = 0; } public void insert(int val) { arr[++size] = val; bubbleUP(size); } public void bubbleUP(int i) { int parent = (i) / 2; while (i > 1 && arr[parent] > arr[i]) { int temp = arr[parent]; arr[parent] = arr[i]; arr[i] = temp; i = parent; } } public int retMin() { return arr[1]; } public void removeMin() { } public void removeMax() { } public void print() { for (int i = 0; i <= size; i++) { System.out.print( arr[i] + " "); } }} public class BinarH { public static void main(String[] args) { BinarHeap Heap1 = new BinarHeap();…arrow_forwardI need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forward
- Correct my codes in java // Arraysimport java.util.Scanner;public class Assignment1 {public static void main (String args[]){Scanner sc=new Scanner (System.in);System.out.println("Enter mark of student");int n=sc.nextInt();int a[]=new int [n];int i;for(i=0;i<n;i++){System.out.println("Total marks of student in smster");a[i]=sc.nextInt();}int sum=0;for(i=0;i<n;i++){sum=sum+a[i];}System.out.println("Total marks is :");for (i=0;i<n;i++);{System.out.println(a[i]);}System.out.println();}}arrow_forwardMethods Details: public static java.lang.StringBuffer[] getArrayStringsLongerThan(java.lang.StringBuffer[] array, int length) Returns a StringBuffer array with COPIES of StringBuffer objects in the array parameter that have a length greater than the length parameter. If no strings are found an empty array will be returned. Parameters: array - length - Returns: Throws:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardpublic class arrayOutput ( public static void main (String [] args) { final int NUM ELEMENTS = 3; int[] userVals = new int [NUM_ELEMENTS]; int i; } Type the program's output userVals [0] = 2; userVals [1] = 6; userVals [2] = 8; for (i = userVals.length - 1; i >= 0; −−1) { System.out.println(userVals [1]); } C.C. ? ? ??arrow_forward
- Write in Java What is this program's exact outputarrow_forwardMy issue: I don't know how to shift left after swapping arrays. My code: import java.util.Scanner;public class StudentScores {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int SCORES_SIZE = 4;int[] oldScores = new int[SCORES_SIZE];int[] newScores = new int[SCORES_SIZE];int i; for (i = 0; i < oldScores.length; ++i) {oldScores[i] = scnr.nextInt();} /* Your solution goes here */for (i=0; i < oldScores.length; i++) {newScores[i]= oldScores[i];}// student code ends here for (i = 0; i < newScores.length; ++i) {System.out.print(newScores[i] + " ");}System.out.println();}}arrow_forwardpackage lab06;;public class gradereport { public static void main(String[] args) { Scanner in = new Scanner(System.in);double[] Scores = new double[10]; for(int i=0;i<10;i++){ System.out.println("Enter score " + (i+1));scores[i]=in.nextdouble(); } for(int i=0;i<10;i++){ if (scores[i] >=80) System.out.println("Score " + (i+1) + " receives a grade of HD"); else if (scores[i]>=70) System.out.println("Score " + (i+1) + " receives a grade of D"); else if (scores[i] >=60) System.out.println("Score "+ (i+1) + " receives a grade of C"); else if (scores[i] >=50) System.out.println("Score " + (i+1) + " receives a grade of P"); else if (scores[i] >=40) System.out.println("Score " + (i+1) + " receives a grade of MF"); else if (scores[i] >=0) System.out.println("Score " +…arrow_forward
- JavaTimer.java: import java.util.Arrays;import java.util.Random; public class JavaTimer { // Please expand method main() to meet the requirements.// You have the following sorting methods available:// insertionSort(int[] a);// selectionSort(int[] a);// mergeSort(int[] a);// quickSort(int[] a);// The array will be in sorted order after the routines are called!// Be sure to re-randomize the array after each sort.public static void main(String[] args) {// Create and initialize arraysint[] a = {1, 3, 5}, b, c, d;// Check the time to sort array along startTime = System.nanoTime();quickSort(a);long endTime = System.nanoTime();long duration = (endTime - startTime) / 1000l;// Output resultsSystem.out.println("Working on an array of length " + a.length + ".");System.out.println("Quick sort: " + duration + "us.");}// Thanks to https://www.javatpoint.com/insertion-sort-in-javapublic static void insertionSort(int array[]) {int n = array.length;for (int j = 1; j < n; j++) {int key = array[j];int…arrow_forwardimport java.awt.*; public class TestRectangle {public static void main(String[] args) {Rectangle r1 = new Rectangle(5, 4, 10, 17);Rectangle r2 = new Rectangle(10, 10, 20, 3);Rectangle r3 = new Rectangle(0, 1, 12, 15);Rectangle r4 = new Rectangle(10, 10, 20, 3);System.out.println("r1 = " + r1);System.out.println("r2 = " + r2);System.out.println("r3 = " + r3);System.out.println("r2 equals r1? " + r2.equals(r1));System.out.println("r2 equals r2? " + r2.equals(r2));System.out.println("r2 equals r3? " + r2.equals(r3));System.out.println("r2 equals r4? " + r2.equals(r4)); System.out.println("r1 contains (6, 8)? = " + r1.contains(6, 8));System.out.println("r2 contains (6, 8)? = " + r2.contains(6, 8));System.out.println("r3 contains (6, 8)? = " + r3.contains(6, 8));System.out.println("r2 contains (30, 13)? = " + r2.contains(30, 13)); r1.intersect(r3);r2.intersect(r4);System.out.println("r1 intersect r3 = " + r1);System.out.println("r2 intersect r4 = " + r2);…arrow_forwardimport java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int n = scnr.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scnr.nextInt(); } for (int i = n - 1; i >= 0; i--) { System.out.print(arr[i]); if (i > 0) { System.out.print(","); } } }}arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





