JAVA PROBLEM Using the data provided, create print-out that will print a letter
ID: 3805219 • Letter: J
Question
JAVA PROBLEM
Using the data provided, create print-out that will print a letter per customer (total of 1000 customers).
Every letter should be 66 lines in total
Each letter cannot exceed 80 columns.
Print the letter for only customer who has more than $5 balance.
It should print nicely.
You will need to calculate new amount due if not paid in 10 day. You need to calculate the new date (system date + 10 days).
Letter date is the system run date.
Deliverable:
Project folder as a zip file. Your output (ColLetter_yourInitials.txt) should be created at your project folder)
Data File -https://www.dropbox.com/s/3hggzrkany68hz1/dataCollection%20%282%29.txt?dl=0
Sample Output - https://www.dropbox.com/s/i6umvr3gcabjsw9/CollectionLetter.TXT?dl=0
Explanation / Answer
Letter.java:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Letters {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
String line;
while((line = reader.readLine()) != null) {
String tokens[] = line.split("\|");
String firstName = tokens[0];
String lastName = tokens[1];
String addr1 = tokens[2];
String addr2 = tokens[3];
String city = tokens[4];
String province = tokens[5];
String zip = tokens[6];
Double amount = Double.parseDouble(tokens[7].replace("$", ""));
if(amount > 5) {
File file = new File("output\" + firstName + ".txt");
file.getParentFile().mkdirs();
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.append(String.format(" %3s%s ", " ", "ACME Inc."));
writer.append(String.format("%3s%s ", " ", "123 Coffee Beans Street"));
writer.append(String.format("%3s%s ", " ", "Java, GA 99999"));
writer.append(String.format("%3s%s %s ", " ",firstName , lastName));
writer.append(String.format("%3s%s ", " ",addr1));
writer.append(String.format("%3s%s ", " ",addr2));
writer.append(String.format("%3s%s, %s %s ", " ",city,province, zip));
writer.append(String.format("%62s%s ", " ", LocalDate.now().format(DateTimeFormatter.ofPattern("M/d/yyyy"))));
writer.append(String.format("%3s%s %s %s, ", " ","Dear",firstName , lastName));
int lines = 27;
String lineContent = "Our records shows unpaid balance of $"+ String.format("%.2f", amount) +" that is over 120+ days old. "
+ "The balance due is now. If the balance is not fully paid in ten days "
+ "(by 3/27/2017), we will have to inform the collection agent for outstanding "
+ "balance plus %10 processing fee that increases total amount to $"+ String.format("%.2f", 1.1*amount) +".";
lines += writeLine(lineContent, 80, writer);
writer.append(" ");
lines += 1;
lineContent = "If you have any questions or like to discuss a payment plan, please do"
+ "not hesitate our office at 555-555-5555.";
lines += writeLine(lineContent, 80, writer);
writer.append(" ");
lines += 4;
writer.append(String.format("%3s%s ", " ","Acme Financial Team"));
while(++lines < 66) {
writer.append(" ");
}
writer.close();
}
}
reader.close();
}
static int writeLine(String line, int max, BufferedWriter writer) throws IOException {
String tokens[] = line.split(" ");
int lines = 1;
writer.append(" ");
int col = 7;
for (String word : tokens) {
if (col + word.length() > max) {
writer.append(" ");
lines++;
writer.append(" ");
col = 3;
}
writer.append(word + " ");
col += word.length() + 1;
}
writer.append(" ");
return lines;
}
}
Place your input file in the same directory as this java file with name "input.txt". After running the program, you will get a folder as output, inside which all the files will be residing corresponding to letters for first_name.
Sample Output:
FirstNameDPT.txt:
ACME Inc.
123 Coffee Beans Street
Java, GA 99999
FirstNameDPT LastDPT
406 Main Street
Suite 100A
City104, GA 25133
3/27/2017
Dear FirstNameDPT LastDPT,
Our records shows unpaid balance of $444.87 that is over 120+ days old.
The balance due is now. If the balance is not fully paid in ten days (by
3/27/2017), we will have to inform the collection agent for outstanding
balance plus %10 processing fee that increases total amount to $489.36.
If you have any questions or like to discuss a payment plan, please donot
hesitate our office at 555-555-5555.
Acme Financial Team
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.