Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Learning Objectives 1. Program runs successfully for up to 20 patients a. Inputs

ID: 3739045 • Letter: L

Question

Learning Objectives 1. Program runs successfully for up to 20 patients a. Inputs Influenza Type from the user using a Scanner object. b. Inputs patient age from the user using a Scanner object c. Repeats until x is entered d. Outputs all of the data input, correctly sorted by age e. Correctly outputs summary even if no patients are input 2. Program contents follow readablity standards including Correctly use the "Prime the Read" method for inputting data before a sentinel loop. a. Note: You may not use any break or continue statements in your program i. b. Successfully write and use a method outside of the main method c. Correct variable types with Useful, Camel-case identifiers and proper tabbing d. Document your code with at least 5 helpful comments Put comments above the lines of code they are documenting, not to the right. i. Summary We will create a very basic version of the FluView application that the CDC provides to track current Influenza activity by age. To use the actual EluView application, click here: Details Your program will need to start by asking which type of Influenza the patient then asking for the age of the patient. This will repeat until the user presses x to exit. You will need to store the types and ages in two different arrays, which will only need to hold up to 20 patient's data. Once all of the data is entered, you will sort the data by age, preserving the name/age pairs as they were input. You will then print out all of the information you gathered. Below is what a full run of the program looks like: (Items in green/underline are the user inputs. Your program should not print these items)

Explanation / Answer

Try code below:

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Main

{

static class pair{

String name;

int age;

}

public static Comparator<pair> comp=new Comparator<pair>(){

@Override

public int compare(pair p1,pair p2){

return p1.age-p2.age;

}

};

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

Scanner inp = new Scanner(System.in);

ArrayList<pair> flu = new ArrayList<pair>();

System.out.println("Welcome to flu tracker!!! ");

while(true)

{

System.out.println("Type the name of the influenza type (x to exit)");

String name = inp.next();

if(name.equals("x"))

{

if(flu.size() == 0)

{

System.out.println("There were: 0 cases of flu to be summarized");

}

else

{

Collections.sort(flu,comp);

for(int i=0;i<flu.size();i++)

{

System.out.println(flu.get(i).name+" "+flu.get(i).age);

}

}

break;

}

else// add data

{

pair p=new pair();

p.name= name;

System.out.println("What is the age of patient? ");

int age = inp.nextInt();

p.age = age;

flu.add(p);

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote