Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can anybody fix this code with above requirements.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a program that calculates the amount of maoney earned on an investment, that amount should include 12 percent interest. prompt the user to choose the investment amount form one menu and the number of years for the investment in the second menu. display the total amount(balance)for each year of the investment. use a loop instructionto calculate the balance for each year. use the fourmula amount = investment * (1 + interest)raised to a power equalt to the year to caluclate the balance. Use the math power fucntion Math.pow(x,y) where x = (1 + interest) and y is for the year.
Who can fix this the correct way!!!
import javax.swing.*;
//Sample Program to enter String, Integer, and Float Numbers
public class Investment
{
public static void main(String[] args)
{
String gradePointAverage = JOptionPane.showInputDialog("How much money are you going to invest?");
float investment = Float.parseFloat(gradePointAverage);
String admissionScor = JOptionPane.showInputDialog("How many year are you interested in? (1-30)");
int years = Integer.parseInt(admissionScor);

double amount,amount1, x;
int y;

x = (1 + 0.12);
y = years;
amount = investment * (1 + 0.12);


amount1 = Math.pow(x,y) * investment;

for(y = years; y < 0; --y)
//if(amount1 > 0)
//amount1 += 1;
{
System.out.println( "For year number " + y + " The total will be " + amount1);
}

System.exit(0);
}
}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you need fixed? We don't do homework assignments around here but we are more than happy to help you work through them. Are you getting errors when you run the code? Are you having logic problems? Are you getting errors when you compile the code?
Let us know more about your problems and we can help.
You should enclose all code in Code Tags. It makes it easier to read when trying to debug on here.
 
Jeff Lamay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure some people help out students, anyways, I am using loops and I need to calculate a new balance for every year. The user selects an amount and then the user enters how many years. By that the system will run what I wrote but it is not. if you have jGrasp you can try it.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jeff Lamay:
I am sure some people help out students, anyways, I am using loops and I need to calculate a new balance for every year. The user selects an amount and then the user enters how many years. By that the system will run what I wrote but it is not. if you have jGrasp you can try it.


I didn't say we didn't help students. I said we don't do homework but we are more than happy to help you through your problems. That aside, you still have not provided enough information about your problem. So I am having a hard time helping you.
By that the system will run what I wrote but it is not...means nothing to me other than you can't get it to work. What I want to know is what specific problems are you having? Does the program execute? Are you just getting the wrong values?
if you have jGrasp you can try it
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After looking over your code, and re-reading your question, it would appear that this really has nothing to do with swing. The JOptionPane part of your program works. It looks like you are just having a problem getting the correct values when specifying an investment amount and for how many years.
Here would have been a better way of wording your question that might have caused less confusion...
I am supposed to write a program that calculates the amount of money earned on an investment. That amount should include a 12 percent interest rate. What I have compiles and executes just fine but I am not getting the expected results. Could someone give me a hand trying to figure this out?
And then show some code...
Anyway, as I was saying, since this really has nothing to do with Swing in terms of the problems you are having, I am going to move this to our Java In General (Intermediate) forum. You should get some good results there. Sorry about all the confusion.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It's clear that ur code won't execute since the for loop isn't accessible because the condition of (y) is wrong (y<0 instead of y>0) ..
Is this the problem?
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic