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

Write a Java program that reads a text file with the following: Account Number #

ID: 3542425 • Letter: W

Question

Write a Java program that reads a text file with the following:


Account Number      # of Items

10001                              3

10001                              2

10003                              4


Each item price is $1.50 (constant variable)


The program should output a yourbill.txt file that is a receipt including all account numbers and totals (the number of acct numbers is not known in advance)


Farmers Market Receipt


ACC #            TOTAL

10001                $4.50

10001                $3.00

10003                $6.00


GrantTotal         $13.50


Arrays can be used for this program.

Explanation / Answer

import java.io.*;

import java.lang.*;


public class prg

{

public static void main(String[] args)throws Exception

{

try{

BufferedReader in = new BufferedReader(new FileReader("./input.txt"));

String str;

while((str = in.readLine()) != null)

{

process(str);

}

in.close();

}

catch(Exception e){}

}


private static void process(String str)

{

try{

String[] parts = str.split(" ");

String part2 = parts[1];

int part_int2 = Integer.parseInt(part2);

double total = (1.50) * (double)part_int2;

System.out.println(total);


File file = new File("./output.txt");

FileWriter writer = new FileWriter(file, true);

writer.write(parts[0] +" $"+total+" ");

System.out.println(parts[0]+" $"+total);

writer.close();

}

catch(Exception e){}

}

}

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