Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

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 program answering part i) works. It should be a method specific to this program and not, for example, a generic method provided for you such as a generic input method.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY