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

Using a text file, complete the following program that reads all information int

ID: 3828891 • Letter: U

Question

Using a text file, complete the following program that reads all information into an array and prints the following information: The total deposits (add all deposits for all customers) The total withdrawals (add all withdrawals for all customers) The name and balance of the customer with the highest final balance A sample line of the text file: Sarah Eaton, 12345, 1000, d, 250, d, 45, w, 100, d, 65, w, 25 import java.util.Scanner; import java.io.*; public class FileAccount {public static void main(string[] args) throws IOException {Scanner filescan, linescan; String filename; String line;//a line from the file Scanner scan = new Scanner(System.in); system.out.printIn("Enter the name of the input file:"); fileName = scan.nextLine(); filescan = new Scanner (new File(fileName));//Read and process each line of the file while (filescan.hasNext()) {line = fileScan.nextLine(); linescan = new Scanner (line); linescan.useDelimiter(", "); while (lineScan.hasNext()) {}//end of Linescan}//end of the fileScan fileScan.close();}}

Explanation / Answer

The same I have developed using JDBC by which we can extract the customer account info directly from bank database

import java.sql.*;

public class DisplayAccountStat {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";

// Database credentials
static final String USER = "username";
static final String PASS = "password";

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);

//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT acno,credit,debit from CUSTACCOUNT";
ResultSet rs = stmt.executeQuery(sql);

//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int acno = rs.getInt("acno");
int credit = rs.getInt("credit");
int debit = rs.getInt("debit");

//Display values

System.out.print("acno" + acno);
System.out.print("Credit" + credit);
System.out.print("debit " + debit);

}
//STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Thank you");
}//end main
}//end DisplayAccountStat class

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