In: Computer Science
Online bank loan sanction facility is launched to facilitate the client. Write a java program to create class Loan with data members client name, address, age, salary, loan amount, loan type(housing, vehicle, personal) . Take the necessary inputs and write the object into the file. The bank manager will fetch the loan details from the file and verify the details for approval.
a. Write a java program for a client to submit the application in a file.
b. Write a java program for a bank manager to fetch the details from the file for approval.. Single line text.
(A). Client program code
import java.io.*;
import java.util.Scanner;
class Loan {
   private String name, age, address, salary, loanAmount,
loanType;
//constructor for variable initialization
   Loan(String n, String age, String address, String
salary, String la, String lt) {
       this.name = n;
       this.age = age;
       this.address = address;
       this.salary = salary;
       this.loanAmount = la;
       this.loanType = lt;
   }
//function to store the data in the file
   public void createUser() {
       try {
           File fobj = new
File("S:\\banking.txt"); /* creating the object of File class(Enter
location according to your choice)*/
          
fobj.createNewFile(); // creating file
           FileWriter
myWriter = new FileWriter("S:\\banking.txt", true); /* creating
FileWriter object to write in the file*/
           BufferedWriter
out = new BufferedWriter(myWriter);
          
out.write(this.name + " " + this.age + " " + this.address + " " +
this.salary + " " + this.loanAmount + " " + this.loanType +
"\n");
          
out.close();
       } catch (IOException e) {
          
System.out.println(e);
       }
}
}
class Banking {
   public static void main(String[] args) {
       Scanner obj = new
Scanner(System.in);
       System.out.println("Enter
name");
       String name = obj.nextLine();
       System.out.println("Enter
age");
       String age = obj.nextLine();
       System.out.println("Enter Loan type
and choices are Housing, Vehicle, Personal");
       String loan_type =
obj.nextLine();
       System.out.println("Enter
Salary");
       String sal = obj.nextLine();
       System.out.println("Enter Loan
Amount");
       String loan_amount =
obj.nextLine();
       System.out.println("Enter address
");
       String add = obj.nextLine();
       Loan user = new Loan(name, age,
add, sal, loan_amount, loan_type);//create object of class
Loan
       user.createUser();//call function
to store data in file
       System.out.println("Record added
successfully");
       obj.close();
   }
}


OUTPUT:

(B). Manager program
import java.io.File; // File class
import java.io.FileNotFoundException; // class to handle
errors
import java.util.Scanner; // Scanner class to read text files
public class Manager {
public static void main(String[] args) {
System.out.println(" NAme Age Address Salary Loan Amount Loan Type
");
try {
File obj = new File("S:\\banking.txt"); //creating the file
object
Scanner sc = new Scanner(obj); //creating the object of scanner
class to read file content
int i=1;
while (sc.hasNextLine()) { //Run while loop until the file has
lines
String data = sc.nextLine();
System.out.println(i+". " + data); //printing the line of
file
i++;
}
sc.close();
} catch (FileNotFoundException e) { // to catch exception
System.out.println("An error occurred.");
e.printStackTrace(); //print the stack of exception
}
}
}
OUTPUT:
