# Need a little help. would be greatly appreciated

• September 26th, 2009, 05:49 PM
ryan29121
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.

Attachment 58

__________________________________________________ ____________________________________
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) {

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.
• September 27th, 2009, 02:53 AM
helloworld922
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 :P The instructions seem pretty self-explanatory, follow them and come back to us with your questions.
• September 27th, 2009, 08:29 AM
ryan29121
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.

Attachment 59
• September 27th, 2009, 01:30 PM
helloworld922
Re: Need a little help. would be greatly appreciated
Haha, my bad :P Yes, I think I see you're problem. On this line:

Code :

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

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

Code :

`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.
• September 27th, 2009, 02:03 PM
Json
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