import java.util.*; public class save { public static void main(String args[]) { double Money = 0, principle_amount, Interest_rate = 0, Amount, n; int Time = 0, Actual_amount_need; Scanner sc = new Scanner(System.in); System.out.println("Enter desired cashflow: "); System.out.println("Enter time (in months): "); System.out.println("Enter rate: "); Money = sc.nextDouble(); Time = sc.nextInt(); Interest_rate = sc.nextDouble(); try { if (Money > 0 && Time > 0 && Interest_rate >= 0) { if (Interest_rate != 0) { Interest_rate = Interest_rate / 100; principle_amount = Money * ((1 - Math.pow((1+(Interest_rate/12)),(-Time)))/(Interest_rate / 12)); } else { Amount = Money * Time; principle_amount = Amount; } Actual_amount_need = (int)(principle_amount + 0.5); System.out.println("Money to be deposited now: " + Actual_amount_need); return; } else { System.out.println("Error"); } } catch (Exception e) { System.out.println(e); System.out.println("not Amount valid input"); } } }
Quote: import java.util.*; public class Save { public static void main(String[] args) { // TODO Auto-generated method stub double Money = 0.00, principle_amount=0.00, Interest_rate = 0.00; int Time = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter desired cashflow: "); System.out.println("Enter time (in months): "); System.out.println("Enter rate: "); try { Money = sc.nextDouble(); Time = sc.nextInt(); Interest_rate = sc.nextDouble(); sc.close(); if (Money > 0 && Time > 0 && Interest_rate >= 0) { if (Interest_rate != 0) { Interest_rate = Interest_rate / 100; principle_amount = (Money * Time)/Interest_rate; } else { principle_amount = Money * Time; } System.out.println("Money to be deposited now: " + principle_amount); return; } else { System.out.println("Error"); } } catch (Exception e) { System.out.println(e); System.out.println("not Amount valid input"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)