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

In JAVA, Write a program that reads data from an input file and writes a report

ID: 3747801 • Letter: I

Question

In JAVA, Write a program that reads data from an input file and writes a report to an output file.

The input data will be veterinary data. The output will be a report of the cost of one visit to the vet for one pet. See below for both the input file format and the report format.

1) Report column specifications. Define the columns in the printf statements that generate the report such that they are wide enough to hold data at least as large as the data that appears in the sample input file below. All data in each column should be properly lined up

The name column should be left justified and the other columns should be right justified.

Ask the user to enter the name of both the input and output files. Whatever names they enter at the command line during execution should be used for input and output.

File Format

Sample Input File (Visit.txt)

Andrea Rodriguez

9

3

2018

Snickers

Dog

Male

7

Rabies Shot

20.00

1

true

0.75

Distemper/Parvo Combo

45.00

1

false

0.0

Physical Therapy

100.00

2

true

.5

Microchip

19.00

1

false

0.0

Neutering

200.00

1

true

.8

X ray

200.00

3

true

.9

Overnight Stay

200.00

2

true

.8

Sample File Output (Report.txt)

Pet Veterinarian Visit Report

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

Veterinarian: Andrea Rodriguez

Date        : 09/03/2018

Pet Name   : Snickers

Pet Species: Dog

Pet Gender : Male

Procedures

Name                         Price Qty     Amount   Is Covered Pct Covered   Amount Covered   Amount Due

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

Rabies Shot                  20.00    1      20.00         true         0.75            15.00         5.00

Distemper/Parvo Combo        45.00    1      45.00        false         0.00             0.00        45.00

Physical Therapy            100.00    2     200.00         true         0.50           100.00       100.00

Microchip                    19.00    1      19.00        false         0.00             0.00        19.00

Neutering                   200.00    1     200.00         true         0.80           160.00        40.00

X ray                       200.00    3     600.00         true         0.90           540.00        60.00

Overnight Stay              200.00    2     400.00         true         0.80           320.00        80.00

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

Total                                      1484.00                                    1135.00       349.00

Explanation / Answer

If you have any doubts, please give me comment...

import java.util.*;

import java.io.*;

public class PetVeterinarian {

public static void main(String[] args) {

String veterinarian, date, pet_name, species, gender;

try {

Scanner in = new Scanner(new File("Visit.txt"));

PrintWriter pw = new PrintWriter(new File("Report.txt"));

pw.println("Pet Veterinarian Visit Report");

pw.println("----------------------------------");

veterinarian = in.nextLine();

date = in.nextInt()+"/"+in.nextInt()+"/"+in.nextInt();

pet_name = in.next();

species = in.next();

gender = in.next();

pw.printf("%-15s: %s ","Veterinarian", veterinarian);

pw.printf("%-15s: %s ", "Date", date);

pw.printf("%-15s: %s ", "Pet Name", pet_name);

pw.printf("%-15s: %s ", "Pet Species", species);

pw.printf("%-15s: %s ", "Pet Gender", gender);

pw.println("Procedures");

pw.printf("%-25s %8s %5s %8s %15s %15s %15s %15s ", "Name", "Price", "Qty", "Amount", "Is Covered", "Pct Covered", "Amount Covered", "Amount Due");

pw.println("-------------------------------------------------------------------------------------------------------------------------");

String name, is_covered;

double price, pct_covered, amount, total_amount = 0, total_amt_covered = 0;

int qty;

in.nextInt();

while(in.hasNextLine()){

in.nextLine();

name = in.nextLine();

price = in.nextDouble();

qty = in.nextInt();

is_covered = in.next();

pct_covered = in.nextDouble();

amount = qty*price;

total_amount+= amount;

total_amt_covered += amount*pct_covered;

pw.printf("%-25s %8.2f %5d %8.2f %15s %15.2f %15.2f %15.2f ", name, price, qty, amount, is_covered, pct_covered, pct_covered*amount, (amount-pct_covered*amount));

}

pw.println("-------------------------------------------------------------------------------------------------------------------------");

pw.printf("%-25s %8s %5s %8.2f %15s %15s %15.2f %15.2f ", "Total", " ", " ", total_amount, " ", " ", total_amt_covered, (total_amount-total_amt_covered));

in.close();

pw.close();

} catch (FileNotFoundException e) {

System.out.println("Unable to open Visit.txt"+e.getMessage());

}

}

}

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