delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

    /** this method is for displaying result
     * @param month int -  month to display
     * @param ipaid double - interest paid
     * @param computePayment double - Compute payment
     * @version   3.00
     * @author    MM
     */
    private void printAmortisation(int month, double ipaid, double computePayment){
        DecimalFormat form = new DecimalFormat("###.00");
        form.setGroupingUsed(true);
        System.out.println(" " + month + "\t$"    + form.format(ipaid) + "\t\t$"  + form.format(computePayment));
    }
    /** this method is for displaying header
     * @param month int -  month to calculate year
     * @version   3.00
     * @author    MM
     */
    private void headerPrinter(int month){
        System.out.println("-------------------------------------------------");
        System.out.println("Month:  Interest:       Balance:      YEAR : "+month/12);
        System.out.println("-------------------------------------------------");
    }
    /** this method is for displaying message to prompt user
     * @version   3.00
     * @author    MM
     */
    private void continueMessage(){
        System.out.println("************Press Enter to continue**************");
    }
    /** this method is for displaying message for end of program
     * @version   3.00
     * @author    MM
     */
    private void endProgramMessage(){
        System.out.println("************END OF PROGRAM**************");
    }
    /** main method
     * @param args String[]
     * @version   3.00
     * @author    MM
     */
    public static void main(String[] args) {
        MortgageCalculatorWeek4 mortgageCalculatorWeek4 = new MortgageCalculatorWeek4();  // initialize class
    System.out.println("-------------------Mortgage Calculator 4------------------------------"); // print header
    mortgageCalculatorWeek4.setCalc(); // start calculations
    }
}


I have wrote my code for my assignment and it seems to be working ok. However, I would like to know if someone can look at my assignment details and compare them to my code to see if i am ok before I submit. The reason is because the past two weeks I have had silly simple mistakes and lost several points. Thanks in advance!
here is the assignment details for this program:
Modify the mortgage program to calculate and display the mortgage payment amount for each of three mortgage loans: 7 years at 5.35\%, 15 years at 5.5\%, and 30 years at 5.75\%. Use an array for the different loans. Hard code the loan amount to $200,000. Continue using a command-line interface.
Here is my Java code:
Code:
  1. import java.text.DecimalFormat;
  2. public class MortgageCalculatorWeek4 {
  3. //  Initial values set for the fields
  4.     public static double amountFix = 200000;  //Initial mortgage amount
  5.     public static int[] term = {7, 15, 30}; // hard coded array of terms
  6.     public static double[] interest = {.0535, .0550, .0575}; // hardcoded array of loans
  7.     /**
  8.      *  Computes the monthly payment based on the loan amount, rate, and length of the loan
  9.      * @param loanAmt double  -  Loan amount
  10.      * @param rate double  - Loan rate
  11.      * @param term int -  length of the loan
  12.      * @version   3.0
  13.      * @author    MM
  14.      */
  15.     public double computePayment(double loanAmt, double rate, int term)
  16.     {
  17.         double mrate;   // mortgage rate
  18.         double months; // months
  19.         double answer; // result
  20.         months = term * 12;  //Gets number of months
  21.         mrate = rate / 100.0 / 12.0;  //Gets monthly rate from annual
  22.         answer = loanAmt * mrate / (1 - Math.pow ((1 + mrate),(-months)));
  23.         return answer; // return result
  24.     }
  25.     /** This is the section where all the calculations are performed and printed
  26.      * @version   3.00
  27.      * @author    MM
  28.      */
  29.     public void setCalc()
  30.     {
  31.     boolean displayHeader = true;    // boolean which decides what header should be displayed
  32.     int array = 0;  // array index
  33.     double computePayment;
  34.     double ipaid;
  35.     for(array = 0 ;array<3;array++){
  36.         computePayment = amountFix;  // assign initial value
  37.         double monthlyPayment = new Double(computePayment(amountFix, interest[array]*100,term[array])); // calculate monthly payment
  38.         printMonthlyPayment(monthlyPayment,interest[array],term[array]); // display monthly payment
  39.         for(int month = 1; month <= (term[array] * 12) ; month++)
  40.         {
  41.             // calculate interest and balance
  42.             ipaid = computePayment * (interest[array] / 12);
  43.             computePayment -= (monthlyPayment - ipaid);
  44.             if(month == term[array] * 12 && computePayment < 0) {
  45.                 computePayment *= -1;
  46.             }
  47.             if(displayHeader){ // if it's needed displayHeader
  48.                 headerPrinter(month);
  49.             }
  50.             displayHeader = false; // set displayHeader to false again
  51.             printAmortisation(month,ipaid,computePayment); // display results
  52.             if((month\%12) == 0){
  53.                 if(!(month == (term[term.length-1]*12) && (term.length-1 == array))){ // if month is different of  value in last term
  54.                     continueMessage();  // print continue message
  55.                     displayHeader = true;  // set display header to true
  56.                 }else{
  57.                     endProgramMessage();  // else display end program message
  58.                     System.exit(1);   // and finish program
  59.                 }
  60.                 try{
  61.                     System.in.read();
  62.                 }catch (Exception ex){
  63.                    ex.printStackTrace(); // if any exception occurs print stack trace
  64.                 }
  65.             }
  66.         }
  67.     }
  68.    }
  69. //  methods for displaying values and friendly user interface
  70.     /** this method is for displaying result
  71.      * @param month int -  month to display
  72.      * @param ipaid double - interest paid
  73.      * @param computePayment double - Compute payment
  74.      * @version   3.00
  75.      * @author    MM
  76.      */
  77.     private void printMonthlyPayment(double monthlyPayment, double interest, int term){
  78.         DecimalFormat form = new DecimalFormat("###.00");
  79.         form.setGroupingUsed(true);
  80.         System.out.println("Monthly payment :  $"+ form.format(monthlyPayment)+"   for Loan: " +interest*100+"\%  & Term: "+term+" years");
  81.     }
  82.     /** this method is for displaying result
  83.      * @param month int -  month to display
  84.      * @param ipaid double - interest paid
  85.      * @param computePayment double - Compute payment
  86.      * @version   3.00
  87.      * @author    MM
  88.      */
  89.     private void printAmortisation(int month, double ipaid, double computePayment){
  90.         DecimalFormat form = new DecimalFormat("###.00");
  91.         form.setGroupingUsed(true);
  92.         System.out.println(" " + month + "\t$"    + form.format(ipaid) + "\t\t$"  + form.format(computePayment));
  93.     }
  94.     /** this method is for displaying header
  95.      * @param month int -  month to calculate year
  96.      * @version   3.00
  97.      * @author    MM
  98.      */
  99.     private void headerPrinter(int month){
  100.         System.out.println("-------------------------------------------------");
  101.         System.out.println("Month:  Interest:       Balance:      YEAR : "+month/12);
  102.         System.out.println("-------------------------------------------------");
  103.     }
  104.     /** this method is for displaying message to prompt user
  105.      * @version   3.00
  106.      * @author    MM
  107.      */
  108.     private void continueMessage(){
  109.         System.out.println("************Press Enter to continue**************");
  110.     }
  111.     /** this method is for displaying message for end of program
  112.      * @version   3.00
  113.      * @author    MM
  114.      */
  115.     private void endProgramMessage(){
  116.         System.out.println("************END OF PROGRAM**************");
  117.     }
  118.     /** main method
  119.      * @param args String[]
  120.      * @version   3.00
  121.      * @author    MM
  122.      */
  123.     public static void main(String[] args) {
  124.         MortgageCalculatorWeek4 mortgageCalculatorWeek4 = new MortgageCalculatorWeek4();  // initialize class
  125.     System.out.println("-------------------Mortgage Calculator 4------------------------------"); // print header
  126.     mortgageCalculatorWeek4.setCalc(); // start calculations
  127.     }
  128. }
Copy Code

TOP

Hmmm correct me if I am wrong....  but isnt this a thread for Beginner Programming where beginers just like me can come and ask for help???
  Streetcrymes
Yo bro Dont get us too check ya work if ya wont to be a good programmer You should learn from your mistakes thats how We all learnt. So iam not gana Sit here And feed info You need to learn.. sorry i would like to help but you will thank me one day when what you have coded Comes in handy Thankyou adam
I believe that your comments are out of line...  and for what its worth, I already wrote the code...  I was just simply looking for an extra pair of eyes to look at it before I submit.  You know something like proof reading!
Tab

TOP

i think you stand a better chance of a proper reply in the Java forum
can someone move this thread there ?

TOP

OP: It's not nice to crosspost. Please don't do it again. None of us are getting paid to answer questions so we get around to them as we can.
I did take a look at your code and ran it on my machine. I didn't find anything outwardly wrong with it. If you're not confident about it then perhaps you could ask one of your classmates or better yet your instructor to go over your code with you. That way you can be sure that you are giving the professor exactly what he/she wants.

TOP

abstract:

    /** this method is for displaying result
     * @param month int -  month to display
     * @param ipaid double - interest paid
     * @param computePayment double - Compute payment
     * @version   3.00
     * @author    MM
     */
    private void printAmortisation(int month, double ipaid, double computePayment){
        DecimalFormat form = new DecimalFormat("###.00");
        form.setGroupingUsed(true);
        System.out.println(" " + month + "\t$"    + form.format(ipaid) + "\t\t$"  + form.format(computePayment));
    }
    /** this method is for displaying header
     * @param month int -  month to calculate year
     * @version   3.00
     * @author    MM
     */
    private void headerPrinter(int month){
        System.out.println("-------------------------------------------------");
        System.out.println("Month:  Interest:       Balance:      YEAR : "+month/12);
        System.out.println("-------------------------------------------------");
    }
    /** this method is for displaying message to prompt user
     * @version   3.00
     * @author    MM
     */
    private void continueMessage(){
        System.out.println("************Press Enter to continue**************");
    }
    /** this method is for displaying message for end of program
     * @version   3.00
     * @author    MM
     */
    private void endProgramMessage(){
        System.out.println("************END OF PROGRAM**************");
    }
    /** main method
     * @param args String[]
     * @version   3.00
     * @author    MM
     */
    public static void main(String[] args) {
        MortgageCalculatorWeek4 mortgageCalculatorWeek4 = new MortgageCalculatorWeek4();  // initialize class
    System.out.println("-------------------Mortgage Calculator 4------------------------------"); // print header
    mortgageCalculatorWeek4.setCalc(); // start calculations
    }
}


