The application must calculate the compound interest of the amount entered at the required investment type. Moderate investments receive 10% interest, while the aggressive receives 15% interest per year for the selected term. A sample output based on the selection above would be: (10) Q.1.4 Comment your program; Marks will be allocated to the declaration of objects, logic, class definitions, method calls, etc.
import javax.swing.JOptionPane;
public class Main {
/**
* main menu
*
* @param args
*/
public static void main(String[] args) {
// Read name
String customerName = JOptionPane.showInputDialog("Enter name: ");
// Read original amount
double originalAmount = Double.parseDouble(JOptionPane.showInputDialog("Enter original amount: "));
int yearsInvested = Integer.parseInt(JOptionPane.showInputDialog("Enter number of years invested: "));
//calculate the compound interest
double finalAmount = originalAmount *(Math.pow((1.0 + (10.0 / 100.0)), yearsInvested));
finalAmount = originalAmount *(Math.pow((1.0 + (15.0 / 100.0)), yearsInvested));
String result = "INVESTMENT REPORT\n" + "CUSTOMER NAME: " + customerName + "\nORIGINAL AMOUNT R "
+ String.format("%.2f", originalAmount) + "\nYEARS INVESTED " + yearsInvested + "\n" + "FINAL AMOUNT: R "
+ String.format("%.2f", finalAmount);
// display result
JOptionPane.showMessageDialog(null, result);
}
}
Comments
Leave a comment