/*manimbo_mp4.java*/
import java.io.*;
	public class manimbo_mp4{
		public static void main (String[]args) throws IOException{
			BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
			
			/*initializing STRING FORMAT variables
			 *smmort holds monthly mortgage amount
			 *spaym holds mortgage payment amount
			 *sremb holds principal amount*/
			String smmort,spaym,sremb;
			
			/*initializing LONG FORMAT variables
			 *lmmort holds monthly mortgage amount
			 *lpaym holds mortgage payment amount
			 *loutb holds outstanding balance
			 *lremb holds principal amount*/
			Long lmmort,lpaym,loutb,lremb;
			
			/*initializing DOUBLE FORMAT variables
			 *doutb holds outstanding balance
			 *dremb holds principal amount
			 *dinte holds interest amount*/
			Double doutb,dremb,dinte;
			
			/*prints "Enter Monthly Mortgage Amount: " on sreen and asks for input from user*/
			System.out.print ("Enter Monthly Mortgage Amount: ");
			/*assigns smmort to hold the inputted data from user*/
			smmort=br.readLine();
			/*converts smmort value to Long Format*/
			lmmort=Long.parseLong(smmort);
			
			/*prints "Enter Mortgage Payment Amount: " on screen and asks for input from user*/
			System.out.print ("Enter Mortgage Payment Amount: ");
			/*assigns spaym to hold the inputted data from user*/
			spaym=br.readLine();
			/*converts spaym value to Long Format*/
			lpaym=Long.parseLong(spaym);
			
			/*if statement*/
			/*determines if mortgage payment is greater than the monthly mortgage amount*/
			if (lpaym>lmmort){
				/*assigns loutb to hold the change if there is any*/
				loutb=lpaym-lmmort;
				/*determines if there is a change*/
				if (loutb>0){
					/*prints the amount of change on screen*/
					System.out.println ("Change: " + loutb);
				}
				/*determines if the customer gave an exact amount of payment*/
				else{
					/*SHOULD PRINT "Exact Amount of Payment Received" BUT ON MY CASE, IT DOES NOT*/
					System.out.println ("Exact Amount of Payment Received");
				}
			}
			else if (lpaym<lmmort){
				lremb=lmmort-lpaym;
				System.out.println ("Principal Amount: " + lremb);
				sremb=String.valueOf(lremb);
				dremb=Double.parseDouble(sremb);
				dinte=(dremb*(7.49/12));
				doutb=dinte+dremb;
				System.out.println ("Interest Amount: " + dinte);
				System.out.println ("Outstanding Balance: " + doutb);
			}

		}
	}

Dani AI

Generated

Nice catch — that explains it. The reason nothing printed for the “exact” case is a logic/branching issue: the code never handles the equality scenario because the exact-message branch is nested inside the branch that only runs when the payment is greater. When the payment equals the mortgage, neither the greater nor the less-than branch runs, so nothing executes. The simplest, clear fixes are either to add an explicit equality branch or to structure the outer test to include equality and then distinguish greater vs equal inside.

Example (structure only — not a copy of your original block):

if (payment > mortgage) {
  // print change
} else if (payment == mortgage) {
  // print exact-payment message
} else {
  // compute remainder + interest
}

A few extra, immediately useful notes you won’t see from a quick fix:

  • Interest formula: if 7.49 is an annual percent, the monthly interest is principal * (7.49 / 100) / 12. Leaving out the /100 makes the interest 100× too large.
  • Currency: avoid double for money. Use BigDecimal (or work in cents with long) to prevent rounding surprises and to control scale/rounding.
  • Types and parsing: prefer the primitive long for amounts (avoid nullable wrappers unless needed). Wrap parsing in a try/catch and validate input (non-numeric, negatives, empty).
  • Output: format money with DecimalFormat or NumberFormat.getCurrencyInstance() so results look correct and consistent.

Test all three cases (underpay, exact, overpay) and a couple of edge cases (zero, negative, malformed input). Fixing the branch plus correcting the interest calculation will make the program behave predictably.

Finally know the answer... I was hungry a while ago so I ate some. Then I came to realize that the condition

if (lpaym>lmmort)

is the reason why it does not print "Exact amount of payment received".

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.