Pabroa 03-NO.1 DeparmentCustomerData

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Pabroa, Jhon Lorenz E.

BSIT – 2 (Returnee)
JAVA CODE
package pabroa_departmentStoreCustomer;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.text.DecimalFormat;

/*OUTPUT: Write output to a file

Develop a Java program that will determine if a department store customer


has exceeded the credit limit on a charge account. For each customer,
the following facts are available:

a) Account number (integer)


b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer’s account this month
e) Allowed credit limit

The program should input all of these facts, calculate the new balance ( =
beginning balance + charges - credits )
and determine if the new balance exceeds the customer's credit limit. For
those customers whose credit limit
is insufficient for the new balance, the program should display the customer's
account number, credit limit,
new balance and the message "Credit limit exceeded!"

Enter Account Number: 100


Enter beginning balance: 5394.78
Enter total charges: 1000
Enter total credits: 500
Enter credit limit: 5500

Account No.: 100


Credit Limit: 5500
Balance: 5894.75
Credit Limit Exceeded!
*/

public class TestClass_3 {

public static void main(String[] args){


FileProcess file_process = new FileProcess();

file_process.input();
}

}
class CustomerAccount {

private int account_number;


private double balance;
private int total_charge;
private int total_credit;
private int credit_limit;

public int getAccount_number() {


return account_number;
}

public void setAccount_number(int account_number) {


this.account_number = account_number;
}

public double getBalance() {


return balance;
}

public void setBalance(double balance) {


this.balance = balance;
}

public int getTotal_charge() {


return total_charge;
}

public void setTotal_charge(int total_charge) {


this.total_charge = total_charge;
}

public int getTotal_credit() {


return total_credit;
}

public void setTotal_credit(int total_credit) {


this.total_credit = total_credit;
}

public int getCredit_limit() {


return credit_limit;
}

public void setCredit_limit(int credit_limit) {


this.credit_limit = credit_limit;
}

public double getTotal_balanced() {


return ((this.balance + this.total_charge) - this.total_credit);
}

public boolean isCreditLimit_exceed() {


return (getTotal_balanced() > this.credit_limit);
}
@Override
public String toString(){
final DecimalFormat df = new DecimalFormat("0.00");
String creditLimit_text = "\n";

if (isCreditLimit_exceed()) {
creditLimit_text = "\nCredit Limit Exceeded!";
}

return ("\nAccount No.: " + this.account_number + "\nCredit Limit: " +


this.credit_limit
+ "\nBalance: " + df.format(getTotal_balanced()) +
creditLimit_text);
}
}

class FileProcess {

public void input() {


Scanner scanner = new Scanner(System.in);
CustomerAccount cust_acct = new CustomerAccount();

System.out.print("Enter Account Number: ");


int acct_number = scanner.nextInt();
cust_acct.setAccount_number(acct_number);

System.out.print("Enter beginning balance: ");


double balance = scanner.nextDouble();
cust_acct.setBalance(balance);

System.out.print("Enter total charges: ");


int total_charge = scanner.nextInt();
cust_acct.setTotal_charge(total_charge);

System.out.print("Enter total credits: ");


int total_credit = scanner.nextInt();
cust_acct.setTotal_credit(total_credit);

System.out.print("Enter credit limit: ");


int credit_limit = scanner.nextInt();
cust_acct.setCredit_limit(credit_limit);

customerData_process(cust_acct);
}

public void customerData_process(CustomerAccount cust_acct) {

PrintWriter out_write = null;

try {
out_write = new PrintWriter(new BufferedWriter(new
FileWriter("customer_info.txt", true)));
out_write.println("\n" +cust_acct.toString());
} catch (IOException e) {
e.printStackTrace();
}finally {
if(out_write != null){
out_write.close();
}
}
}
}

INPUT:

OUTPUT:

You might also like