Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3


  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Default I NEED HELP Q-Q

    ok guys i need a lot of help in short x-x idk how to add my interest rate to my balance using class(1) and method (4). I am lost while doing my homework. Now it turned into a chunk of confusion java program by using JOptionPane

    //This is my Saving account
    import java.text.DecimalFormat;

    public class SavingAccount
    private DecimalFormat dollar = new DecimalFormat("#,###.00");
    private double balance;
    private double interestRate;
    private double interest; //interest earned

    // Contructor to set the starting balance
    public SavingAccount()
    balance = 0.0;
    public SavingAccount(double startBalance, double rate)
    balance = startBalance;
    interestRate = (rate / 12) / 100;
    interest = 0.0;

    public SavingAccount(String str)
    balance = Double.parseDouble(str);

    // Methods for Annual interest rate
    public void setInterestRate()
    interest = balance * interestRate;
    balance += interest;
    public double doInterest()
    return interest;

    // Methods for Deposit
    public void doDeposit(double amount)
    balance += amount;

    public void doDeposit(String str)
    balance += Double.parseDouble(str);

    // Methods for Wit3hdrawal
    public void doWithdrawal(double amount)
    balance -= amount;

    public void doWithdrawal(String str)
    balance -= Double.parseDouble(str);

    public double getBalance()
    return balance;

    //And this is my Saving accountdemo

    import javax.swing.JOptionPane;
    import java.text.DecimalFormat;

    public class SavingAccountDemo
    public static void main(String[] args)

    DecimalFormat dollar = new DecimalFormat("#,###.00");

    //To make the final output work
    double interestTotal = 0;
    double depositTotal = 0;
    double withdrawalTotal = 0;

    // Annual Interest rate input
    String interestRate = JOptionPane.showInputDialog("Enter annual interest rate as percent: ");
    double annualRate = Double.parseDouble( interestRate );

    // Starting Balance input
    String balance = JOptionPane.showInputDialog("Enter starting balance: ");
    SavingAccount account = new SavingAccount( balance,interestRate );

    // Numbers of months since the account opened
    String numberMonth = JOptionPane.showInputDialog("Enter numbers of months since account opened: ");
    int month = Integer.parseInt( numberMonth );


    JOptionPane.showMessageDialog(null, "You will be asked to enter\n" +
    " deposit and withdrawal for each month\n" +
    " for " + month + " months.");

    for (int count = 1; count <= month ;count++)

    // Deposit the user's pay into the account.
    String stringDeposit = JOptionPane.showInputDialog("Enter Deposit for month-" + count + ":");
    double deposit = Double.parseDouble( stringDeposit );

    // Withdraw some cash from the account.
    String stringWithdrawal = JOptionPane.showInputDialog("Enter withdrawal for month-" + count + ":");
    double withdrawal = Double.parseDouble( stringWithdrawal );

    // Update

    depositTotal = deposit + depositTotal;
    withdrawalTotal = withdrawal + withdrawalTotal;

    // Output for deposit, withdrawal, etc.
    "For month-" + count +
    "\nDeposit is: $" + dollar.format(deposit) +
    "\nWithdrawal is: $" + dollar.format(withdrawal) +
    "\nMonth Interest is: $" dollar.format(account.doInterest) +
    "\nBalance is: $" + balance);


    JOptionPane.showMessageDialog(null,"For " + month + " month(s)" +
    "\nEnding Balance is: $" + finalBalance +
    "\nTotal for deposits is: $" + dollar.format(depositTotal) +
    "\nTotal for withdrawals is: $" + dollar.format(withdrawalTotal) +
    "\nTotal for interest is: $" + dollar.format(interestTotal);


    The point is I'm having trouble with idk how to add my withdrawal, deposit and interestrate to my balance x-x Once you guys read this and fix it. Please explain to me how u guys fix it. THANK YOU

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 687 Times in 585 Posts

    Default Re: I NEED HELP Q-Q

    That's a big homework dump, which makes it a lot harder to help you than if you post an SSCCE and ask a specific question. Also, when posting code, you should always use the highlight tag.

    Instead of posting your homework, narrow your problem down to a specific step and ask a specific question about exactly where you're stuck.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    Join Date
    Sep 2013
    Thanked 13 Times in 13 Posts

    Default Re: I NEED HELP Q-Q

    Use code tags when posting to make everything nice and clean.
    [code=java] Place code in here[/code]

    As for your code I doubt anyone will just fix it we will however guide you in the right direction.

    You must understand what Objects are and how to use them. For example when you create a String it has methods you can use. How do you access those methods? An Object usually has constructors, Accessors/Mutators (getters/setters), and methods.

    Just skimming through the SavingAccount class you seem to be on the right track but as I said place it in the code tags to make it easier to read. When asking questions ask exactly what you are having trouble with and don't post code and expect people to "fix" it for you as that is not what the forums are for.

Tags for this Thread