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

Billing Record With Exception 1. The following Person, Patient, Doctor and Billi

ID: 3711283 • Letter: B

Question

Billing Record With Exception

1. The following Person, Patient, Doctor and Billing Classes are given. A possible sample output is also given. By using the given classes, create a Main Class that will output the possible sample output. Include an appropriate amount of try/catch blocks necessary in order to handle exceptions. Do not modify the Person, Patient, Doctor and Billing Classes. Only the Main Class needs to be created. (Tip: Follow the comment blocks in the Main Class).  

Main Class:

Person Class:

Patient Class:

Doctor Class:

Billing Class:

Sample Output:

Enter number of doctors in the facility: 2

Enter number of patients in the facility: 5

-----------------------------

Create Doctor Array:

-----------------------------

Doctor 1

Enter doctor's name: Garry Allen

Enter Specialty: Family Medicine

Enter office visit fee: 180.65

Doctor 2

Enter doctor's name: Sarah Adler

Enter Specialty: Cardiology

Enter office visit fee: 540.98

-----------------------------

Create Patient Array:

-----------------------------

Patient 0

Enter Patient's name: Bruce Ammar

Enter Patient ID: 1234

Patient 1

Enter Patient's name: Mike Anderson

Enter Patient ID: 2345

Patient 2

Enter Patient's name: Jenna Baily

Enter Patient ID: 5678

Patient 3

Enter Patient's name: Mark Kapur

Enter Patient ID: 6789

Patient 4

Enter Patient's name: Lilian Snyder

Enter Patient ID: 7890

Enter Patient index: 0

Enter Doctor index: 0

Do you want to set another appointment? (y/n)y

Enter Patient index: 0

Enter Doctor index: 1

Do you want to set another appointment? (y/n)y

Enter Patient index: 3

Enter Doctor index: 0

Do you want to set another appointment? (y/n)y

Enter Patient index: 4

Enter Doctor index: 1

Do you want to set another appointment? (y/n)y

Enter Patient index: 2

Enter Doctor index: 0

Do you want to set another appointment? (y/n)y

Enter Patient index: 1

Enter Doctor index: 1

Do you want to set another appointment? (y/n)n

Name Garry Allen

Specialty Family Medicine

Office Visit Fee $180.65

Total Income $541.95

------------------------------------

Name Sarah Adler

Specialty Cardiology

Office Visit Fee $540.98

Total Income $1622.94

------------------------------------

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


import java.util.Scanner;

public class BillingRecordException {

public static void main(String[] args) {
  
int numDoc = 0, numPat = 0;
Scanner keyboard = new Scanner(System.in);

//1 - prompt user to enter length of docArray (numDoc) and patArray (numPat) - Exception
System.out.print("Enter number of doctors in the facility: ");
numDoc = keyboard.nextInt();

  
System.out.print("Enter number of patients in the facility: ");
numPat = keyboard.nextInt();

//2- create Doctor array and Patient array
Doctor[] docArray = new Doctor[numDoc];
Patient[] patArray = new Patient[numPat];
  
//3 - create each element of these two arrays
System.out.println("-----------------------------");
System.out.println("Create Doctor Array:");
System.out.println("-----------------------------");

  
//loop
for(int i = 0; i < numDoc; i++)
{
keyboard.nextLine(); //get rid of newline

System.out.println("Doctor " + (i+1));
// prompt user: name, specialty, fee - controling statement and exception
System.out.print("Enter doctor's name: ");
String name = keyboard.nextLine();
System.out.print("Enter Specialty: ");
String speciality = keyboard.nextLine();
System.out.print("Enter office visit fee: ");
double fee = keyboard.nextDouble();


// create a Doctor object
docArray[i] = new Doctor(name, speciality, fee);
}
  
  
//4- loop
System.out.println("-----------------------------");
System.out.println("Create Patient Array:");
System.out.println("-----------------------------");

for(int i = 0; i < numPat; i++)
{
keyboard.nextLine(); //get rid of newline
System.out.println("Patient " + i);
System.out.print("Enter Patient's name: ");
String name = keyboard.nextLine();
System.out.print("Enter Patient ID: ");
int id = keyboard.nextInt();
patArray[i] = new Patient(name, id);
}
  
// prompt user for doctor and patient index - exception
int dIdx, pIdx;
  
String ans;
do
{
System.out.print("Enter Patient index: ");
pIdx = keyboard.nextInt();
System.out.print("Enter Doctor index: ");
dIdx = keyboard.nextInt();
// create a Billing object
Billing bill = new Billing(docArray[dIdx], patArray[pIdx]);
// prompt user
System.out.print("Do you want to set another appointment? (y/n): ");
ans = keyboard.next();
}while(ans.equalsIgnoreCase("y"));
  
//5 - display method Doctor class
System.out.println();
for(int i = 0; i < numDoc; i++)
docArray[i].display();

}

}


output
------
Enter number of doctors in the facility: 2
Enter number of patients in the facility: 5
-----------------------------
Create Doctor Array:
-----------------------------
Doctor 1
Enter doctor's name: Garry Allen
Enter Specialty: Family Medicine
Enter office visit fee: 180.65
Doctor 2
Enter doctor's name: Sarh Adler
Enter Specialty: Cardiology
Enter office visit fee: 540.98
-----------------------------
Create Patient Array:
-----------------------------
Patient 0
Enter Patient's name: Bruce Ammar
Enter Patient ID: 1234
Patient 1
Enter Patient's name: Mike Anderson
Enter Patient ID: 2345
Patient 2
Enter Patient's name: Jenna Baily
Enter Patient ID: 5678
Patient 3
Enter Patient's name: Mark Kapur
Enter Patient ID: 6789
Patient 4
Enter Patient's name: Lilian Snyder
Enter Patient ID: 7890
Enter Patient index: 0
Enter Doctor index: 0
Do you want to set another appointment? (y/n): y
Enter Patient index: 0
Enter Doctor index: 1
Do you want to set another appointment? (y/n): y
Enter Patient index: 3
Enter Doctor index: 0
Do you want to set another appointment? (y/n): y
Enter Patient index: 4
Enter Doctor index: 1
Do you want to set another appointment? (y/n): y
Enter Patient index: 2
Enter Doctor index: 0
Do you want to set another appointment? (y/n): y
Enter Patient index: 1
Enter Doctor index: 1
Do you want to set another appointment? (y/n): n

Name Garry Allen
Specialty Family Medicine
Office Visit Fee $180.65
Total Income $541.95
------------------------------------
Name Sarh Adler
Specialty Cardiology
Office Visit Fee $540.98
Total Income $1622.94
------------------------------------