Click here to Skip to main content
15,890,741 members
Home / Discussions / Java
   

Java

 
Questioncalendar and reservation Pin
donaldchristian9-Mar-09 0:11
donaldchristian9-Mar-09 0:11 
AnswerRe: calendar and reservation Pin
Nagy Vilmos9-Mar-09 23:37
professionalNagy Vilmos9-Mar-09 23:37 
Questionclock Pin
donaldchristian9-Mar-09 0:09
donaldchristian9-Mar-09 0:09 
AnswerRe: clock Pin
fly9049-Mar-09 0:26
fly9049-Mar-09 0:26 
AnswerRe: clock Pin
mukulrajput19926-Mar-13 0:29
mukulrajput19926-Mar-13 0:29 
QuestionDigital Image Detection Pin
nasiraftab8-Mar-09 21:32
nasiraftab8-Mar-09 21:32 
AnswerRe: Digital Image Detection Pin
Nagy Vilmos9-Mar-09 23:38
professionalNagy Vilmos9-Mar-09 23:38 
QuestionTrouble with my loop ~I think Pin
Bactos8-Mar-09 11:35
Bactos8-Mar-09 11:35 
Hi am new to Java and programming in general. I have been trying to work on a project for school of which I have already posted ( a horrible version of the "program") though would just like to understand what I have done wrong. I don't like not knowing how to do stuff...

here is what I have posted :

/*
Write the program in Java (without a graphical user interface)
using a loan amount of $200,000 with an interest rate of 5.75% and
a 30 year term. Display the mortgage payment amount and then list the
loan balance and interest paid for each payment over the term of the loan.
If the list would scroll off the screen, use loops to display a partial list,
hesitate, and then display more of the list.
*/

package cr1;
import java.text.DecimalFormat;
/**
*
* @author
*/
public class CR1 {


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

public static void main(String[] args) {
DecimalFormat dollarAmount = new DecimalFormat("0.00");

double loan_amount = 200000.00;
int years = 30;
// calculation number of payments
int number_of_payments = years*12;

double intrest_rate = 5.75;
double monthly_intrest_rate = intrest_rate/100/12; // calculates monthly inrest rate



// monthly payment

double monthly_payment = monthly_intrest_rate/(1 - Math.pow(1+monthly_intrest_rate,-number_of_payments)) * loan_amount;

double ipaid = monthly_payment * .0575;
int paymentnumber = 0;


int payCounter = 0;
int pCounter = 0;
double loanbalance = loan_amount - number_of_payments;


while (loanbalance > 0) //


if (payCounter == 0)


{
System.out.println("Starting loan balance: $" + dollarAmount.format(loan_amount));
System.out.println("");

payCounter += 1;
pCounter += 1;
}

else
{


System.out.println("Payment Number:" + payCounter);
System.out.println("Monthly Payment:$"+dollarAmount.format (monthly_payment));
System.out.println("Loan Balance: $" +dollarAmount.format (loanbalance));
System.out.println("Intrest Paid:$ " +dollarAmount.format (ipaid));



loanbalance = loanbalance - monthly_payment;
payCounter ++;
pCounter += 1;


}



if (pCounter ==9 )
{


try
{
Thread.sleep(200000);
pCounter = 0;
}
catch(InterruptedException CR1)
{

// message prints with Java-generated data
}
}


else
{
System.out.println("Than you for using Billy Bakers Program. Have a good DAY!!!");
System.exit(0);
}
}
}







Though I know it is not outputting the information the right way..it is supposed to have 360 payments and its not. I don't know if there is a problem with my math, loop or both. Could someone explain to me what mine eyes cant ?


Thank you very much,

Bactos

AnswerRe: Trouble with my loop ~I think Pin
fly9049-Mar-09 0:34
fly9049-Mar-09 0:34 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 6:52
Bactos9-Mar-09 6:52 
GeneralRe: Trouble with my loop ~I think Pin
fly9049-Mar-09 9:30
fly9049-Mar-09 9:30 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 11:19
Bactos9-Mar-09 11:19 
GeneralRe: Trouble with my loop ~I think Pin
fly9049-Mar-09 12:06
fly9049-Mar-09 12:06 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 14:41
Bactos9-Mar-09 14:41 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 15:33
Bactos9-Mar-09 15:33 
AnswerRe: Trouble with my loop ~I think Pin
Reagan Conservative9-Mar-09 9:03
Reagan Conservative9-Mar-09 9:03 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 11:33
Bactos9-Mar-09 11:33 
GeneralRe: Trouble with my loop ~I think Pin
Bactos9-Mar-09 15:34
Bactos9-Mar-09 15:34 
Questionconversion of a color image into a black white image Pin
sudipkumar036-Mar-09 22:23
sudipkumar036-Mar-09 22:23 
JokeRe: conversion of a color image into a black white image Pin
fly9047-Mar-09 8:38
fly9047-Mar-09 8:38 
GeneralRe: conversion of a color image into a black white image Pin
sudipkumar0316-Mar-09 20:12
sudipkumar0316-Mar-09 20:12 
AnswerRe: conversion of a color image into a black white image Pin
fly9047-Mar-09 8:42
fly9047-Mar-09 8:42 
QuestionRead Incoming SMS Pin
Nitharshan6-Mar-09 19:34
Nitharshan6-Mar-09 19:34 
RantRe: Read Incoming SMS Pin
fly9047-Mar-09 9:04
fly9047-Mar-09 9:04 
Questionusing COM objects from Java that runs on SUN Java VM under MS platforms Pin
Varghese Paul M6-Mar-09 16:12
Varghese Paul M6-Mar-09 16:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.