Debugging Assignment, Chapter 3, Bert,java

Java Programming Third Edition Complete Concepts and Techniques

/*

Chapter 3 Debugging Assignment

Programmer:

Date:

Program Name: Bert,java

Purpose:

*/

import java.io.*;

public class Bert

{

public static void main(String[] args) throws IOException

{

BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));

//Declaring Variables

int price, downpayment, tradeIn, months,loanAmt, interest;

double annualInterest, payment;

String custName, inputPrice,inputDownPayment,inputTradeIn,inputMonths, inputAnnualInterest;

//Get Input from User

System.out.println("What is your name?");

custName = dataIn.readLine();

System.out.print("What is the price of the car?");

inputPrice = dataIn.readLine();

System.out.print("What is the downpayment?");

inputDownPayment = dataIn.readLine();

System.out.print("What is the trade-in value?");

inputTradeIn = dataIn.readLine();

System.out.print("For how many months is the loan?");

inputMonths = dataIn.readLine();

System.out.print("What is the decimal interest rate?");

inputAnnualInterest = dataIn.readLine();

//Conversions

price = Integer.parseInt(inputPrice);

downpayment = Integer.parseInt(inputDownPayment);

tradeIn = Integer.parseInt(inputTradeIn);

months = Integer.parseInt(inputMonths);

annualInterest =Double.parseDouble(inputAnnualInterest);

//Calculations

payment=loanAmt/((1/interest)-(1/(interest*Math.round(1+ inputMonths))));

//Output

System.out.print("The monthly payment for " + custName + " is $");

System.out.println((int)payment);

;

}

}

I have a problem in this calculation:

payment=loanAmt/((1/interest)-(1/(interest*Math.round(1+ inputMonths))));

Can somebody helpme?

[1932 byte] By [tito_elcarniceroa] at [2007-11-26 12:22:25]
# 1

Try this modified code.

import java.io.*;

public class Bert

{

public static void main(String[] args) throws IOException

{

BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));

//Declaring Variables

int price, downpayment, tradeIn, months,loanAmt=0, interest =0;

double annualInterest, payment;

String custName, inputPrice,inputDownPayment,inputTradeIn,inputMonths, inputAnnualInterest;

//Get Input from User

System.out.println("What is your name?");

custName = dataIn.readLine();

System.out.print("What is the price of the car?");

inputPrice = dataIn.readLine();

System.out.print("What is the downpayment?");

inputDownPayment = dataIn.readLine();

System.out.print("What is the trade-in value?");

inputTradeIn = dataIn.readLine();

System.out.print("For how many months is the loan?");

inputMonths = dataIn.readLine();

System.out.print("What is the decimal interest rate?");

inputAnnualInterest = dataIn.readLine();

//Conversions

price = Integer.parseInt(inputPrice);

downpayment = Integer.parseInt(inputDownPayment);

tradeIn = Integer.parseInt(inputTradeIn);

months = Integer.parseInt(inputMonths);

annualInterest =Double.parseDouble(inputAnnualInterest);

//Calculations

payment=loanAmt/((1/interest)-(1/(interest*Math.round(1+ months))));

//Output

System.out.print("The monthly payment for " + custName + " is $");

System.out.println((int)payment);

;

}

}

harishotya at 2007-7-7 15:15:40 > top of Java-index,Archived Forums,Socket Programming...
# 2

this calculation

payment=loanAmt/((1/interest)-(1/(interest*Math.round(1+ inputMonths))));

uses things that are not defined.

it seems u have to do some extra work to get this calculation done.

think about calculating loanAmt and using some other data(available in ur code) instead of interest and inputMonths

EKTa at 2007-7-7 15:15:40 > top of Java-index,Archived Forums,Socket Programming...
# 3
THANKS BRO
tito_elcarniceroa at 2007-7-7 15:15:40 > top of Java-index,Archived Forums,Socket Programming...
# 4
thing is that Math.round has the following syntaxMath.round(double a) Returns closest long to the argumentMath.round(float a) Returns closest int to the argumentAnd you have string as argumentMessage was edited by: Mithu
Mithua at 2007-7-7 15:15:40 > top of Java-index,Archived Forums,Socket Programming...