Question: Instruction: Write a class with methods to help you balance your checking account (an object class-main method is not in this class). The CheckingAccount Class

Instruction:

Write a class with methods to help you balance your checking account (an object

class-main method is not in this class). The CheckingAccount Class should have at

least two instance variables: the balance and the total service charges, along with

methods to get and set each instance variable. You may add other variables and

methods if you like. The program should read the initial balance for the month, followed

by a series of transactions. For each transaction entered, the program should display

the transaction data, the current balance for the account, and the total service charges.

Service charges are $0.10 for a deposit and $0.15 for a check. If a check forces the

balance to drop below $500.00 at any point during the month, a service charge of $5.00

is assessed but only for the first time this happens. Anytime the balance drops below

$50.00, the program should print a warning message. If a check results in a negative

balance, an additional service charge of $10.00 should be assessed. A transaction

takes the form of an int number (the transaction code), followed by a double number

(the transaction amount). If the int number is a 1, then the double number is the amount

of a check. If the int number is 2, then the double number is the amount of a deposit.

The last transaction is 0 with no number to follow it. Use the JOptionPane to produce

the dialog. A sample Input/Output dialogue is provided via the Sample Run Link below.

Use proper style and indentation, efficient programming techniques and meaningful

variable and method names according to Java conventions.

I have to make a checking account program using JOptionPane. It's not done yet and I have some troubles.

And this is my code:

Main.Java

import java.util.Scanner;

import javax.swing.JOptionPane;

public class Main

{

CheckingAccount acct = new CheckingAccount();

public static void main(String[] args)

{

Scanner scan = new Scanner (System.in);

double transAmt, check, deposit;

double initialBalance = Double.parseDouble(JOptionPane.showInputDialog("Enter your initial balance: "));

int transCode=getTransCode();

do

{

if(transCode==1)

{

transAmt= getTransAmt();

check=processCheck();

}

else if(transCode==2)

{

transAmt=getTransAmt();

deposit=processDeposit();

}

}while(transCode!= 0);

JOptionPane.showMessageDialog(null,"Transaction: End Current balance ");

}

public static int getTransCode()

{

int transCode = Integer.parseInt(JOptionPane.showInputDialog("Enter trans code: "));

return transCode;

}

public static double getTransAmt()

{

double transAmt=Double.parseDouble(JOptionPane.showInputDialog("Enter trans amount: "));

return transAmt;

}

public static void processCheck()

{

double balance=acct.getBalance();

JOptionPane.showMessageDialog(null,"Transaction: Current balance ");

}

public static void processDeposit()

{

}

}

CheckingAccount.Java

public class CheckingAccount

{

private double balance;

private double totalServiceCharge;

public CheckingAccount(double initialBalance)

{

balance = initialBalance;

totalServiceCharge =0.00;

}

public double getBalance(double transAmt, int code)

{

return balance;

}

public void setBalance(double transAmt, int code)

{

if(code==1)

{

balance = balance + transAmt;

}

else if(code==2)

{

balance = balance - transAmt;

}

}

public double getServiceCharge(int code)

{

if(code==1)

{

if(balance<500)

{

totalServiceCharge=5.00;

}

totalServiceCharge= 0.15;

}

else if(code==2)

{

if(balance<500)

{

totalServiceCharge=5.00;

}

totalServiceCharge= 0.10;

}

return totalServiceCharge;

}

public void setServiceCharge(double currentServiceCharge)

{

totalServiceCharge = currentServiceCharge;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!