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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 5 of 5

Thread: Need a little help. would be greatly appreciated

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need a little help. would be greatly appreciated

    I am taking a java class this semester and to me its pretty challenging because we are going really fast. I have a project that is due very soon so I am in need of some help. I think I have the majority of it completed I just think I need help on part 4 and mostly part 5. This part is the newest information that we learned, so I am not too familiar with it. I copy and pasted the word file of the project assignment and I also attached a .txt file of what I currently have. Any advice or help you can provide would be greatly appreciated. I feel lost, and for that matter, frustrated. Thanks in advance for any help you are willing to provide.

    AnnuityValue.txt

    __________________________________________________ ____________________________________
    Project 1
    Due date: September 28, 2009

    1. Project description: You are asked to develop a program to compute the amount of money (V) needed to be deposited into a student’s money market account so that he/she can withdraw a fixed amount (P) every month for the next (n) months. This money market account will pay him/her interest of (i)% per annum each month. The amount V is computed as follows:

    // it wouldn't let me copy and paste the math problem, but my professor says this part is fine so ill post the code for it
    deposit = withdrawal*((1-Math.pow(1+(interest/12),-months))/(interest/12));

    Please following the steps below to complete this assignment.

    1. Open TextPad, and type this code:

    import javax.swing.*;
    import java.text.*;

    public class AnnuityValue {

    public static void main(String[] args) {

    // Please insert your Java code here

    System.exit (0);
    }


    }
    Save this code as AnnuityValue.java.

    2. Modify this code to insert the followings:
    - Declare 4 variables: one variable to represent the amount of money to be deposited, one variable represents the annual interest rate and one variable represents and number of months, and one variable represents the amount of money to be withdrawn. We use “double” data type to represent the amount of money to be deposited, annual interest rate and the amount of money to be withdrawn. We use “int” data type to represent the number of months.

    - Print out the following description on the screen using System.out.println:
    “This program computes the amount of money (V) needed to be deposited into a student’s money market account so that he/she can withdraw a fixed amount (P) every month for the next (n) months. This money market account will pay him/her interest of (i)% per annum each month”

    Save the update of this file to AnnuityValue.java. Compile and run this code. You should see the description displayed on the screen.

    3. Modify this code to use JOptionPane as shown in our class to get input values from users. You should prompt a user to enter annual interest rate, and store it to the variable that represents the annual interest rate (which is declared in step 2). You should prompt a user to enter the amount of money to be withdrawn and store it to the corresponding variable declared in step 2. Finally, you prompt a user to enter the number of months and store it to the variable that represents the number of months in step 2. Notice that you should use a temporary String as a place holder first and then convert from String to integer or double correspondingly. After you modify the code, save, compile and run this code. (30 points)

    4. Please use the formula (1) above compute the amount of money to be deposited. Save, compile and run this code

    5. Modify the program in step 4 to make sure that the input values are valid. In this case, please check if the annual interest rate is from 0.08% to 0.5%, the number of years is greater than zero, and the amount of money to be withdrawn is greater than zero. Use if statement for this task. Print out the error messages if these values are invalid and exit the program.
    Save, compile, run and submit this code.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Need a little help. would be greatly appreciated

    Question: Must you use textpad? I would really recommend getting an IDE, like NetBeans and Eclipse. Which one is usually up to personal preference.

    As for the assignment, what is it you have done? We are not here to do your homework for you The instructions seem pretty self-explanatory, follow them and come back to us with your questions.

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need a little help. would be greatly appreciated

    If you did not see it, I posted the .txt document with all my current work. Since then I worked on it a little more so I will post what I have done right under this text. I have all the message boxes that come up and ask what the amounts are. I have the formula right I believe. My big question is that when I run the code in java and enter in all my numbers I do not get a final answer, just a blank. What else do I need? I think I'm really close to getting it correct. Thank in advance for your help. .txt document follows.

    AnnuityValue.txt

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Need a little help. would be greatly appreciated

    Haha, my bad Yes, I think I see you're problem. On this line:

    System.out.println(" The amount of money needed is ");

    you print out the message, but forget to attach the value. Change it to this:

    System.out.println(" The amount of money needed is "+deposit);

    A second (minor) note is that you're using System.exit(1) to quit your program. In general, I'd advise against that, rather you should just return from the main method and allow the JVM to terminate that way.

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Need a little help. would be greatly appreciated

    The value passed into System.exit should be zero if there was no problems encountered but I'd recommend you to let the main method run to its end as well if possible. System.exit kills the JVM.

    // Json