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 7 of 7

Thread: completely stuck on a simple code

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default completely stuck on a simple code

    hey guys,

    I'm having a problem figuring out how to make a good code for the following problem:

    you have €100000 debt, the bank is asking 9% interest, and you want to pay the bank 15000 every year to make the debt 0.

    now I need 2 different colums, 1 with the remaining debt after every year and 1 with the amount of interest you have to pay every year. how on earth do you make a working code for this problem.

    I would really appreciate if someone could point me in the right direction.
    Last edited by disp; February 22nd, 2011 at 09:39 AM.


  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: completely stuck on a simple code

    What have you tried so far?

    If you're unsure where to get started, try reading The Java™ Tutorials

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: completely stuck on a simple code

    Please show us you have attempted to write a class and we can take it from there.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: completely stuck on a simple code

    so far i made:

    double x;
            int a;
            double r;
            int j;       
     
            r = 100000;
            a = 15000;
            x = 1.09;
     
            for(j=1; j<=11; j++)
     
            System.out.println(r*x-a);

    but that really doesnt do much for me except give the same anwser 11 times.
    Last edited by disp; February 22nd, 2011 at 01:39 PM.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: completely stuck on a simple code

    If I were you, I would give the variables a decscriptive name so you know what you are working with.

    The reason you are getting the same output 11 times is because the value printed never changes in the for loop..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  6. #6
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: completely stuck on a simple code

    Try this

     
    package debt;
     
    public class Debt {
     
        public static void main(String[] args) {
            // TODO code application logic here
     
            double debt = 100000;
            int payment = 15000;
            double interest = 1.09;
     
            while (debt>0)
            {
                 System.out.println("Debt "+(int)debt+" / Interest to pay "+(int)calcinterest(interest,debt));
                 debt=debt+calcinterest(interest,debt)-payment;
            }
        }
     
        public static double calcinterest(double myinterest, double mydebt)
        {
        myinterest=(myinterest*mydebt)-mydebt;    
        return myinterest;    
        }  
     
    }

  7. #7
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: completely stuck on a simple code

    Assuming 'interest' is a percentage rate, your calcinterest method arithmetic is wrong (try working out a few examples on paper before trying to code it). Possibly using 'myInterest' for both the interest rate and the interest value has confused you. It certainly confused me.

    Sensible naming is one of the most important and most neglected areas of coding.

Similar Threads

  1. Need help with simple code
    By suxen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 21st, 2011, 07:10 PM
  2. School java project, completely stuck
    By John1818 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 18th, 2010, 03:10 AM
  3. [SOLVED] My head Hurts... such a simple problem but I'm stuck!
    By Kassino in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2010, 08:38 AM
  4. Help I'm stuck on code.
    By GreenM in forum Loops & Control Statements
    Replies: 3
    Last Post: January 29th, 2010, 08:27 PM
  5. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM