Hi. I'm new to this forum and to programming in general. This is my first programming class and it is in JAVA. I have been doing alright in the class, but am really struggling with this weeks program assignment. If you could help me out at all I would really appreciate it!! Thank you so much.

This is the problem I have to solve.

Unit 8 - Bank Program - Looping

Instructions
Using the algorithm that you created in the last unit.
Write the Java program will solve the following problem definition.
Click on the View/Complete link to submit the program for grading.

A bank in your town updates its customer's accounts at the end of each month.
The bank offers two types of accounts, savings and checking.
Every customer must maintain a minimum balance.
If a customer's balance falls below the minimum,
there is a service fee of $10.00 for a savings account and $25.00 for checking accounts.
If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:

  • Savings accounts receive 4% interest
  • Checking accounts with balances over $5,000 more than the minimum balance receive 3% interest; otherwise the interest is 1.5%

Minimum balance for savings accounts - 500.00
Minimum balance for checking accounts - 25.00

The data will be read from a data file that contains the following information:
account number, customer name, type of account, current balance

Record Layout of the file:
Account Number First Name Last Name AccountType Balance

The data file is attached to this assignment. The filename is bank.dat.

Please Note: The data files will be read and written to the current directory.
Use a relative pathnames for the files. The pathname to the input file
should be "bank.dat" and the pathname to the output file "bank.out".
If you use an absolute pathname like this: "c:/My Documents/ciss-110/bank.dat"
I will not be able to run your program because I do not have access to your hard drive.

This is what I have at the moment.

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.Font;
import java.io.*;
import java.util.*;
import java.lang.*;

public class bankprogramLoop
{
    public static void main(String[]args)
    throws FileNotFoundException
    {

//scanner infile
Scanner inFile = new Scanner(new FileReader("bank.dat"));
//save to file bank.out
PrintWriter outFile = new PrintWriter("bank.out");
    //constants
    double checkingMinimumBalance = 25.00;
    double checkingServiceFee = 25.00;
    double checkingInterestRateMin = 0.015;
    double checkingInterestRateMax = 0.03;
    double hihgerInterestBalance = checkingMinimumBalance + 5000;
    double savingsMinimumBalance = 500.00;
    double savingsServiceFee = 10.00;
    double savingsInterestRate = 0.04;

    //variables
    int accountNumber;
    String firstName;
    String lastName;
    double accountBalance;
    double checkingInterest;
    double savingsInterest;
    char accountType;
    double serviceFee;
    double interest;



    while (inFile.hasNext())
        {
            accountNumber = inFile.nextInt();
            firstName = inFile.next();
            lastName = inFile.next();
            accountType = inFile.next().charAt(0);
            accountBalance = inFile.nextDouble();

switch (accountType)
    {
    case 'c':
    case 'C':
    serviceFee = checkingServiceFee;
        if      (accountBalance < checkingMinimumBalance)
                        {

            interest = accountBalance * checkingInterestRateMin;
            accountBalance = (accountBalance - serviceFee) + interest;
                        }
    else if (accountBalance >= (checkingMinimumBalance+hihgerInterestBalance))
                        {
        interest = accountBalance * checkingInterestRateMax;
        accountBalance = (accountBalance - serviceFee) + interest;
                        }
                    else
                        {
            interest = accountBalance * checkingInterestRateMin;
            accountBalance = (accountBalance - serviceFee) + interest;
                        }

            case 's':
            case 'S':
            serviceFee = savingsServiceFee;
                    if (accountBalance < savingsMinimumBalance)
                        {

            interest = accountBalance*savingsInterestRate;
                accountBalance = (accountBalance - serviceFee) + interest;
                        }
                    else
                        {
                    interest = accountBalance * savingsInterestRate;
                accountBalance = (accountBalance - serviceFee) + interest;
        }
            default: System.out.println("***INVALID ACCOUNT TYPE***");
            }
    //write accountNumber, firstName, lastName, accountType, accountBalance to output file
outFile.printf("%9.2f %20s %20s %20s %9.2f", accountNumber, firstName, lastName, accountType, accountBalance);
}
//close files
inFile.close();
outFile.close();
}
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

What do you mean its looping??

Try displaying the values that you read from the file after every read

System.out.println(accountNumber);

and see if it reads all your data and to verify if your program is indeed looping.

In the bank.dat file there are four lines, each for a seperate account. two are savings and two are checking. The account type is specified by a C or S. the program should read a line, make the appropriate calculations, and save the file to bank.out

unless someone sees another issue with this, I believe the only thing I need to do is make the program read the char and apply it. So far I have not made that work...

this thread can close. I completed my assignment. Just rewrote everything and realized what I had been doing wrong. Got it working properly.

This question has already been answered. Start a new discussion instead.