SHARE
TWEET

Untitled

a guest Oct 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.apache.commons.cli.*;
  2.  
  3. public class cic{
  4.  
  5.  
  6.     public static void main(String[] args) throws Exception {
  7.  
  8.         Options options = new Options();
  9.  
  10.         Option principal = new Option("p", "principal", true, "Starting money (Principal)");
  11.         principal.setRequired(true);
  12.         options.addOption(principal);
  13.  
  14.         Option years = new Option("y", "years", true, "Number of years");
  15.         years.setRequired(true);
  16.         options.addOption(years);
  17.  
  18.         Option interest = new Option("i", "interest", true, "Interest rate (Percentage)");
  19.         interest.setRequired(true);
  20.         options.addOption(interest);
  21.  
  22.         CommandLineParser parser = new DefaultParser();
  23.         HelpFormatter formatter = new HelpFormatter();
  24.         CommandLine cmd=null;
  25.         try {
  26.           cmd = parser.parse(options, args);
  27.         } catch (Exception e) {
  28.  
  29.             formatter.printHelp("compound interest calculator", options);
  30.  
  31.             System.exit(1);
  32.         }
  33.          double Principal = Double.parseDouble(cmd.getOptionValue("principal"));
  34.          double Years = Double.parseDouble(cmd.getOptionValue("years"));
  35.          double Interest = Double.parseDouble(cmd.getOptionValue("interest"));
  36.         public static final String ANSI_PURPLE = "\u001B[35m";
  37.         public static final String ANSI_RESET = "\u001B[0m";
  38.         System.out.println(ANSI_PURPLE+"\t compound interest calculator by mohammed waheeb "+ANSI_RESET);
  39.         calculate(Principal,Years,Interest);
  40.     }
  41.         static void calculate(double Pr ,double Ye ,double In) {
  42.                 double Ci;
  43.                 for(int i=1 ;i<=Ye;i++){
  44.                  Ci = Pr * (Math.pow((1 + In / 100), i));
  45.                 System.out.println("Your "+Pr+" are now: "+Ci+" JD.");
  46.         } }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top