Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.cli.*;
- public class cic{
- public static void main(String[] args) throws Exception {
- Options options = new Options();
- Option principal = new Option("p", "principal", true, "Starting money (Principal)");
- principal.setRequired(true);
- options.addOption(principal);
- Option years = new Option("y", "years", true, "Number of years");
- years.setRequired(true);
- options.addOption(years);
- Option interest = new Option("i", "interest", true, "Interest rate (Percentage)");
- interest.setRequired(true);
- options.addOption(interest);
- CommandLineParser parser = new DefaultParser();
- HelpFormatter formatter = new HelpFormatter();
- CommandLine cmd=null;
- try {
- cmd = parser.parse(options, args);
- } catch (Exception e) {
- formatter.printHelp("compound interest calculator", options);
- System.exit(1);
- }
- double Principal = Double.parseDouble(cmd.getOptionValue("principal"));
- double Years = Double.parseDouble(cmd.getOptionValue("years"));
- double Interest = Double.parseDouble(cmd.getOptionValue("interest"));
- public static final String ANSI_PURPLE = "\u001B[35m";
- public static final String ANSI_RESET = "\u001B[0m";
- System.out.println(ANSI_PURPLE+"\t compound interest calculator by mohammed waheeb "+ANSI_RESET);
- calculate(Principal,Years,Interest);
- }
- static void calculate(double Pr ,double Ye ,double In) {
- double Ci;
- for(int i=1 ;i<=Ye;i++){
- Ci = Pr * (Math.pow((1 + In / 100), i));
- System.out.println("Your "+Pr+" are now: "+Ci+" JD.");
- } }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement