Results 1 to 7 of 7
  1. #1
    Zora is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Please check my Java program

    Hey guys.

    I'm currently working on a Java assignment and I was wondering if there are any problems in my code.

    Here's the question:
    Write an algorithm and a program to settle the following question. A bank account starts out with an initial balance, iBalance. Interest is computed monthly at 6% per year (0.5% per month). Every month $500.00 is withdrawn to meet education expenses. After how many years is the account depleted?
    There are some values for which the algorithm you developed may not terminate. Modify your algorithm to make sure it always terminates. The program should read the iBalance from command line.



    The input of the program is iBalance

    Examples of the output of the program:
    6 years and 1 month

    1 year and 6 months

    8 months (note that the output should not be as 0 years and 8 month)



    Note: Withdraws will be at the end of each month. For example if the deposit is equal to 500$, then at the end of the first month the iBalance will be equal to 500*(1+0.06/12) = 502.50 $.

    By taking 500$, the iBalance will be equal to 2.5$, and at the end of the second month the iBalance will be equal to 2.51 $. As the result at the end of the second month the account will be depleted.
    And here's my code:
    Java Code:
    public class lab3
    {
       public static void main (String[] args)
      {
         float aNumber=0;
         // Read input argument
         if (args.length < 1){ 
            System.out.println("Input a number"); 
            System.exit(0); // Terminate the program if user has not input a number
          }
          else
            aNumber = Float.parseFloat(args[0]);
          
          month = 0
          year = 0
          int iBalance; //Input user's balance
          iBalance * 0.005;
          If (iBalance > 500) {
          iBalance * 0.005 - 500;
          month += month
          }
          Else
          System.out.println("It will take " + month + "month(s) for the account to deplete.")
          If (month > 12) {
          year += year
          }
          If (year > 100) {
          System.out.println("It will take " + years + "year(s) and " + month + "month(s) for the account to deplete.");
      }
    }
    I don't want corrections for my code, just explanations as to why it is wrong so that I can figure out a solution.

    By the way, I'm very new to Java and also on this forum, so I don't know how things work around here, but I appreciate your time and effort to help me out. :D

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Please check my Java program

    Lots of errors there, as you're probably aware. Best thing to do is try to compile it and see what errors it generates, and use that as a starting point to fix it.

    In particular, note that you have to terminate statements with a semicolon, not a new line. Also, don't capitalise keywords like 'if' and 'else'; the compiler won't recognise them as keywords if you do.

  3. #3
    Zora is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: Please check my Java program

    Yeah I'm aware of that. Syntax errors are fine, I just get confused on where to put semicolons and curly braces. I'm more focused on the logical errors, like does it make sense?

  4. #4
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Please check my Java program

    Makes sense to me, but that doesn't matter; you need it to make sense to the compiler. Fix the syntax errors and then you can start worrying about whether it's doing what you expect it to.

  5. #5
    Zora is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: Please check my Java program

    I will do that. Alright thanks for your guidance.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Please check my Java program

    There are so many errors that it suggests that you're not compiling your code frequently enough. If you're not using an IDE like Eclipse or NetBeans, you should compile your code very frequently, probably after every one to two new lines of code, and then don't add any new code until all compilation errors have been fixed.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Please check my Java program

    Quote Originally Posted by Zora View Post
    Yeah I'm aware of that. Syntax errors are fine, I just get confused on where to put semicolons and curly braces. I'm more focused on the logical errors, like does it make sense?
    No it does not. You have it backwards as you cannot test logic if syntax is off.

Similar Threads

  1. please check the program
    By katturv in forum New To Java
    Replies: 1
    Last Post: 01-08-2011, 03:38 PM
  2. java program check
    By ryamz in forum New To Java
    Replies: 4
    Last Post: 07-22-2010, 04:55 AM
  3. CRC check program 1 error
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 05:04 AM
  4. how to check available resources in java program
    By lealea in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 08:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •