dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help

  1. #1
    Join Date
    Apr 2011
    Posts
    4

    Help

    Ok, I'm really new at the whole java thing...and I need some help with this assignment. So people don't think that I'm trying to get people to do the work for me, I've included the code as I've written it thus far. It works, but I know it isn't quite what the assignment is calling for. I appreciate any help that people can provide on how to do this. Please keep in mind I'm brand new to Java.

    Here is the assignment description:

    Create a Mortgage application that calculates the monthly payment of a mortgage. The application uses a class to store the cost of the mortgage amount, the interest rate and the number of years for the life of the mortgage. These should all be required fields, so include a check to make sure each variable is populated. Throw an error if the variable is empty and inform the user that they must populate the value. Also, allow the user to re-enter the value. Display the mortgage amount, interest rate, number of years and calculates the monthly mortgage payment.

    Here is my code:


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    import java.util.Scanner;

    package it215mortcalc1;

    /**
    *
    * @author Ben
    */
    public class Main {

    /**
    * @param args the command line arguments
    */

    public static void main(String[] args) {
    Scanner mortgagecalc = new Scanner(System.in);
    double loanAmount, interestRate, lifeOfLoan, numberOfPayments, answer;

    System.out.println("Please enter the amount of the loan: $");
    loanAmount = mortgagecalc.nextDouble();
    System.out.println();

    System.out.println("Please enter the interest rate: %");
    interestRate = mortgagecalc.nextDouble();
    System.out.println();

    System.out.println("Please enter the life of the loan: ");
    lifeOfLoan = mortgagecalc.nextDouble();
    System.out.println();

    System.out.println("Please enter the number of payments: ");
    numberOfPayments = mortgagecalc.nextDouble();
    System.out.println();

    answer = loanAmount * interestRate / numberOfPayments;
    System.out.println("$" + answer + " monthly payment amount");
    System.out.println();

    System.out.println("$" + loanAmount + " is your starting loan amount");
    System.out.println();

    System.out.println("%" + interestRate + " annual interest rate");
    System.out.println();

    System.out.println(lifeOfLoan + " total years in loan");
    System.out.println();

    System.out.println(numberOfPayments + " total number of payments");
    System.out.println();


    }
    }//end main class

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Help

    Is this the same question as your other post?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help

    Post code in CODE tags (see my sig) so we can read it.

    Quote Originally Posted by SplinteredChaos View Post
    It works, but I know it isn't quite what the assignment is calling for.
    If you know what the assignment is calling for, why didn't you write it like that? and why can't you make it what's required now?

    Exactly what are you stuck on?

    It is easier to measure something than to understand what you have measured...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)