// This is the Debts program in Java
import java.io.*;
class Debts {
public static void main(String[] args) throws IOException{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String Amount, Payable, Interest, Paid;
double Value, Rate, Spent; int Years;
System.out.print("Enter Amount: ");
Amount=stdin.readLine();
Value=Double.parseDouble(Amount);
System.out.print("Enter Payable in years: ");
Payable=stdin.readLine();
Years=Integer.parseInt(Payable);
System.out.print("Enter Intrest Rate: ");
Interest=stdin.readLine();
Rate=Double.parseDouble(Amount);
for (int i = 1; i <=Years; i = i+1) {
System.out.println("year"+ i + " paid: ");
Paid=stdin.readLine();
Spent=Double.parseDouble(Paid);

}
if(Spent>Amount)
System.out.println("lo"); // Finish the line
}
}

Scenario: I already have the for loop there running but my problem is this... for example I tried to enter 5000 then payable in years(this was the for loop... the payable in years) rate is in 5% then i want to do the checking if(Spent> Amount) but the problem can I total all the values I inputed in the for loop???
If it can pls Help me.

// This is the Debts program in Java
import java.io.*;
class Debts {
public static void main(String[] args) throws IOException{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String Amount, Payable, Interest, Paid;
double Value, Rate, Spent; int Years;
System.out.print("Enter Amount: ");
Amount=stdin.readLine();
Value=Double.parseDouble(Amount);
System.out.print("Enter Payable in years: ");
Payable=stdin.readLine();
Years=Integer.parseInt(Payable);
System.out.print("Enter Intrest Rate: ");
Interest=stdin.readLine();
Rate=Double.parseDouble(Amount);
for (int i = 1; i <=Years; i = i+1) {
System.out.println("year"+ i + " paid: ");
Paid=stdin.readLine();
Spent=Double.parseDouble(Paid);

}
if(Spent>Amount)
System.out.println("lo"); // Finish the line
}
}

Scenario: I already have the for loop there running but my problem is this... for example I tried to enter 5000 then payable in years(this was the for loop... the payable in years) rate is in 5% then i want to do the checking if(Spent> Amount) but the problem can I total all the values I inputed in the for loop???
If it can pls Help me.

I think you first need to very precisely define exactly what you are trying to do. From that, name your variables in a very precise manner and change the syntax of the questions to be more precise. The phrasing of the questions and the variable names are too loose for any type of loan/interest calculation. So you need to understand precisely what the goal is, what the loan terms are, and what each variable represents, and the user needs to know exactly what his/her input should be. In particular, what is the data inputted and what is calculated by the program? You appear to be making no calculations.

I think you first need to very precisely define exactly what you are trying to do. From that, name your variables in a very precise manner and change the syntax of the questions to be more precise. The phrasing of the questions and the variable names are too loose for any type of loan/interest calculation. So you need to understand precisely what the goal is, what the loan terms are, and what each variable represents, and the user needs to know exactly what his/her input should be. In particular, what is the data inputted and what is calculated by the program? You appear to be making no calculations.

uhmmm

my point here is this... How could I calculate all of the inputs in the "("year"+i"paid")"?

I think you first need to very precisely define exactly what you are trying to do. From that, name your variables in a very precise manner and change the syntax of the questions to be more precise. The phrasing of the questions and the variable names are too loose for any type of loan/interest calculation. So you need to understand precisely what the goal is, what the loan terms are, and what each variable represents, and the user needs to know exactly what his/her input should be. In particular, what is the data inputted and what is calculated by the program? You appear to be making no calculations.

By the way I'm started to calculate the Interest per year and so on which I do not include here

uhmmm

my point here is this... How could I calculate all of the inputs in the "("year"+i"paid")"?

There are all sorts of math formulas, but they all require a firm understanding of the terms on the loan. You have this question here:

Enter Payable in years:

which suggests you have a starting loan amount, an interest rate (how often is interest compounded? Monthly? You need to know), and the length of the loan, and from that you need to calculate the monthly (or yearly) payment. For that, you cannot use a loop. I'll reiterate. What is known, what is to be inputted by the user, what are the terms of the loan, what is to be calculated? You need to know all of this before you can proceed.

There are all sorts of math formulas, but they all require a firm understanding of the terms on the loan. You have this question here:

which suggests you have a starting loan amount, an interest rate (how often is interest compounded? Monthly? You need to know), and the length of the loan, and from that you need to calculate the monthly (or yearly) payment. For that, you cannot use a loop. I'll reiterate. What is known, what is to be inputted by the user, what are the terms of the loan, what is to be calculated? You need to know all of this before you can proceed.

