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

Modify your program 1 (using this: https://www.chegg.com/homework-help/questions

ID: 3601731 • Letter: M

Question

Modify your program 1 (using this: https://www.chegg.com/homework-help/questions-and-answers/task-write-java-program-reads-processes-four-blood-sugar-test-readings-one-day-program-ask-q24608671) so that it will handle multiple days of blood sugar test readings. Your program #2 should ask the user at runtime to supply the actual number of days’ readings they want to enter in the program for evaluation. In addition to producing the output specified in program 1 for each individual day, program 2 should also output the day (i.e. Day 1, Day 2, etc.) with the highest average blood sugar level, the day with the lowest average blood sugar level, and the overall average blood sugar reading over all days. All output should be displayed with meaningful descriptions. Like program 1, you should validate all numeric input from the user to ensure it falls in an appropriate range of values for the program to work correctly. You are also required to use nested FOR loops for this program.

(hint – This program will require nested FOR loops. The outer loop will control the different days while the inner loop controls the test results for the current day. If you are having trouble understanding nested loops be sure to watch the live classroom from this week or the screen cast on nested loops in the module reading. Both of these work you through an example very similar to this program.)

Program 2 sample execution & output:

How many days of blood sugar test readings would you like to enter: 2

Enter data for day 1
   Enter the blood sugar test reading for test 1: 180
   Enter the blood sugar test reading for test 2: 202
   Enter the blood sugar test reading for test 3: 121
   Enter the blood sugar test reading for test 4: 350

Test Reading 4 had the highest blood sugar level with 350.0 mg/dL
Test Reading 3 had the lowest blood sugar level with 121.0 mg/dL
Your average blood sugar level for today was 213.25 mg/dL

Enter data for day 2
   Enter the blood sugar test reading for test 1: 132
   Enter the blood sugar test reading for test 2: 225
   Enter the blood sugar test reading for test 3: 199
   Enter the blood sugar test reading for test 4: 150

Test Reading 2 had the highest blood sugar level with 225 mg/dL
Test Reading 1 had the lowest blood sugar level with 132 mg/dL
Your average blood sugar level for day 1 was 176.5 mg/dL

Overall Results:

Day 1 had the highest average blood sugar level with 213.25 mg/dL
Day 2 had the lowest average blood sugar level with 176.5 mg/dL

Your average blood sugar over 2 days was 194.875 mg/dL

Explanation / Answer

BloodSugarTest.java

import java.util.Scanner;

public class BloodSugarTest {

public static void main(String[] args) {

//Declaring variables

int noOfDays;

int max=-999,min=999,testReadingMax=-999,testReadingMin=-999;

double avgMinDay,avgMaxDay;

int dayNOMax,dayNOMin;

double daytotal=0.0,dayavg=0.0,overallAvg=0.0,tot=0.0;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("How many days of blood sugar test readings would you like to enter:");

noOfDays=sc.nextInt();

int reading = 0;

avgMinDay=999;

avgMaxDay=-999;

dayNOMax=-999;

dayNOMin=999;

//Creating an double type array which store each day averages

double avgDayReading[]=new double[noOfDays];

for(int i=1;i<=noOfDays;i++)

{

max=-999;

min=999;

testReadingMax=-999;

testReadingMin=999;

daytotal=0.0;

System.out.print("Enter data for day : ");

for(int j=1;j<=4;j++)

{

//Getting the input entered by the user

System.out.print(" Enter the blood sugar test reading for test "+j+":");

reading=sc.nextInt();

//calculating the day min and day max reading

if(testReadingMin>reading)

{

testReadingMin=reading;

min=j;

}

if(testReadingMax<reading)

{

testReadingMax=reading;

max=j;

}

//calculating day total readings

daytotal+=reading;

}

//calculating day average readings

avgDayReading[i-1]=daytotal/4;

//Displaying output

System.out.println("Test Reading "+max+" had the highest blood sugar level with "+testReadingMax+" mg/dL");

System.out.println("Test Reading "+min+" had the lowest blood sugar level with "+testReadingMin+" mg/dL");

System.out.println("Your average blood sugar level for today was "+avgDayReading[i-1]+" mg/dL");

//calculating all days min and max average reading

if(avgMinDay>avgDayReading[i-1])

{

avgMinDay=avgDayReading[i-1];

dayNOMin=i;

}

if(avgMaxDay<avgDayReading[i-1])

{

avgMaxDay=avgDayReading[i-1];

dayNOMax=i;

}

tot+=avgDayReading[i-1];

}

//Displaying the output

System.out.println("Overall Results:");

System.out.println("Day "+dayNOMax+" had the highest average blood sugar level with "+avgMaxDay+"mg/dL");

System.out.println("Day "+dayNOMin+" had the lowest average blood sugar level with "+avgMinDay+"mg/dL");

System.out.println("Your average blood sugar over "+noOfDays+" days was "+tot/noOfDays+"mg/dL");

}

}

_______________

Output:

How many days of blood sugar test readings would you like to enter:2

Enter data for day :

Enter the blood sugar test reading for test 1:180

Enter the blood sugar test reading for test 2:202

Enter the blood sugar test reading for test 3:121

Enter the blood sugar test reading for test 4:350

Test Reading 4 had the highest blood sugar level with 350 mg/dL

Test Reading 3 had the lowest blood sugar level with 121 mg/dL

Your average blood sugar level for today was 213.25 mg/dL

Enter data for day :

Enter the blood sugar test reading for test 1:132

Enter the blood sugar test reading for test 2:225

Enter the blood sugar test reading for test 3:199

Enter the blood sugar test reading for test 4:150

Test Reading 2 had the highest blood sugar level with 225 mg/dL

Test Reading 1 had the lowest blood sugar level with 132 mg/dL

Your average blood sugar level for today was 176.5 mg/dL

Overall Results:

Day 1 had the highest average blood sugar level with 213.25mg/dL

Day 2 had the lowest average blood sugar level with 176.5mg/dL

Your average blood sugar over 2 days was 194.875mg/dL

_____________Could you rate me well.Plz .Thank You

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