Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**I am adding more information for this project: The , delimiter should now be changed to use the ^ delimiter. There needs to be an

**I am adding more information for this project:

The ", delimiter" should now be changed to use the "^ delimiter". There needs to be an 2nd address field added to the original code, as well as, a "plus 4" on the zip code (example: 47408-6606). Then the additional prompts that are in bold *** must be added. Thank you!

Last Real World problem (in module 04 - 05), you added functionality to allow the user to enter multiple patients until the user indicated done. You are to enhance this functionality. Add the following functionality to your report app:

Read the*Attached Text File via your report app. Your app should read this file. If Ithe data within the file (using the exact same format) is changed, the report should read the new data and format the report correctly. As long as the file is in the same format as outlined here:

Each field in this file is delimited by a carat (^)

The fields included in this file are ID^Last Name^First Name^Address Line 1^Address Line 2(optional)^City^State^Zip^ZipPlus4(Optional)^Payment Date^Payment Amount^Amount Owed

The fields marked as optional may not contain data. For example, the format might appear like this:

ID^Last Name^First Name^Address Line 1^^City^State^Zip^^Payment Date^Payment Amount^Amount Owed

When producing the report

Skip those fields that are not part of the report format

Rearrange those fields that are in a different order so they correspond to the report format

***Add a prompt to the user "Do you want to output the report to the screen ('S'), to a file ('F') or both ('B')".

If the user enters 'S' your code should display the report to the screen as it currently does.

Whether the user enters an uppercase or lowercase letter should not matter. For example 'S' or 's' should not matter. In both cases, the user should display the data as described above.

If the user enters "F" (or "f"), then the app should

Prompt the user for the desired file name (including the file path)

Output the report to a file using the file name / path the user entered. This output should be in the exact same format as the report is-if sent to the screen except that it outputs the report to a file.

If the user enters "B" (or "b"), then the app should output the report to both the screen and output it to a file.

*Attached Text File

12345^Jones^John^1234 Test Drive^PO box 123^Test City^IN^11234^1234^12/05/2015^250.00^25000.00

12346^Jones^Sara^1234 Test Drive^PO box 123^Test City^IN^11234^1234^12/20/2017^50.00^50000.00

12347^Doe^John^1235 XYZ Drive^^Test City^IN^11234^^01/05/2016^350.00^56799.00

12348^Doe^Sara^1235 XYZ Drive^^Test City^IN^11234^^11/09/2017^100.00^5020.52

12349^Lawson^Lonnie^12 South Drive^^Test City^IN^11236^^03/15/2013^253.51^25065.52

12349^Anderson^Sara^156 North Avenue^^Test City^IN^11246^^05/05/2013^21.33^251.56

12350^Smith^Andy^2455 East Street^^Test City^IN^11246^^12/05/2017^365.21^2543.33

Here is the original code:

import java.util.Scanner;

import java.util.ArrayList;

import java.util.regex.Pattern;

class Patient {

public String getLast() {

return last;

}

public String getFirst() {

return first;

}

public String getAddress() {

return address;

}

public String getCity() {

return city;

}

public String getState() {

return state;

}

public String getZip() {

return zip;

}

public String getAmount() {

return amount;

}

public String getPayment() {

return payment;

}

public String getDate() {

return date;

}

private String last, first, address, city, state, zip, amount, payment, date;

public Patient (String s1, String s2, String address, String city, String state, String zip, String amount, String payment, String date) {

this.last = s1;

this.first = s2;

this.address = address;

this.city = city;

this.state = state;

this.zip = zip;

this.amount = amount;

this.payment = payment;

this.date = date;

}

}

public class Module04_05 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

char ch;

boolean b;

String s1, s2, address, city, state, zip, amount, payment, date;

ArrayList arr = new ArrayList<>();

do {

do {

System.out.print("Enter last name ");

s1 = input.nextLine();

b = Pattern.matches("[a-zA-Z]+", s1);

if (!b) {

System.out.println("Please enter letters only");

}

}

while (b==false);

do {

System.out.print("Enter first name ");

s2 = input.nextLine();

b = Pattern.matches("[a-zA-Z]+", s2);

if (!b) {

System.out.println("Please enter letters only");

}

}

while (b==false);

System.out.print("Enter address ");

address = input.nextLine();

do {

System.out.print("Enter city ");

city = input.nextLine();

b = Pattern.matches("[a-zA-Z]+", city);

if (!b) {

System.out.println("Please enter letters only");

}

}

while (b==false);

do {

System.out.print("Enter state ");

state = input.nextLine();

b = Pattern.matches("[a-zA-Z]+", state);

if (!b) {

System.out.println("Please enter letters only");

}

}

while (b==false);

do {

System.out.print("Enter zip ");

zip = input.nextLine();

if (zip.length()==5 && Pattern.matches("[0-9]+", zip)) {

b = true;

}

else {

System.out.println("Must be 5 digits long and must be digits only");

b=false;

}

}

while (b==false);

do {

System.out.print("Enter amount owed ");

amount = input.nextLine();

if (Pattern.matches("[0-9]+", amount))

b = true;

else {

System.out.println("Please enter digits only");

b = false;

}

}

while (b==false);

do {

System.out.print("Enter payment amount ");

payment = input.nextLine();

if (Pattern.matches("[0-9]+", payment))

b = true;

else {

System.out.println("Please enter digits only");

b = false;

}

}

while (b==false);

System.out.print("Enter payment date in the format 'dd/mm/yyyy'");

date = input.nextLine();

Patient p = new Patient (s1,s2,address,city,state,zip,amount,payment,date);

arr.add(p);

System.out.println("Any more entries? Click y for Yes or n for No");

ch = input.nextLine().charAt(0);

}

while (ch=='y');

System.out.printf("%80s ", "XYZ Community Hospital");

System.out.printf(String.format("%150s ", "").replace(' ', '='));

System.out.printf("%10s%30s%80s ", "Name", "Address", "Payment Information");

System.out.printf("%-12s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s ", "Last", "First", "Address Line 1", "City", "State", "Zip", "Amount Owed", "Payment Amt.", "Payment Date");

System.out.printf(String.format("%150s ", "").replace(' ', '='));

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

Patient p = arr.get(i);

System.out.printf("%-12s %-12s %-30s %-15s %-5s %-10s %-15s %-15s %-15s ", p.getLast(), p.getFirst(), p.getAddress(), p.getCity(), p.getState(), p.getZip(), p.getAmount(), p.getPayment(), p.getDate());

}

input.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Refer to Exercise 5. Compute a 95% t CI for .

Answered: 1 week ago