// This is the Hello program in Java
import java.io.*;
 class Loan {
	 public static void main(String[] args) throws IOException{
     BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
     String Amount, Payable, Interest, Paid;
     double Value, Rate, Spent, SpentMoney, TotalSpentMoney; int Years; 
        System.out.print("Enter Amount: ");
         Amount=stdin.readLine();
         Value=Double.parseDouble(Amount);	
        System.out.print("Enter Payable in years: ");
         Payable=stdin.readLine();
         Years=Integer.parseInt(Payable);
        System.out.print("Enter Intrest Rate: ");
         Interest=stdin.readLine();
         Rate=Double.parseDouble(Amount);			 
	     for (int i = 1;  i <=Years;  i = i+1)  {    
          System.out.println("year"+ i + " paid: "); 
		  Paid=stdin.readLine();
		  Spent=Double.parseDouble(Paid);
		  SpentMoney += Spent;
		  
         }
		 //TotalSpentMoney=Spent+SpentMoney;
          if(SpentMoney > Amount){
		  
             System.out.println("You paid above the Amount");}
		  else{
		  Rate=Rate/100;
     System.out.println("Interest per year is "+Rate*Value);  // Finish the line
  }
  }

I tried it my own ... but the problem here is in if statement.. it always relases the elase block no matter what is the logic in if... pls help me what's wrong here... uhh the if else block for the meanwhile is to check the logic. if the Spent is greater than amount it wil say "You paid above the amount"

There are all sorts of math formulas, but they all require a firm understanding of the terms on the loan. You have this question here:

which suggests you have a starting loan amount, an interest rate (how often is interest compounded? Monthly? You need to know), and the length of the loan, and from that you need to calculate the monthly (or yearly) payment. For that, you cannot use a loop. I'll reiterate. What is known, what is to be inputted by the user, what are the terms of the loan, what is to be calculated? You need to know all of this before you can proceed.

the interest was per year

Okay, looks like you are NOT calculating a loan or a monthly payment. That's fine. My point earlier is that you should try to be as descriptive as possible so people know what the program does, what it assumes, and what it is asking the user. You should format our code so that it's easier to follow. It looks like you were missing a bracket and forgot to initialize SpentMoney. I formatted the code, initialized the variable to 0, and added the bracket so it would compile:

// This is the Hello program in Java
import java.io.*;

public class Loan
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String Amount, Payable, Interest, Paid;
        double Value, Rate, Spent, SpentMoney = 0, TotalSpentMoney;
        int Years;
        System.out.print("Enter Amount: ");
        Amount = stdin.readLine();
        Value = Double.parseDouble(Amount);
        System.out.print("Enter Payable in years: ");
        Payable = stdin.readLine();
        Years = Integer.parseInt(Payable);
        System.out.print("Enter Intrest Rate: ");
        Interest = stdin.readLine();
        Rate = Double.parseDouble(Amount);
        for (int i = 1; i <= Years; i = i + 1)
        {
            System.out.println("year" + i + " paid: ");
            Paid = stdin.readLine();
            Spent = Double.parseDouble(Paid);
            SpentMoney += Spent;

        }
        //TotalSpentMoney=Spent+SpentMoney;
        if (SpentMoney > Amount)
        {

            System.out.println("You paid above the Amount");
        }
        else
        {
            Rate = Rate / 100;
            System.out.println("Interest per year is " + Rate * Value);  // Finish the line
        }
    } 
}

Line 30 - Amount is a String. You are comparing a number to a String with the > operator. You need to turn Amount into a String using parseInt or parseDouble as you did in other parts of the program.

Okay, looks like you are NOT calculating a loan or a monthly payment. That's fine. My point earlier is that you should try to be as descriptive as possible so people know what the program does, what it assumes, and what it is asking the user. You should format our code so that it's easier to follow. It looks like you were missing a bracket and forgot to initialize SpentMoney. I formatted the code, initialized the variable to 0, and added the bracket so it would compile:

// This is the Hello program in Java
import java.io.*;

