Java Console Application For Recovering COVID-19

Assignment task

Write a java console application for calculating the chance of recovering from COVID-19 based on age and past statistics about COVID-19 recoveries and deaths. The example data statistics such as age range, age group, number of patients, number of recovered patients, and number of deaths are shown below in Table 1.

The application should ask the user to enter the age for each patient and calculate the chance of recovering in percentage and age group for each patient. The application should run for N times (N is number of patients). N should be declared as a constant and it should be equal to the largest digit of your student ID number (e.g. if your ID number is S334517 then N should be equal to 7 and you can declare it as final int N=7). The application should display the chance to recover (e.g. (recovered patients/patients) * 100) and age group for each patient as shown in the example below. At the end of the Nth patient, the details such as age of youngest patient, age of oldest patient and average age of all patients should be displayed.

Output Formate:

Example for N=6

Enter the age for patient 1: 29

The chance to recover for patient 1 is 99.98%

The age group for patient 1 is 1

Enter the age for patient 2: 61

The chance to recover for patient 2 is 98.83%

The age group for patient 2 is 3

Enter the age for patient 3: 55

The chance to recover for patient 3 is 99.84%

The age group for patient 3 is 2

Enter the age for patient 4: 86

The chance to recover for patient 4 is 80.52%

The age group for patient 4 is 5

Enter the age for patient 5: 73

The chance to recover for patient 5 is 95.57%

The age group for patient 5 is 4

Enter the age for patient 6: 94

The chance to recover for patient 6 is 16.00%

The age group for patient 6 is 6

Code Script:

package com.myfirstprogramme;

//import java.util.Scanner;

public class Patient {

	// instance variable/constant declarations
	private int patientAge;
	private int ageGroup=0;
	private int patients=0;
	private int recoveredPatients =0;
	private int youngestPatientAge;
	private int oldestPatientAge;
	private int avgAge=0;
	public Patient(int patientAge,int youngestPatientAge, int oldestPatientAge,int avgAge)
	// constructor to initialize the values of private variables
		this.patientAge= patientAge;
		this.youngestPatientAge= youngestPatientAge;
		this.avgAge = avgAge;
	// under the patientGroup method comapre agegroup
	public void patientGroup() {
		if (0 < patientAge && patientAge<=49) {
		}else if (50<=patientAge && patientAge<=59) {
		}else if (60<=patientAge && patientAge<=69) {
		}else if (70<=patientAge && patientAge<=79) {
		}else if (80<=patientAge && patientAge<=89) {
		}else if (patientAge>=90) {
	//Method patientChanceToRecover
	public double patientChanceToRecover()
	// code to calculate chance to recover using following formula
	// chance to recover (%) = (recovered patients/patients for that age group in Table 1) * 100
		double chanceToRecover= ((double)recoveredPatients/(double)patients)*100;
		return chanceToRecover;
	//under  prepareReport method comparing youngest age and oldest age
	public void prepareReport(){
		if (youngestPatientAge>patientAge) {
		if (oldestPatientAge<patientAge) {
		avgAge = avgAge+patientAge;
	//getters to get the values of private vriables
	public int getRecoveredPatients() {
		return recoveredPatients;
	public int getYoungestPatientAge() {
		return youngestPatientAge;
	public int getOldestPatientAge() {
		return oldestPatientAge;
	public int getAvgAge() {
		return avgAge;
	public int getPatientAge() {
		return patientAge;
	public int getAgeGroup() {
		return ageGroup;
	public int getPatients() {
		return patients;

package com.myfirstprogramme;

import java.util.Scanner;

public class PatientTest {

	public static void main(String[] args) {
		//Variables used in the application
	    final int noOfPatients;
		int patientAge=0;
		Patient patient=null;
		int youngestPatientAge =99999;
		int oldestPatientAge =0;
		int avgAge=0;

		System.out.println("Welcome To COVID-19 Patient Data");
		Scanner sc = new Scanner(;
		System.out.print("Please enter the number of patients ");
		for (int i = 1; i <=noOfPatients; i++) {
			System.out.print("Please Enter the age of Patient "+ i +" ");
			patientAge = sc.nextInt();
			patient =new Patient(patientAge,youngestPatientAge,oldestPatientAge,avgAge);
			System.out.println("The chance to recover for patient "+ i +" is "+ patient.patientChanceToRecover());
			System.out.println("The age group for patient "+ i +" is " + patient.getAgeGroup());
			youngestPatientAge = patient.getYoungestPatientAge();
			oldestPatientAge= patient.getOldestPatientAge();
			avgAge= patient.getAvgAge();
		System.out.println("Age of youngest patient: "+ patient.getYoungestPatientAge());
		System.out.println("Age of oldest patient: "+ patient.getOldestPatientAge());
		System.out.println("Average age of all patients: "+ (double)patient.getAvgAge()/noOfPatients);
		System.out.println("Exiting the application");
		//closing resources


Are you looking for Java Web and console-based Programming experts to solve your assignment, homework, coursework, coding, and projects? Codersarts web developer experts and programmers offer the best quality Java web and console-based Programming programming, coding or web programming experts. Get Web Assignment Help at an affordable price from the best professional experts Assignment Help. Order now at get 15% off. CONTACT US NOW

7 views0 comments