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

JAVA PROBLEM Using the data provided, create print-out that will print a letter

ID: 3804955 • 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

package sorter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; public class SortingAlgorithm { private static final String CREATE_DB = "CREATE DATABASE sorting"; private static final String DROP_DB = "DROP DATABASE sorting"; private static final String CREATE_TABLE = "CREATE TABLE sorting.sorting ( num double not null )"; public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); List doubles = new ArrayList(50); String typed; do { typed = JOptionPane.showInputDialog(null, "Type a double:"); if (typed != null) doubles.add(Double.parseDouble(typed)); } while (typed != null); List sorted = new ArrayList(50); try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "root")) { try (PreparedStatement ps = con.prepareStatement(CREATE_DB)) { ps.executeUpdate(); } try (PreparedStatement ps = con.prepareStatement(CREATE_TABLE)) { ps.executeUpdate(); } for (Double d : doubles) { try (PreparedStatement ps = con.prepareStatement("INSERT INTO sorting.sorting (num) VALUES (" + d + ")")) { ps.executeUpdate(); } } try ( PreparedStatement ps = con.prepareStatement("SELECT * FROM sorting.sorting ORDER BY num"); ResultSet rs = ps.executeQuery()) { while (rs.next()) { sorted.add(rs.getDouble("num")); } } try (PreparedStatement ps = con.prepareStatement(DROP_DB)) { ps.executeUpdate(); } } JOptionPane.showMessageDialog(null, "The array sorted is: " + sorted); } }