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

Thread: The code work the output different what it could be please help

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question The code work the output different what it could be please help

    My code seems to work with allowing me to enter my all the data that I ask for. But the out put should something different. I am student and new at this would like some help. I made CAR LOAN CALCULATOR and it work be said this Loan Amount: $12000.0 ,Annual Interest Rate: % 5.6, Monthly Payment: $203.02, Total Payments: $14000.0 but should said Loan Amount: $12000.0, Annual Interest Rate: % 5.60, Monthly Payment: $229.77, Total Payments: $15786.09. And the in put should be Total Costs: 14000,Down Payment: 2000, Number of Years: 5, Credit Score of Applicant: 710. Please help

    // 	Scanner input = new Scanner(System.in);
    public static void main(String[] args)
    {
    import java.util.Scanner;
     
    	// Create a Scanner
    	Scanner input = new Scanner(System.in);
    	public static void main(String[] args) {
    		// Create a Scanner
    		Scanner input = new Scanner(System.in);
    	// Total Cost delcaire and setup print out statements
    			System.out.print("Enter totalCost: ");
    			double totalCost = input.nextDouble();
     
    			// Down Payments delcaire and setup print out statements
    			System.out.print("Enter DownPayments: ");
    			double downPayment = input.nextDouble();
     
    			// number of Years delcaire and setup print out statements
    			System.out.print("Enter number of Years:");
    			int numberOfYears = input.nextInt();
     
    			// Credit Score delcaire and setup print out statements
    			System.out.print("Enter Credit Score of Applicant:");
    			double creditScore = input.nextDouble();
     
    			// other need to be delcaire
    			double loanAmount;
    			double monthlyPayment;
    			int numberOfMonths = ++numberOfYears;
    			double totalPayments;
    			double annualInterestRatePercentage;
    			double monthlyInterestRate;
     
    			// Create the Formulas
     
    			// Calculate loan Amount
    			loanAmount = totalCost - downPayment;
    			// Calculate Monthly Payment
    			monthlyPayment = loanAmount / numberOfMonths;
    			// Calculate Total Payments
    			totalPayments = monthlyPayment * numberOfMonths + downPayment;
    			//Calculate Annual Interest Rate Percentage
    			annualInterestRatePercentage = 34 - creditScore/25.0;
    			//Calculate Monthly Interest Rate with Annual Interest Rate Percentage
    			monthlyInterestRate = annualInterestRatePercentage / 1200;
     
    			//Calculate the Monthly Payment with Math.pow
    			monthlyPayment = (loanAmount * monthlyInterestRate * Math.pow(
    					1 + monthlyInterestRate, numberOfMonths))
    					/ (Math.pow(1 + monthlyInterestRate, numberOfMonths) - 1);
     
    			// Display results
    			System.out.println("Loan Amount: $" + (int) (loanAmount * 100) / 100.00);
     
    			System.out.println("Annual Interest Rate: % " + (int) (annualInterestRatePercentage  * 100)	/ 100.00);
     
    			System.out.println("Monthly Payment: $" + (int) (monthlyPayment * 10)	/ 100.00);
     
    			System.out.println("Total Payments: $" + (int) (totalPayments * 100)/ 100.00);
     
    			// close the scanner
    			input.close();
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: The code work the output different what it could be please help

    the out put should something different
    Can you post the program's current output (the red text in a paragraph is hard to read and see what is wrong) and some comments saying what is wrong with it and show what it should be?

    The posted code will not compile without errors.
    Please make sure you post code without errors
    or post the error messages if you need help with them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The code work the output different what it could be please help

    Quote Originally Posted by Norm View Post
    Can you post the program's current output (the red text in a paragraph is hard to read and see what is wrong) and some comments saying what is wrong with it and show what it should be?

    The posted code will not compile without errors.
    Please make sure you post code without errors
    or post the error messages if you need help with them.
    out put.jpg

    Here is the output the program give me be it need to be Loan Amount : 12000.00, Annual Interest Rate: 5.60 %, Monthly Payment: 229.77,
    Total Payments: 15786.09, but I am at lost to do that and there is not errors.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: The code work the output different what it could be please help

    there is not errors.
    Please post the code you have that does not have errors. The posted code has many errors.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The code work the output different what it could be please help

    Quote Originally Posted by Norm View Post
    Please post the code you have that does not have errors. The posted code has many errors.
     
    import java.util.Scanner;
    public class Assignment1 {
    // Create a Scanner
    Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
    // Create a Scanner
    Scanner input = new Scanner(System.in);
    // Total Cost delcaire and setup print out statements
    System.out.print("Enter totalCost: ");
    double totalCost = input.nextDouble();

    // Down Payments delcaire and setup print out statements
    System.out.print("Enter DownPayments: ");
    double downPayment = input.nextDouble();

    // number of Years delcaire and setup print out statements
    System.out.print("Enter number of Years:");
    int numberOfYears = input.nextInt();

    // Credit Score delcaire and setup print out statements
    System.out.print("Enter Credit Score of Applicant:");
    double creditScore = input.nextDouble();

    // other need to be delcaire
    double loanAmount;
    double monthlyPayment;
    int numberOfMonths = ++numberOfYears;
    double totalPayments;
    double annualInterestRatePercentage;
    double monthlyInterestRate;

    // Create the Formulas

    // Calculate loan Amount
    loanAmount = totalCost - downPayment;
    // Calculate Monthly Payment
    monthlyPayment = loanAmount / numberOfMonths;
    // Calculate Total Payments
    totalPayments = monthlyPayment * numberOfMonths + downPayment;
    //Calculate Annual Interest Rate Percentage
    annualInterestRatePercentage = 34 - creditScore/25.0;
    //Calculate Monthly Interest Rate with Annual Interest Rate Percentage
    monthlyInterestRate = annualInterestRatePercentage / 1200;

    //Calculate the Monthly Payment with Math.pow
    monthlyPayment = (loanAmount * monthlyInterestRate * Math.pow(
    1 + monthlyInterestRate, numberOfMonths))
    / (Math.pow(1 + monthlyInterestRate, numberOfMonths) - 1);

    // Display results
    System.out.println("Loan Amount: $" + (int) (loanAmount * 100) / 100.00);

    System.out.println("Annual Interest Rate: % " + (int) (annualInterestRatePercentage * 100) / 100.00);

    System.out.println("Monthly Payment: $" + (int) (monthlyPayment * 10) / 100.00);

    System.out.println("Total Payments: $" + (int) (totalPayments * 100)/ 100.00);

    // close the scanner
    input.close();
    }
    }



  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: The code work the output different what it could be please help

    Please edit your post and fix the formatting of the code. It has lost the indentations.

    Have you posted the program's output
    and the desired output?

    Copy it from the console exactly as the program prints it, don't put it in a string in a paragraph. It should be exactly as is printed.

    For example:
    Output:
    xxx
    yyyyyy
    zz
    Desired:
    xx1
    yyyy
    z2
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. why my code does not work ?? ://
    By without name in forum What's Wrong With My Code?
    Replies: 13
    Last Post: May 6th, 2014, 02:35 PM
  3. how to get output for this ajax using code. Code is shown bellow.
    By pragathi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 4th, 2014, 04:51 AM
  4. Help me I am trying to get this code to work.
    By Leonardo1143 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 26th, 2013, 06:41 PM
  5. please tell me why this code does not work
    By amr in forum Java Theory & Questions
    Replies: 9
    Last Post: December 6th, 2010, 05:46 PM