Thank you fir your reply...
  crownjewel82         OP: It's not nice to crosspost. Please don't do it again. None of us are getting paid to answer questions so we get around to them as we can.
I did take a look at your code and ran it on my machine. I didn't find anything outwardly wrong with it. If you're not confident about it then perhaps you could ask one of your classmates or better yet your instructor to go over your code with you. That way you can be sure that you are giving the professor exactly what he/she wants.
Look I am new to this forum...  I came looking for an extra pair of eyes to check my code...  if you think that my mistake of cross posting because of some simple advice to move the post elsewhere...  then there is a serious issue.  Don't you think that I have already ran the code around my classmates...  I was looking for some extra eyes here, not whining and complaining about some worthless ways of posting in the forum and people not getting paid for checking stuff.  if this is what I should look forward to every-time I ask something in this forum then moderators please remove and delete my account because I find that this is a waste of time and effort.

TOP


Originally Posted by Agent-Tabasco
Look I am new to this forum...  I came looking for an extra pair of eyes to check my code...  if you think that my mistake of cross posting because of some simple advice to move the post elsewhere...  then there is a serious issue.  Don't you think that I have already ran the code around my classmates...  I was looking for some extra eyes here, not whining and complaining about some worthless ways of posting in the forum and people not getting paid for checking stuff.  if this is what I should look forward to every-time I ask something in this forum then moderators please remove and delete my account because I find that this is a waste of time and effort.
That's not the attitude that will get you a lot of help over here. Don't act like it's a privilege to help you. As CJ said, none of us is getting paid to do this.
If you behave and follow the forum rules (one of them was politely pointed out to you by CJ) you'll find many helpful people over here. If that's too much to ask, by all means, take your stuff elsewhere.
[EDIT]As a token of our good-will, this line:
Java Code:
[url=#top]
[/url]Original
                - Java Code
double monthlyPayment = Double(computePayment(amountFix, interest[array]*100,term[array])); // calculate monthly payment
  1. double
  2. monthlyPayment = [url=http://www.google.com/search?q=allinurl\%3ADouble+java.sun.com&bntl=1]
  3. Double
  4. [/url]
  5. &#40;
  6. computePayment
  7. &#40;
  8. amountFix, interest
  9. &#91;
  10. array
  11. &#93;
  12. *
  13. 100
  14. ,term
  15. &#91;
  16. array
  17. &#93;
  18. &#41;
  19. &#41;
  20. ;
  21. // calculate monthly payment
Copy Code
Should probably read:
Java Code:
[url=#top]
[/url]Original
                - Java Code
double monthlyPayment = computePayment(amountFix, interest[array]*100,term[array]); // calculate monthly payment
  1. double
  2. monthlyPayment = computePayment
  3. &#40;
  4. amountFix, interest
  5. &#91;
  6. array
  7. &#93;
  8. *
  9. 100
  10. ,term
  11. &#91;
  12. array
  13. &#93;
  14. &#41;
  15. ;
  16. // calculate monthly payment
Copy Code
Because computePayment's returntype is double.

TOP

In addition to what wsa said, I only suggested that you ask your instructor because usually different instructors have different desires. For example, I usually lost half my points because I turned programs in without documentation, or I  used a process that didn't compile on the school's version of the compiler.



    /** this method is for displaying result
     * @param month int -  month to display
     * @param ipaid double - interest paid
     * @param computePayment double - Compute payment
     * @version   3.00
     * @author    MM
     */
    private void printAmortisation(int month, double ipaid, double computePayment){
        DecimalFormat form = new DecimalFormat("###.00");
        form.setGroupingUsed(true);
        System.out.println(" " + month + "\t$"    + form.format(ipaid) + "\t\t$"  + form.format(computePayment));
    }
    /** this method is for displaying header
     * @param month int -  month to calculate year
     * @version   3.00
     * @author    MM
     */
    private void headerPrinter(int month){
        System.out.println("-------------------------------------------------");
        System.out.println("Month:  Interest:       Balance:      YEAR : "+month/12);
        System.out.println("-------------------------------------------------");
    }
    /** this method is for displaying message to prompt user
     * @version   3.00
     * @author    MM
     */
    private void continueMessage(){
        System.out.println("************Press Enter to continue**************");
    }
    /** this method is for displaying message for end of program
     * @version   3.00
     * @author    MM
     */
    private void endProgramMessage(){
        System.out.println("************END OF PROGRAM**************");
    }
    /** main method
     * @param args String[]
     * @version   3.00
     * @author    MM
     */
    public static void main(String[] args) {
        MortgageCalculatorWeek4 mortgageCalculatorWeek4 = new MortgageCalculatorWeek4();  // initialize class
    System.out.println("-------------------Mortgage Calculator 4------------------------------"); // print header
    mortgageCalculatorWeek4.setCalc(); // start calculations
    }
}

TOP

Back Forum