hey guys, i need some help with hava assignment. I took C++ before and now taking java. I am new to java and my professor thinks everyone has knowledge about java and didnt even teach the basics. Now i am having problem doing the assignment. I tried doing it myself but couldnot figure out. Hope u guys can help. HEre is the assignment. Write a program that creates a loan amortization table. The user of the program will supply values for Initial Loan Principal, Annual Percentage Rate and Monthly Payment. The program should print out the appropriate amortization table including the Number of Monthly Payments and the Total Interest Paid for the life of the loan. The program should allow multiple runs of the table process and should allow the user to compare runs in a tabular format (at least 4 different versions of the amortization table) at the end of the program execution. Key data from each amortization table that should be displayed in the comparison table are Initial Principle, Initial Payment, Annual Percentage Rate, Total Number of Payments and Total Interest Paid. Below is the code i wrote. import javax.swing.JOptionPane; import java.text.DecimalFormat; public class creditcardassignment { public static void main(String[] args) { int run; do { String Run_Question = JOptionPane.showInputDialog(null, "How many times do you like to run the program? (Up to four runs only!)", JOptionPane.QUESTION_MESSAGE); run = Integer.parseInt(Run_Question); if( run < 0 || run > 4) { JOptionPane.showMessageDialog(null, "The number is invalid,please try again!", "Error", JOptionPane.INFORMATION_MESSAGE); } }while(run < 0 || run > 4); } } The question is how do i make the ammortization table. Please help me guys.
iamunknown · Sep 12, 2011 10:42 AM · 13,586 views
Does it have to be swing? Are you trying to make something like this? http://www.amortizationtable.o...
bange · Sep 12, 2011 10:50 AM
Does it have to be swing? Are you trying to make something like this? http://www.amortizationtable.o...
bange · Sep 12, 2011 10:51 AM
No table like below.. Payment # Principle Payment Percentage MPR Interest Payment Principle Payment ---------------------------------------------------------------------------- 1 400.00 100.00 12.00 0.01 4.00 96.00 2 304.00 100.00 12.00 0.01 3.04 96.96 3 207.04 100.00 12.00 0.01 2.07 97.93
iamunknown · Sep 12, 2011 10:54 AM
Then do this on command line, pseudo code Display headers for i=0 to 3 get inputs calculate outputs display as row end
bange · Sep 12, 2011 11:26 AM
public class creditcardassignment { public static void main(String[] args) { int run; int i=0; while(i < 4 ){ String Run_Question = JOptionPane.showInputDialog(null, "How many times do you like to run the program? (Up to four runs only!)", JOptionPane.QUESTION_MESSAGE); run = Integer.parse(Run_Question); if(run > 4 && run <1) { JOptionPane.showMessageDialog(null, "The number is invalid,please try again!", "Error", JOptionPane.INFORMATION_MESSAGE); exit(0); } } List<Info> infoList = new Arraylist<Info>(); for(int i=0; i<run; i++) { //get input from users and calculate output //enter or calculate intialprinciple //enter or calculateintialpayment //enter or calculateAPR //enter or calculate noofpayments //enter or calculate totalinterestpaid //create info object //add allthe above principle, payment, apr, no of payments, interest paid to info object Info i = new Info(); i.add(intialprinciple) and so on ArrayList.add(i); } //iterate and display content from List in tabular format } } public class Info { double initialPrinciple; double initialPayment; double APR; double noOfPayments; double totalInterestPaid; //add getter setter }
serial · Sep 12, 2011 11:37 AM
/* Som ework for you ... use you formula to calulate..just used semo formula use do while loop to take to input for 4 times only */ import javax.swing.JOptionPane; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JTextArea; public class Table extends JFrame{ private static JTextArea output; public Table(){ int lp, ap,mp; int count=0; String loanPrincipal = JOptionPane.showInputDialog(null, "Enter Initial Loan Princial", JOptionPane.QUESTION_MESSAGE); String annualPercentage = JOptionPane.showInputDialog(null, "Enter Annual Percentage", JOptionPane.QUESTION_MESSAGE); String monthlyPayment = JOptionPane.showInputDialog(null, "Enter MonthlyPayment", JOptionPane.QUESTION_MESSAGE); if(loanPrincipal!=null && annualPercentage!=null && monthlyPayment!=null){ lp = Integer.parseInt(loanPrincipal); ap= Integer.parseInt(loanPrincipal); mp=Integer.parseInt(loanPrincipal); output = new JTextArea(10,15); int results = lp * ap; // use your own formula to calculate : this is just a demo output.append("Loan Principal"+" "+"Annual %"+" "+"Monthly Payment"+" "+"Results"); output.append("\n"); output.append(lp +"\t"+ ap +"\t"+mp+ "\t"+ results); this.getContentPane().add(output,"Center"); this.setSize(400,600); this.setLocation(100,200); this.show(); count++; }else{ JOptionPane.showMessageDialog(null, "The number is invalid,please try again!", "Error", JOptionPane.INFORMATION_MESSAGE); count++; } } public static void main(String[]args){ Table t = new Table(); } }
ayus · Sep 12, 2011 11:40 AM
O0ops !! that count++ in code was to take count input...forgot to remove everything.... right now it doesnt make any sense to have count ++ post if you need any further help..
ayus · Sep 12, 2011 11:42 AM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion