I need help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pcbutts1

    #1

    I need help

    Yes this is a homework assignment. My instructor has broken english and I
    just could not follow along last night. How do I do this

    Write the program in Java (without a graphical user interface) and have it
    calculate the payment amount for 3 mortgage loans:

    a.. 7 year at 5.35%
    b.. 15 year at 5.5%
    c.. 30 year at 5.75%
    Use an array for the different loans. Display the mortgage payment amount
    for each loan.


    My first one is below that works but how do I do the above

    public class wtest
    {

    public static void main (String[] args)
    {
    double principal =2000000.0;
    double rate =5.75;
    double term =30.0;
    double monthlyPayment =0.0;

    rate = rate/1200.0;
    term = term * 12;
    monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
    System.out.prin tln(monthlyPaym ent);
    }

    }


    --


    The best live web video on the internet http://www.seedsv.com/webdemo.htm
    NEW Embedded system W/Linux. We now sell DVR cards.
    See it all at http://www.seedsv.com/products.htm
    Sharpvision simply the best http://www.seedsv.com




  • Eric Sosman

    #2
    Re: I need help



    (Was it really necessary to post this question to four
    count them four different newsgroups, at least one of which
    has nothing to do with Java? Methinks a brief look at some
    of the "new to Usenet" or "Emily Postnews" articles would
    be of benefit ...)


    pcbutts1 wrote On 02/23/06 14:33,:[color=blue]
    > Yes this is a homework assignment. My instructor has broken english and I
    > just could not follow along last night. How do I do this
    >
    > Write the program in Java (without a graphical user interface) and have it
    > calculate the payment amount for 3 mortgage loans:
    >
    > a.. 7 year at 5.35%
    > b.. 15 year at 5.5%
    > c.. 30 year at 5.75%
    > Use an array for the different loans. Display the mortgage payment amount
    > for each loan.
    >
    >
    > My first one is below that works but how do I do the above
    >
    > public class wtest
    > {
    >
    > public static void main (String[] args)
    > {
    > double principal =2000000.0;
    > double rate =5.75;
    > double term =30.0;
    > double monthlyPayment =0.0;
    >
    > rate = rate/1200.0;
    > term = term * 12;
    > monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
    > System.out.prin tln(monthlyPaym ent);
    > }
    >
    > }[/color]

    Since it's homework, I'll give a hint rather than
    an all-out answer:

    public class Wtest {
    public static void main (String[] args) {
    double principal = 2000000.0; // nice house!
    double[] rates = { 5.35, 5.5, 5.75 };
    double[] terms = { 7.0, 15.0, 30.0 };
    for (int i = 0; i < rates.length; ++i) {
    ...

    I hope this helps!

    --
    Eric.Sosman@sun .com

    Comment

    • pcbutts1

      #3
      Re: I need help

      Thanks for the tip. Sorry for the cross post, I wanted the maximum results
      by reading only one group. I snipped the java script group. Thanks again.

      --


      The best live web video on the internet http://www.seedsv.com/webdemo.htm
      NEW Embedded system W/Linux. We now sell DVR cards.
      See it all at http://www.seedsv.com/products.htm
      Sharpvision simply the best http://www.seedsv.com



      "Eric Sosman" <Eric.Sosman@su n.com> wrote in message
      news:dtl3jo$lt7 $1@news1brm.Cen tral.Sun.COM...[color=blue]
      >
      >
      > (Was it really necessary to post this question to four
      > count them four different newsgroups, at least one of which
      > has nothing to do with Java? Methinks a brief look at some
      > of the "new to Usenet" or "Emily Postnews" articles would
      > be of benefit ...)
      >
      >
      > pcbutts1 wrote On 02/23/06 14:33,:[color=green]
      >> Yes this is a homework assignment. My instructor has broken english and I
      >> just could not follow along last night. How do I do this
      >>
      >> Write the program in Java (without a graphical user interface) and have
      >> it
      >> calculate the payment amount for 3 mortgage loans:
      >>
      >> a.. 7 year at 5.35%
      >> b.. 15 year at 5.5%
      >> c.. 30 year at 5.75%
      >> Use an array for the different loans. Display the mortgage payment amount
      >> for each loan.
      >>
      >>
      >> My first one is below that works but how do I do the above
      >>
      >> public class wtest
      >> {
      >>
      >> public static void main (String[] args)
      >> {
      >> double principal =2000000.0;
      >> double rate =5.75;
      >> double term =30.0;
      >> double monthlyPayment =0.0;
      >>
      >> rate = rate/1200.0;
      >> term = term * 12;
      >> monthlyPayment = principal * rate/ (1.0 -
      >> Math.pow(rate+1 ,-term));
      >> System.out.prin tln(monthlyPaym ent);
      >> }
      >>
      >> }[/color]
      >
      > Since it's homework, I'll give a hint rather than
      > an all-out answer:
      >
      > public class Wtest {
      > public static void main (String[] args) {
      > double principal = 2000000.0; // nice house!
      > double[] rates = { 5.35, 5.5, 5.75 };
      > double[] terms = { 7.0, 15.0, 30.0 };
      > for (int i = 0; i < rates.length; ++i) {
      > ...
      >
      > I hope this helps!
      >
      > --
      > Eric.Sosman@sun .com
      >[/color]


      Comment

      • pcbutts1

        #4
        Re: I need help

        Can you give me another hint? I am still lost.

        --


        The best live web video on the internet http://www.seedsv.com/webdemo.htm
        NEW Embedded system W/Linux. We now sell DVR cards.
        See it all at http://www.seedsv.com/products.htm
        Sharpvision simply the best http://www.seedsv.com



        "Eric Sosman" <Eric.Sosman@su n.com> wrote in message
        news:dtl3jo$lt7 $1@news1brm.Cen tral.Sun.COM...[color=blue]
        >
        >
        > (Was it really necessary to post this question to four
        > count them four different newsgroups, at least one of which
        > has nothing to do with Java? Methinks a brief look at some
        > of the "new to Usenet" or "Emily Postnews" articles would
        > be of benefit ...)
        >
        >
        > pcbutts1 wrote On 02/23/06 14:33,:[color=green]
        >> Yes this is a homework assignment. My instructor has broken english and I
        >> just could not follow along last night. How do I do this
        >>
        >> Write the program in Java (without a graphical user interface) and have
        >> it
        >> calculate the payment amount for 3 mortgage loans:
        >>
        >> a.. 7 year at 5.35%
        >> b.. 15 year at 5.5%
        >> c.. 30 year at 5.75%
        >> Use an array for the different loans. Display the mortgage payment amount
        >> for each loan.
        >>
        >>
        >> My first one is below that works but how do I do the above
        >>
        >> public class wtest
        >> {
        >>
        >> public static void main (String[] args)
        >> {
        >> double principal =2000000.0;
        >> double rate =5.75;
        >> double term =30.0;
        >> double monthlyPayment =0.0;
        >>
        >> rate = rate/1200.0;
        >> term = term * 12;
        >> monthlyPayment = principal * rate/ (1.0 -
        >> Math.pow(rate+1 ,-term));
        >> System.out.prin tln(monthlyPaym ent);
        >> }
        >>
        >> }[/color]
        >
        > Since it's homework, I'll give a hint rather than
        > an all-out answer:
        >
        > public class Wtest {
        > public static void main (String[] args) {
        > double principal = 2000000.0; // nice house!
        > double[] rates = { 5.35, 5.5, 5.75 };
        > double[] terms = { 7.0, 15.0, 30.0 };
        > for (int i = 0; i < rates.length; ++i) {
        > ...
        >
        > I hope this helps!
        >
        > --
        > Eric.Sosman@sun .com
        >[/color]


        Comment

        • pcbutts1

          #5
          Re: I need help

          I got the errors down to 7 from 12 when trying to compile. Can someone
          explain these error and how to fix them.

          C:\w1>javac Wtest.java
          Wtest.java:10: operator / cannot be applied to double[],double
          rate = rate/1200.0;
          ^
          Wtest.java:11: operator * cannot be applied to double[],int
          term = term * 12;
          ^
          Wtest.java:12: cannot resolve symbol
          symbol : variable monthlyPayment
          location: class Wtest
          monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
          ^
          Wtest.java:12: operator * cannot be applied to double,double[]
          monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
          ^
          Wtest.java:12: operator + cannot be applied to double[],int
          monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
          ^
          Wtest.java:12: operator - cannot be applied to double[]
          monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
          ^
          Wtest.java:13: cannot resolve symbol
          symbol : variable monthlyPayment
          location: class Wtest
          System.out.prin tln(monthlyPaym ent);
          ^


          This is the file

          public class Wtest
          {
          public static void main (String[] args)
          {
          double principal = 2000000.0; // nice house!
          double[] rate = { 5.35, 5.5, 5.75 };
          double[] term = { 7.0, 15.0, 30.0 };
          for (int i = 0; i < rate.length; ++i)

          rate = rate/1200.0;
          term = term * 12;
          monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
          System.out.prin tln(monthlyPaym ent);
          }

          }

          --


          The best live web video on the internet http://www.seedsv.com/webdemo.htm
          NEW Embedded system W/Linux. We now sell DVR cards.
          See it all at http://www.seedsv.com/products.htm
          Sharpvision simply the best http://www.seedsv.com



          "Eric Sosman" <Eric.Sosman@su n.com> wrote in message
          news:dtl3jo$lt7 $1@news1brm.Cen tral.Sun.COM...[color=blue]
          >
          >
          > (Was it really necessary to post this question to four
          > count them four different newsgroups, at least one of which
          > has nothing to do with Java? Methinks a brief look at some
          > of the "new to Usenet" or "Emily Postnews" articles would
          > be of benefit ...)
          >
          >
          > pcbutts1 wrote On 02/23/06 14:33,:[color=green]
          >> Yes this is a homework assignment. My instructor has broken english and I
          >> just could not follow along last night. How do I do this
          >>
          >> Write the program in Java (without a graphical user interface) and have
          >> it
          >> calculate the payment amount for 3 mortgage loans:
          >>
          >> a.. 7 year at 5.35%
          >> b.. 15 year at 5.5%
          >> c.. 30 year at 5.75%
          >> Use an array for the different loans. Display the mortgage payment amount
          >> for each loan.
          >>
          >>
          >> My first one is below that works but how do I do the above
          >>
          >> public class wtest
          >> {
          >>
          >> public static void main (String[] args)
          >> {
          >> double principal =2000000.0;
          >> double rate =5.75;
          >> double term =30.0;
          >> double monthlyPayment =0.0;
          >>
          >> rate = rate/1200.0;
          >> term = term * 12;
          >> monthlyPayment = principal * rate/ (1.0 -
          >> Math.pow(rate+1 ,-term));
          >> System.out.prin tln(monthlyPaym ent);
          >> }
          >>
          >> }[/color]
          >
          > Since it's homework, I'll give a hint rather than
          > an all-out answer:
          >
          > public class Wtest {
          > public static void main (String[] args) {
          > double principal = 2000000.0; // nice house!
          > double[] rates = { 5.35, 5.5, 5.75 };
          > double[] terms = { 7.0, 15.0, 30.0 };
          > for (int i = 0; i < rates.length; ++i) {
          > ...
          >
          > I hope this helps!
          >
          > --
          > Eric.Sosman@sun .com
          >[/color]


          Comment

          • ge0rge

            #6
            Re: I need help

            pcbutts1 wrote:[color=blue]
            > I got the errors down to 7 from 12 when trying to compile. Can someone
            > explain these error and how to fix them.[/color]
            ....[color=blue]
            >
            > public class Wtest
            > {
            > public static void main (String[] args)
            > {
            > double principal = 2000000.0; // nice house!
            > double[] rate = { 5.35, 5.5, 5.75 };
            > double[] term = { 7.0, 15.0, 30.0 };
            > for (int i = 0; i < rate.length; ++i)
            >
            > rate = rate/1200.0;
            > term = term * 12;
            > monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
            > System.out.prin tln(monthlyPaym ent);
            > }
            >
            > }[/color]

            Ok pcbutts1. Since you mentioned DOS, I figure you are no spring chicken and
            therefore not a spotty kid too lazy to do the work. Assuming your difficulty is
            genuine, here is my way of tackling this problem (to which Eric Sosman has
            given a partial solution + java syntax) -

            thinking first
            principal is 2,000,000
            interest is 5.35% per annum
            Therefore interest per year is 2000000 x .0535 = 107000
            Total interest is 107000 x 7 = 749000
            Therefore total to be repaid is 2000000 + 749000 = 2749000
            number of months' repayment is 7 x 12 = 84
            Thererefore monthly repayment is 32,726.20

            answer = ((2000000 * 0.0535 * 7) + 2000000)/(7 * 12)
            Now, do a sanity check on the answer (perhaps on a calculator). If it checks
            out replace it with the correct java syntax

            monthlyPayment = ((principal * (rate[i]/100) * term[i]) + principal) / (term[i]
            * 12)

            Other things - brush up on arrays, the for statement, indent the code correctly
            and figure out when to use double or integers, how to get the correct display
            to 2 decimal places.

            I am too lazy to check your (1.0 - Math.pow(rate+1 ,-term)) for what it means.
            The syntax is incorrect anyway but if the logic is correct, use it. Otherwise
            do the code yourself.

            --
            Why is the alphabet in that order? Is it because of that song?
            -- Steven Wright

            Comment

            • zero

              #7
              Re: I need help

              "pcbutts1" <pcbutts1@seeds v.com> wrote in
              news:N9mdnZMLcd zXPZ3ZnZ2dnUVZ_ vidnZ2d@giganew s.com:
              [color=blue]
              > I got the errors down to 7 from 12 when trying to compile. Can someone
              > explain these error and how to fix them.
              >
              > C:\w1>javac Wtest.java
              > Wtest.java:10: operator / cannot be applied to double[],double
              > rate = rate/1200.0;[/color]


              First note I did not examine your original post, so I don't know if what
              I'm telling you is correct with regards to the logic you need. I am
              only commenting on the compilation errors you listed.

              rate is an array of doubles. You cannot divide an array by a double,
              you instead need to divide each of the elements of the array. This is
              done with a loop, for example:

              for(int i = 0; i < rate.length; i++)
              {
              rate[i] = rate[i] / 1200.00
              }

              [color=blue]
              > ^
              > Wtest.java:11: operator * cannot be applied to double[],int
              > term = term * 12;[/color]

              same as above
              [color=blue]
              > ^
              > Wtest.java:12: cannot resolve symbol
              > symbol : variable monthlyPayment
              > location: class Wtest
              > monthlyPayment = principal * rate/ (1.0 -
              > Math.pow(rate+1 ,-term)); ^[/color]

              What is monthlyPayment? It has not been defined anywhere in the
              program. In Java, you need to define all your variables (tell the
              compiler what type they have) before using them. In many cases, you'll
              also need to initialize (give them a specific value) before using them.
              [color=blue]
              > Wtest.java:12: operator * cannot be applied to double,double[]
              > monthlyPayment = principal * rate/ (1.0 -
              > Math.pow(rate+1 ,-term));
              > ^
              > Wtest.java:12: operator + cannot be applied to double[],int
              > monthlyPayment = principal * rate/ (1.0 -
              > Math.pow(rate+1 ,-term));
              > ^
              > Wtest.java:12: operator - cannot be applied to double[]
              > monthlyPayment = principal * rate/ (1.0 -
              > Math.pow(rate+1 ,-term));
              > ^
              > Wtest.java:13: cannot resolve symbol
              > symbol : variable monthlyPayment
              > location: class Wtest
              > System.out.prin tln(monthlyPaym ent);[/color]

              These are all the same errors as above
              [color=blue]
              >
              >
              > This is the file
              >
              > public class Wtest
              > {
              > public static void main (String[] args)
              > {
              > double principal = 2000000.0; // nice house!
              > double[] rate = { 5.35, 5.5, 5.75 };
              > double[] term = { 7.0, 15.0, 30.0 };
              > for (int i = 0; i < rate.length; ++i)
              >
              > rate = rate/1200.0;
              > term = term * 12;
              > monthlyPayment = principal * rate/ (1.0 -
              > Math.pow(rate+1 ,-term)); System.out.prin tln(monthlyPaym ent);
              > }
              >
              > }
              >[/color]

              Comment

              • pcbutts1

                #8
                Re: I need help

                I'm sorry but I am still lost. I think it's because I just don't know the
                commands or syntax or when or where to use them.

                --


                The best live web video on the internet http://www.seedsv.com/webdemo.htm
                NEW Embedded system W/Linux. We now sell DVR cards.
                See it all at http://www.seedsv.com/products.htm
                Sharpvision simply the best http://www.seedsv.com



                "ge0rge" <ge0rge@privacy .net> wrote in message
                news:46brgvFagi uhU1@individual .net...[color=blue]
                > pcbutts1 wrote:[color=green]
                >> I got the errors down to 7 from 12 when trying to compile. Can someone
                >> explain these error and how to fix them.[/color]
                > ...[color=green]
                >>
                >> public class Wtest
                >> {
                >> public static void main (String[] args)
                >> {
                >> double principal = 2000000.0; // nice house!
                >> double[] rate = { 5.35, 5.5, 5.75 };
                >> double[] term = { 7.0, 15.0, 30.0 };
                >> for (int i = 0; i < rate.length; ++i)
                >>
                >> rate = rate/1200.0;
                >> term = term * 12;
                >> monthlyPayment = principal * rate/ (1.0 -
                >> Math.pow(rate+1 ,-term));
                >> System.out.prin tln(monthlyPaym ent);
                >> }
                >>
                >> }[/color]
                >
                > Ok pcbutts1. Since you mentioned DOS, I figure you are no spring chicken
                > and therefore not a spotty kid too lazy to do the work. Assuming your
                > difficulty is genuine, here is my way of tackling this problem (to which
                > Eric Sosman has given a partial solution + java syntax) -
                >
                > thinking first
                > principal is 2,000,000
                > interest is 5.35% per annum
                > Therefore interest per year is 2000000 x .0535 = 107000
                > Total interest is 107000 x 7 = 749000
                > Therefore total to be repaid is 2000000 + 749000 = 2749000
                > number of months' repayment is 7 x 12 = 84
                > Thererefore monthly repayment is 32,726.20
                >
                > answer = ((2000000 * 0.0535 * 7) + 2000000)/(7 * 12)
                > Now, do a sanity check on the answer (perhaps on a calculator). If it
                > checks out replace it with the correct java syntax
                >
                > monthlyPayment = ((principal * (rate[i]/100) * term[i]) + principal) /
                > (term[i] * 12)
                >
                > Other things - brush up on arrays, the for statement, indent the code
                > correctly and figure out when to use double or integers, how to get the
                > correct display to 2 decimal places.
                >
                > I am too lazy to check your (1.0 - Math.pow(rate+1 ,-term)) for what it
                > means. The syntax is incorrect anyway but if the logic is correct, use it.
                > Otherwise do the code yourself.
                >
                > --
                > Why is the alphabet in that order? Is it because of that song?
                > -- Steven Wright[/color]


                Comment

                • Patricia Shanahan

                  #9
                  Re: I need help

                  pcbutts1 wrote:[color=blue]
                  > I'm sorry but I am still lost. I think it's because I just don't know the
                  > commands or syntax or when or where to use them.
                  >[/color]

                  Getting that lost feeling while learning a programming language often
                  means you need to take a step back.

                  Redo some earlier exercises. Do exercises from a book or on-line
                  tutorial. Go back to where you were comfortable, and work forward again
                  making sure you practice enough to get each point before going on to the
                  next thing.

                  Patricia

                  Comment

                  • Marc

                    #10
                    Re: I need help

                    Patricia Shanahan wrote:[color=blue]
                    > Getting that lost feeling while learning a programming language often
                    > means you need to take a step back.
                    >
                    > Redo some earlier exercises. Do exercises from a book or on-line
                    > tutorial. Go back to where you were comfortable, and work forward again
                    > making sure you practice enough to get each point before going on to the
                    > next thing.[/color]

                    Good advice, I recommend the Java 2 'for dummies' book, or even
                    Beginning program with Java for Dummies if you've never programmed before.


                    --
                    Marc
                    http://www.iMarc.co.uk/ for contact details.

                    Comment

                    • pcbutts1

                      #11
                      Re: I need help

                      I want to thank you guys for your help and hints, I got it working thanks.

                      --


                      The best live web video on the internet http://www.seedsv.com/webdemo.htm
                      NEW Embedded system W/Linux. We now sell DVR cards.
                      See it all at http://www.seedsv.com/products.htm
                      Sharpvision simply the best http://www.seedsv.com



                      "pcbutts1" <pcbutts1@seeds v.com> wrote in message
                      news:muidnfwvku WJk2PeRVn-uw@giganews.com ...[color=blue]
                      > Yes this is a homework assignment. My instructor has broken english and I
                      > just could not follow along last night. How do I do this
                      >
                      > Write the program in Java (without a graphical user interface) and have it
                      > calculate the payment amount for 3 mortgage loans:
                      >
                      > a.. 7 year at 5.35%
                      > b.. 15 year at 5.5%
                      > c.. 30 year at 5.75%
                      > Use an array for the different loans. Display the mortgage payment amount
                      > for each loan.
                      >
                      >
                      > My first one is below that works but how do I do the above
                      >
                      > public class wtest
                      > {
                      >
                      > public static void main (String[] args)
                      > {
                      > double principal =2000000.0;
                      > double rate =5.75;
                      > double term =30.0;
                      > double monthlyPayment =0.0;
                      >
                      > rate = rate/1200.0;
                      > term = term * 12;
                      > monthlyPayment = principal * rate/ (1.0 - Math.pow(rate+1 ,-term));
                      > System.out.prin tln(monthlyPaym ent);
                      > }
                      >
                      > }
                      >
                      >
                      > --
                      >
                      >
                      > The best live web video on the internet http://www.seedsv.com/webdemo.htm
                      > NEW Embedded system W/Linux. We now sell DVR cards.
                      > See it all at http://www.seedsv.com/products.htm
                      > Sharpvision simply the best http://www.seedsv.com
                      >
                      >
                      >
                      >[/color]


                      Comment

                      Working...