public class Loan
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String Amount, Payable, Interest, Paid;
        double Value, Rate, Spent, SpentMoney = 0, TotalSpentMoney;
        int Years;
        System.out.print("Enter Amount: ");
        Amount = stdin.readLine();
        Value = Double.parseDouble(Amount);
        System.out.print("Enter Payable in years: ");
        Payable = stdin.readLine();
        Years = Integer.parseInt(Payable);
        System.out.print("Enter Intrest Rate: ");
        Interest = stdin.readLine();
        Rate = Double.parseDouble(Amount);
        for (int i = 1; i <= Years; i = i + 1)
        {
            System.out.println("year" + i + " paid: ");
            Paid = stdin.readLine();
            Spent = Double.parseDouble(Paid);
            SpentMoney += Spent;

        }
        //TotalSpentMoney=Spent+SpentMoney;
        if (SpentMoney > Amount)
        {

            System.out.println("You paid above the Amount");
        }
        else
        {
            Rate = Rate / 100;
            System.out.println("Interest per year is " + Rate * Value);  // Finish the line
        }
    } 
}

Line 30 - Amount is a String. You are comparing a number to a String with the > operator. You need to turn Amount into a String using parseInt or parseDouble as you did in other parts of the program.

i found out this code manner

// This is the Hello program in Java
import java.io.*;
 class Loan {
	 public static void main(String[] args) throws IOException{
     BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
     String Amount, Payable, Interest, Paid;
     double Value, Rate, Spent, SpentMoney, TotalSpentMoney; int Years; 
        System.out.print("Enter Amount: ");
         Amount=stdin.readLine();
         Value=Double.parseDouble(Amount);	
        System.out.print("Enter Payable in years: ");
         Payable=stdin.readLine();
         Years=Integer.parseInt(Payable);
        System.out.print("Enter Intrest Rate: ");
         Interest=stdin.readLine();
         Rate=Double.parseDouble(Amount);			 
	     for (int i = 1;  i <=Years;  i = i+1)  {    
          System.out.println("year"+ i + " paid: "); 
		  Paid=stdin.readLine();
		  Spent = Double.parseDouble(Paid);
		  //TotalSpentMoney+=Spent;
		  if(Spent > Value){
		  
             System.out.println("You paid above the Amount");}
		  else{
		  Rate=Rate/100;
     System.out.println("Interest per year is "+Rate*Value);  // Finish the line
  }
         }
		 //TotalSpentMoney=Spent+SpentMoney;
          
  }
  }

I have only one thing in my mind... why does the if block cannot calculate outside for loop?

it seems to be every after input the if else is there for this code.. is there a way I can only do IF else out side for loop??

i found out this code manner

// This is the Hello program in Java
import java.io.*;
 class Loan {
	 public static void main(String[] args) throws IOException{
     BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
     String Amount, Payable, Interest, Paid;
     double Value, Rate, Spent, SpentMoney, TotalSpentMoney; int Years; 
        System.out.print("Enter Amount: ");
         Amount=stdin.readLine();
         Value=Double.parseDouble(Amount);	
        System.out.print("Enter Payable in years: ");
         Payable=stdin.readLine();
         Years=Integer.parseInt(Payable);
        System.out.print("Enter Intrest Rate: ");
         Interest=stdin.readLine();
         Rate=Double.parseDouble(Amount);			 
	     for (int i = 1;  i <=Years;  i = i+1)  {    
          System.out.println("year"+ i + " paid: "); 
		  Paid=stdin.readLine();
		  Spent = Double.parseDouble(Paid);
		  //TotalSpentMoney+=Spent;
		  if(Spent > Value){
		  
             System.out.println("You paid above the Amount");}
		  else{
		  Rate=Rate/100;
     System.out.println("Interest per year is "+Rate*Value);  // Finish the line
  }
         }
		 //TotalSpentMoney=Spent+SpentMoney;
          
  }
  }

I have only one thing in my mind... why does the if block cannot calculate outside for loop?

it seems to be every after input the if else is there for this code.. is there a way I can only do IF else out side for loop??

With code that is formatted like this, it is impossible to see where all of the if and for blocks start and stop. It's very possible that what you think is inside the if and for blocks is in fact NOT inside the if and for blocks or vice versa. Format your code with constant indentation like I did and it will be immediately apparent what is inside which brackets and what isn't, and also when you are missing a bracket or have an extra one. Format your code, look at it, and see if the problems become clearer.

With code that is formatted like this, it is impossible to see where all of the if and for blocks start and stop. It's very possible that what you think is inside the if and for blocks is in fact NOT inside the if and for blocks or vice versa. Format your code with constant indentation like I did and it will be immediately apparent what is inside which brackets and what isn't, and also when you are missing a bracket or have an extra one. Format your code, look at it, and see if the problems become clearer.

well it seems to be you'll be my friend gere oh well uhmm I'm getting to sleep now... thnx for the help anywayz... u can add me on super_alazar@yahoo.com and If only possible ur online tommorow then I can finally finish this task. Thank you for teaching me. I'm going to sleep now.. thx friend

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.