Results 1 to 7 of 7
- 11-29-2008, 01:12 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
Array Assign Values from a Textfile
Hello,
I have a full functional code that I wrote for my university. I currently assign array values manually:
I would like to assign these numbers from a textfile. Could you please help me?Java Code:double[] mortgageAPRArray = {5.35, 5.50, 5.75};
Thank you very much in advance,Java Code:import java.text.*; import java.math.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Date; public class MortgageCalculatorArray_Week5 { public static void main(String[] args) throws IOException { JFrame MortgageWindow = new MortgageCalculator(); //Initiate New Mortgage Window MortgageWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //End the program if user clicks on close icon upper right hand corner MortgageWindow.setVisible(true); //display the program } } class MortgageCalculator extends JFrame implements ActionListener { /***********************************************************************************************************/ /* JOptionPane is very similar to HTML form. You can create input boxes, drop-down boxes, selection boxes, */ /* and etc. I am only using fields, input box, buttons, and text area to get my assignment done. */ /***********************************************************************************************************/ /**********************************************************************************************/ /* Step 1) Initializations and declarations of the variables */ /**********************************************************************************************/ //Creating buttons for the Mortgage Calculator: protected JButton btnCalc07Yearsr, //Button for 7 Years Loan @ 5.35% btnCalc15Years, //Button for 15 Years Loan @ 5.50% btnCalc30Years, //Button for 30 Years Loan @ 5.75% btnUserInput, //Button if Users Input their Numbers btnClearAllFields, //Button to Clear Input Fields btnCloseProgram; //Button to Close the Program //Creating labels for the Mortgage Calculator: protected JLabel labelHeader01, //Program headers labelHeader02, labelHeader03, labelHeader04, //End of program header labelFirstInstructions, //First Instruction labelSecondInstructions, //Second Instruction labelThirdInstructions, //Third Instruction labelMortgageTerm, //Mortgage Term labelMortgageAPR, //Mortgage APR labelMortgageTextArea, //Mortgage Amortization /* Vertical borders' variables start from here */ labelV01, labelV02, labelV03, labelV04, labelV05, labelV06, labelV07, labelV08, labelV09, labelV10, labelV11, labelV12, labelV13, labelV14, labelV15, labelV16, labelV17, labelV18, labelV19, labelV20, labelV21, labelV22, labelV23, labelV24, labelV25, labelV26, labelV27, labelV28, labelV29, labelV30, labelV31, labelV32, labelV33, labelV34, labelV35, labelV36, labelV37, labelV38, labelV39, labelV40, labelV41, labelV42, labelV43, labelV44, labelV45, labelV46, labelV48, /* End of vertical borders */ labelH01, labelH02, labelH03, labelH04, //Horizontal borders labelMonthlyPayment, labelLoanAmount; //Mortgage Monthly Payment protected JTextField fieldMortgageAmount, //Input Mortgage Amount fieldMortgageTerm, //Input Mortgage Term fieldMortgageAPR, //Input Mortgage APR fieldMonthlyPayment; //Output Monthly Payment protected JTextArea textAreaMortgageTable; //TextArea to display individual records per term /***********************************************************************************************************/ /* End of the form fields and labels */ /***********************************************************************************************************/ //Mortgage variables for the calculation purposes double InterestPaid, PrinciplePaid, Balance, monthlyPay, updatedLoanAmount; int [] mortgageTermsArray = {7, 15, 30}; //Three mortgage loan terms: 7 years, 15 years, and 30 years double[] mortgageAPRArray = {5.35, 5.50, 5.75}; //Three APRs: 5.35%, 5.50%, and 5.75% double mortgageInitialLoanAmount = updatedLoanAmount; double inputRatebyUser; //Holds the APR input by the user int inputTermbyUser; //Holds the input term by user /**********************************************************************************************/ /* End of Step 1 */ /**********************************************************************************************/ /**********************************************************************************************/ /* Step 2) First we need to find out what button was pressed by the users */ /**********************************************************************************************/ public void actionPerformed (ActionEvent e) { //Did user click on "7 Years @ 5.35%" button? If yes, execute the following line of codes! if ("ActionCalculate7YearsTerms".equals(e.getActionCommand())) { DecimalFormat decimalPlaces = new DecimalFormat("0.00"); NumberFormat currency = NumberFormat.getCurrencyInstance(); double paymentAmount = Calculation7YearsLoan(); fieldMonthlyPayment.setText("" + (currency.format(paymentAmount))); textAreaMortgageTable.setText (""); //Clear the amortization table before the calculation textAreaMortgageTable.append ("Payment # \t Remaining Balance \t Interest Paid\n"); // set loan amount mortgageInitialLoanAmount = Double.parseDouble(fieldMortgageAmount.getText()); for (int x = 1; x <=(mortgageTermsArray[0]*12); x++) //Loop through all monthly payments for each loan { Balance=mortgageInitialLoanAmount; //Set Balance to Loan Amount //Calculations on monthly payment InterestPaid=(((mortgageAPRArray[0]/100.0)/12.0)*Balance); //Monthly Interest paid PrinciplePaid=(paymentAmount-InterestPaid); //Applied towards principle mortgageInitialLoanAmount=(Balance-PrinciplePaid); //loan balance after payment textAreaMortgageTable.append (x + " \t " + currency.format(mortgageInitialLoanAmount) + " \t\t " + currency.format(InterestPaid)+"\n"); } if (Balance <= 0) //ending statement { textAreaMortgageTable.append ("\tRemaining balance = $0.00"); } } //Did user click on "15 Years @ 5.50%" button? If yes, execute the following line of codes! else if ("ActionCalculate15YearsTerms".equals(e.getActionCommand())) { DecimalFormat decimalPlaces = new DecimalFormat("0.00"); NumberFormat currency = NumberFormat.getCurrencyInstance(); double paymentAmount = Calculation15YearsLoan (); fieldMonthlyPayment.setText("" + (currency.format(paymentAmount))); textAreaMortgageTable.setText (""); //Clear the amortization table before the calculation textAreaMortgageTable.append ("Payment # \t Remaining Balance \t Interest Paid\n"); mortgageInitialLoanAmount = Double.parseDouble(fieldMortgageAmount.getText()); for (int x = 1; x <=(mortgageTermsArray[1]*12); x++) //Loop through all monthly payments for each loan { Balance = mortgageInitialLoanAmount; //Calculations on monthly payment InterestPaid=((mortgageAPRArray[1]/100/12)*Balance); //Monthly Interest paid PrinciplePaid=(paymentAmount-InterestPaid); //Applied towards principle mortgageInitialLoanAmount=((Balance-PrinciplePaid)); //loan balance after payment textAreaMortgageTable.append (x + " \t " + currency.format(mortgageInitialLoanAmount) + " \t\t " + currency.format(InterestPaid)+"\n"); } if (mortgageInitialLoanAmount <= 0) //ending statement { textAreaMortgageTable.append ("\tRemaining balance = $0.00"); } } //Did user click on "30 Years @ 5.75%" button? If yes, execute the following line of codes! else if ("ActionCalculate30YearsTerms".equals(e.getActionCommand())) { DecimalFormat decimalPlaces = new DecimalFormat("0.00"); NumberFormat currency = NumberFormat.getCurrencyInstance(); double paymentAmount = Calculation30YearsLoan (); textAreaMortgageTable.setText (""); //Clear the amortization table before the calculation fieldMonthlyPayment.setText("" + (currency.format(paymentAmount))); textAreaMortgageTable.append ("Payment # \t Remaining Balance \t Interest Paid\n"); mortgageInitialLoanAmount = Double.parseDouble(fieldMortgageAmount.getText()); for (int x = 1; x <=(mortgageTermsArray[2]*12); x++) //Loop through alll monthly payments for each loan { Balance = mortgageInitialLoanAmount; //Calculations on monthly payment InterestPaid=((mortgageAPRArray[2]/100/12)*Balance); //Monthly Interest paid PrinciplePaid=(paymentAmount-InterestPaid); //Applied towards principle mortgageInitialLoanAmount=((Balance-PrinciplePaid)); //loan balance after payment textAreaMortgageTable.append (x + " \t " + currency.format(mortgageInitialLoanAmount) + " \t\t " + currency.format(InterestPaid)+"\n"); } if (mortgageInitialLoanAmount <= 0) //ending statement { textAreaMortgageTable.append ("\tRemaining balance = $0.00"); } } //Does the user wants to use his/her own numbers? If yes, then execute the following lines! else if ("Calculate".equals(e.getActionCommand())) { DecimalFormat decimalPlaces = new DecimalFormat("0.00"); NumberFormat currency = NumberFormat.getCurrencyInstance(); double paymentAmount = CalculatePayment(); textAreaMortgageTable.setText (""); //Clear the amortization table before the calculation fieldMonthlyPayment.setText("" + (currency.format(paymentAmount))); textAreaMortgageTable.append ("Payment # \t Remaining Balance \t Interest Paid\n"); mortgageInitialLoanAmount = Double.parseDouble(fieldMortgageAmount.getText()); inputTermbyUser = Integer.parseInt(fieldMortgageTerm.getText()); inputRatebyUser = Double.parseDouble(fieldMortgageAPR.getText()); for (int x = 1; x <=(inputTermbyUser*12); x++) //Loop through all monthly payments for each loan { Balance = mortgageInitialLoanAmount; //Calculations on monthly payment InterestPaid = ((inputRatebyUser / 100 / 12) * Balance); //Monthly Interest paid PrinciplePaid = (paymentAmount - InterestPaid); //Applied towards principle mortgageInitialLoanAmount = ((Balance - PrinciplePaid)); //loan balance after payment textAreaMortgageTable.append (x + " \t " + currency.format(mortgageInitialLoanAmount) + " \t\t " + currency.format(InterestPaid)+"\n"); } if (mortgageInitialLoanAmount <= 0) //ending statement { textAreaMortgageTable.append ("\tRemaining balance = $0.00"); } } //Did user click on "Clear All" button? If yes, then clear the three fields! else if ("Clear".equals(e.getActionCommand())) ClearFields (); //User must have clicked "Close Program" button because it is the last one! else System.exit(0); //Exit the application } /**********************************************************************************************/ /* End of Step 2 */ /**********************************************************************************************/ /**********************************************************************************************/ /* Step 3) Now we do some calculation based on users' action on buttons */ /**********************************************************************************************/ //What to do if user had clicked on "7 Years @ 5.35%" button? public double Calculation7YearsLoan () { //First let's check for the valid input: try { //If the input is valid, execute the following lines fieldMonthlyPayment.setText (""); double Payment = (updatedLoanAmount() * (mortgageAPRArray[0] / 100 / 12)) / (1 - Math.pow(1 / (1 + (mortgageAPRArray[0] / 100 / 12)), mortgageTermsArray[0] * 12)); return Payment; } catch (NumberFormatException event) { //If the input is invalid, execute the following lines JOptionPane.showMessageDialog(null, " Invalid Entry!\nPlease enter only numeric values!!", "ERROR", JOptionPane.ERROR_MESSAGE); return 0; } } //What to do if user had clicked on "15 Years @ 5.50%" button? public double Calculation15YearsLoan () { //First let's check for the valid input: try { //If the input is valid, execute the following lines fieldMonthlyPayment.setText (""); double Payment =(updatedLoanAmount() * (mortgageAPRArray[1] / 100 / 12)) / (1 - Math.pow(1 / (1 + (mortgageAPRArray[1] / 100 / 12)), mortgageTermsArray[1] * 12)); return Payment; } catch (NumberFormatException event) { //If the input is invalid, execute the following lines JOptionPane.showMessageDialog(null, " Invalid Entry!\nPlease enter only numeric values!!", "ERROR", JOptionPane.ERROR_MESSAGE); return 0; } } //What to do if user had clicked on "30 Years @ 5.75%" button? public double Calculation30YearsLoan () { //First let's check for the valid input: try { //If the input is valid, execute the following lines fieldMonthlyPayment.setText (""); double Payment = (updatedLoanAmount() * (mortgageAPRArray[2] / 100 / 12)) / (1 - Math.pow(1 / (1 + (mortgageAPRArray[2] / 100 / 12)), mortgageTermsArray[2] * 12)); return Payment; } catch (NumberFormatException event) { //If the input is invalid, execute the following lines JOptionPane.showMessageDialog(null, " Invalid Entry!\nPlease enter only numeric values!!", "ERROR", JOptionPane.ERROR_MESSAGE); return 0; } } //What to do if user had clicked on "User Input" button? public double CalculatePayment() { //First let's check for the valid input: try { //If the input is valid, execute the following lines fieldMonthlyPayment.setText (""); double Payment =(updatedLoanAmount() * (inputRatebyUser/100/12)) / (1 - Math.pow(1/(1 + (inputRatebyUser/100/12)),inputTermbyUser*12)); return Payment; } catch (NumberFormatException event) { //If the input is invalid, execute the following lines JOptionPane.showMessageDialog(null, " Invalid Entry!\nPlease enter only numeric values!!", "ERROR", JOptionPane.ERROR_MESSAGE); return 0; } } //What to do if user had clicked on "Clear All" button? public void ClearFields() { //Set all text fields to blank fieldMonthlyPayment.setText (""); fieldMortgageAmount.setText (""); textAreaMortgageTable.setText (""); } /**********************************************************************************************/ /* End of Step 3 */ /**********************************************************************************************/ /**********************************************************************************************/ /* Step 4) Display the data on the window */ /**********************************************************************************************/ public MortgageCalculator () { /**************************************************************/ /* Creating the buttons and naming them! */ /**************************************************************/ Date currentDate = new Date(); //Display current date btnCalc07Yearsr = new JButton ("7 Year, 5.35%"); //7 Years Loan @ 5.35% button btnCalc07Yearsr.setActionCommand ("ActionCalculate7YearsTerms"); btnCalc15Years = new JButton ("15 Year, 5.50%"); //15 Years Loan @ 5.50% button btnCalc15Years.setActionCommand ("ActionCalculate15YearsTerms"); btnCalc30Years = new JButton ("30 Year, 5.75%"); //30 Years Loan @ 5.75% button btnCalc30Years.setActionCommand ("ActionCalculate30YearsTerms"); btnUserInput = new JButton ("User Input"); //User Input button btnUserInput.setActionCommand ("Calculate"); btnClearAllFields = new JButton ("Reset All"); //Reset All button btnClearAllFields.setActionCommand ("Clear"); btnCloseProgram = new JButton ("Close Program"); //Close Program button btnCloseProgram.setActionCommand ("Exit"); /**************************************************************/ /* Program Headers! */ /**************************************************************/ labelHeader01 = new JLabel ("Programmer: Ahmad F. Rashidi"); labelHeader02 = new JLabel ("Course: PRG 421 - Week 3 - Individual Assignment"); labelHeader03 = new JLabel ("Instructor: Keith Wright"); labelHeader04 = new JLabel ("Date: " + currentDate); //Display current from user's machine clock /*************************************************************************************************/ /* I am sure there is an easy way of generating borders around boxes, I haven't learnt it yet. */ /*************************************************************************************************/ /* Horizontal lines used for the top and bottom borders */ labelH01 = new JLabel ("___________________________________________________________________________"); labelH02 = new JLabel ("___________________________________________________________________________"); labelH03 = new JLabel ("___________________________________________________________________________"); labelH04 = new JLabel ("___________________________________________________________________________"); /* End of horizontal lines */ /* Borders for the first box */ labelV01 = new JLabel ("|"); labelV02 = new JLabel ("|"); labelV03 = new JLabel ("|"); labelV04 = new JLabel ("|"); labelV05 = new JLabel ("|"); labelV06 = new JLabel ("|"); labelV07 = new JLabel ("|"); labelV08 = new JLabel ("|"); labelV09 = new JLabel ("|"); labelV10 = new JLabel ("|"); labelV11 = new JLabel ("|"); labelV12 = new JLabel ("|"); labelV13 = new JLabel ("|"); labelV14 = new JLabel ("|"); labelV15 = new JLabel ("|"); labelV16 = new JLabel ("|"); labelV17 = new JLabel ("|"); labelV18 = new JLabel ("|"); labelV19 = new JLabel ("|"); labelV20 = new JLabel ("|"); labelV21 = new JLabel ("|"); labelV22 = new JLabel ("|"); labelV23 = new JLabel ("|"); labelV24 = new JLabel ("|"); /* End of borders for the first box */ /* Borders for the second box */ labelV25 = new JLabel ("|"); labelV26 = new JLabel ("|"); labelV27 = new JLabel ("|"); labelV28 = new JLabel ("|"); labelV29 = new JLabel ("|"); labelV30 = new JLabel ("|"); labelV31 = new JLabel ("|"); labelV32 = new JLabel ("|"); labelV33 = new JLabel ("|"); labelV34 = new JLabel ("|"); labelV35 = new JLabel ("|"); labelV36 = new JLabel ("|"); labelV37 = new JLabel ("|"); labelV38 = new JLabel ("|"); labelV39 = new JLabel ("|"); labelV40 = new JLabel ("|"); labelV41 = new JLabel ("|"); labelV42 = new JLabel ("|"); labelV43 = new JLabel ("|"); labelV44 = new JLabel ("|"); labelV45 = new JLabel ("|"); labelV46 = new JLabel ("|"); /* End of borders for the second box */ /* Instructions on how to user the calculator*/ labelFirstInstructions = new JLabel ("1) Please enter your mortgage loan, loan term, and APR:"); labelSecondInstructions = new JLabel ("2) Now, please click on a button to see the results:"); labelThirdInstructions = new JLabel ("Note: 'Input User' button you must fill all three above boxes!"); labelMortgageTextArea = new JLabel ("3) Click on above buttons to see the records!"); /* End of instructions */ /**************************************************************/ /* Initiating the fields */ /**************************************************************/ labelMonthlyPayment = new JLabel ("Montly mortgage payment:"); labelLoanAmount = new JLabel ("Loan Amount:"); labelMortgageAPR = new JLabel ("APR:"); labelMortgageTerm = new JLabel ("Loan Term:"); fieldMonthlyPayment = new JTextField ("", 10); fieldMortgageAmount = new JTextField ("", 10); fieldMortgageAPR = new JTextField ("", 3); fieldMortgageTerm = new JTextField ("", 3); textAreaMortgageTable = new JTextArea (100, 550); JScrollPane scrollPane = new JScrollPane (textAreaMortgageTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); /**************************************************************/ /* Attach action to each button */ /**************************************************************/ btnCalc07Yearsr.addActionListener(this); btnCalc15Years.addActionListener(this); btnCalc30Years.addActionListener(this); btnUserInput.addActionListener(this); btnClearAllFields.addActionListener(this); btnCloseProgram.addActionListener(this); /**************************************************************/ /* Build and position individual fields, labels, and textarea */ /**************************************************************/ JPanel mine = new JPanel(); mine.setLayout (null); //Program Headers mine.add (labelHeader01); labelHeader01.setBounds (10, 10, 600, 15); mine.add (labelHeader02); labelHeader02.setBounds (10, 30, 600, 15); mine.add (labelHeader03); labelHeader03.setBounds (10, 50, 600, 15); mine.add (labelHeader04); labelHeader04.setBounds (10, 70, 600, 15); mine.add (labelFirstInstructions); labelFirstInstructions.setBounds (20, 110, 550, 15); mine.add (labelSecondInstructions); labelSecondInstructions.setBounds (20, 250, 550, 15); mine.add (labelThirdInstructions); labelThirdInstructions.setBounds (35, 270, 550, 15); //End of headers /* Positioning borders of the first box*/ //Left border mine.add (labelV01); labelV01.setBounds (9, 90, 100, 25); mine.add (labelV02); labelV02.setBounds (9, 100, 100, 25); mine.add (labelV03); labelV03.setBounds (9, 110, 100, 25); mine.add (labelV04); labelV04.setBounds (9, 120, 100, 25); mine.add (labelV05); labelV05.setBounds (9, 130, 100, 25); mine.add (labelV06); labelV06.setBounds (9, 140, 100, 25); mine.add (labelV07); labelV07.setBounds (9, 150, 100, 25); mine.add (labelV08); labelV08.setBounds (9, 160, 100, 25); mine.add (labelV09); labelV09.setBounds (9, 170, 100, 25); mine.add (labelV10); labelV10.setBounds (9, 180, 100, 25); mine.add (labelV11); labelV11.setBounds (9, 190, 100, 25); mine.add (labelV12); labelV12.setBounds (9, 198, 100, 25); //Right border mine.add (labelV13); labelV13.setBounds (534, 90, 100, 25); mine.add (labelV14); labelV14.setBounds (534, 100, 100, 25); mine.add (labelV15); labelV15.setBounds (534, 110, 100, 25); mine.add (labelV16); labelV16.setBounds (534, 120, 100, 25); mine.add (labelV17); labelV17.setBounds (534, 130, 100, 25); mine.add (labelV18); labelV18.setBounds (534, 140, 100, 25); mine.add (labelV19); labelV19.setBounds (534, 150, 100, 25); mine.add (labelV20); labelV20.setBounds (534, 160, 100, 25); mine.add (labelV21); labelV21.setBounds (534, 170, 100, 25); mine.add (labelV22); labelV22.setBounds (534, 180, 100, 25); mine.add (labelV23); labelV23.setBounds (534, 190, 100, 25); mine.add (labelV24); labelV24.setBounds (534, 198, 100, 25); /* End of positioning borders of the first box*/ /* Positioning borders of the second box*/ //Left border mine.add (labelV25); labelV25.setBounds (534, 230, 100, 25); mine.add (labelV26); labelV26.setBounds (534, 240, 100, 25); mine.add (labelV27); labelV27.setBounds (534, 250, 100, 25); mine.add (labelV28); labelV28.setBounds (534, 260, 100, 25); mine.add (labelV29); labelV29.setBounds (534, 270, 100, 25); mine.add (labelV30); labelV30.setBounds (534, 280, 100, 25); mine.add (labelV31); labelV31.setBounds (534, 290, 100, 25); mine.add (labelV32); labelV32.setBounds (534, 300, 100, 25); mine.add (labelV33); labelV33.setBounds (534, 310, 100, 25); mine.add (labelV34); labelV34.setBounds (534, 320, 100, 25); //Right border mine.add (labelV35); labelV35.setBounds (9, 230, 100, 25); mine.add (labelV36); labelV36.setBounds (9, 240, 100, 25); mine.add (labelV37); labelV37.setBounds (9, 250, 100, 25); mine.add (labelV38); labelV38.setBounds (9, 260, 100, 25); mine.add (labelV39); labelV39.setBounds (9, 270, 100, 25); mine.add (labelV40); labelV40.setBounds (9, 280, 100, 25); mine.add (labelV41); labelV41.setBounds (9, 290, 100, 25); mine.add (labelV42); labelV42.setBounds (9, 300, 100, 25); mine.add (labelV43); labelV43.setBounds (9, 310, 100, 25); mine.add (labelV44); labelV44.setBounds (9, 320, 100, 25); /* End of positioning borders of the second box*/ /* Horizontal Lines */ mine.add (labelH01); labelH01.setBounds (10, 85, 600, 15); mine.add (labelH02); labelH02.setBounds (10, 200, 550, 20); mine.add (labelH03); labelH03.setBounds (10, 222, 550, 20); mine.add (labelH04); labelH04.setBounds (10, 322, 550, 20); /* End of Horizontal Lines */ /* Question 1) the input boxes */ mine.add (labelLoanAmount); labelLoanAmount.setBounds (40, 135, 100, 20); //Loan amount label field mine.add (fieldMortgageAmount); fieldMortgageAmount.setBounds (160, 135, 100, 20); mine.add (labelMortgageTerm); labelMortgageTerm.setBounds (40, 160, 140, 20); mine.add (fieldMortgageTerm); fieldMortgageTerm.setBounds (160, 160, 100, 20); mine.add (labelMortgageAPR); labelMortgageAPR.setBounds (40, 185, 100, 20); mine.add (fieldMortgageAPR); fieldMortgageAPR.setBounds (160, 185, 100, 20); /* Question 2) Four buttons */ mine.add (btnCalc07Yearsr); btnCalc07Yearsr.setBounds (30, 300, 110, 20); mine.add (btnCalc15Years); btnCalc15Years.setBounds (150, 300, 120, 20); mine.add (btnCalc30Years); btnCalc30Years.setBounds (280, 300, 120, 20); mine.add (btnUserInput); btnUserInput.setBounds (410, 300, 100, 20); mine.add (labelMonthlyPayment); labelMonthlyPayment.setBounds (280, 650, 150, 25); //Monthly Mortgage Payment Label mine.add (fieldMonthlyPayment); fieldMonthlyPayment.setBounds (436, 650, 100, 25); //Display the amount fieldMonthlyPayment.setEditable (false); //This field can't be edited mine.add (labelMortgageTextArea);labelMortgageTextArea.setBounds (20, 375, 500, 25);//Textarea to display the amortization records // Add the scrollpane, set its bounds and set the table as not editable. mine.add (scrollPane); scrollPane.setBounds (10, 360, 527, 270); textAreaMortgageTable.setEditable(false); mine.add (btnClearAllFields); btnClearAllFields.setBounds (110, 710, 125, 30); //"Clear All" button mine.add (btnCloseProgram); btnCloseProgram.setBounds (250, 710, 125, 30); //"Close Program" button this.setContentPane(mine); this.pack(); this.setTitle("Mortgage Calculator"); //Title of the Window //Set window size Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(562, 800); //Size of the Window } /**********************************************************************************************/ /* End of Step 4 */ /**********************************************************************************************/ /* Final Step: Update the loan Amount */ public double updatedLoanAmount () { double updatedLoanAmount = Double.parseDouble(fieldMortgageAmount.getText()); return updatedLoanAmount; } }
-
Ignore your previous code and create a completely new class whose purpose is solely to read a text file and create an ArrayList<Double> with the data read (because you really don't want to create a fixed-size array). To get you going, you should use the Scanner class and read in doubles with nextDouble. Come back if you run into any problems. Good luck.
- 11-29-2008, 08:51 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
-
You're welcome.
This can ruffle many feathers in here, mine included. We are volunteers who are here to help teach a subject we love, not code-producing servants. Please never ask for someone to do your work for you. Ever. Instead, write your own code, and feel free to ask questions regarding this code you've created as most here will gladly help you with this.is there any way you can provide me with the source code?
A hard truth but you'd better learn it now: Your time management problems are just that: your problem not ours.I am really short on time!!!
Best of luck and look forward to seeing you here again.
- 11-29-2008, 11:27 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
I was able to fix the issue myself!
Java Code:double[] mortgageAPRArray = new double [3]; try { BufferedReader afr = new BufferedReader (new FileReader ("rates.txt")); for(int i = 0 ; i < 3; i++) { mortgageAPRArray[i] = Double.parseDouble(afr.readLine()); } } catch (IOException m) { System.err.println("*** IOexception ***" + m.getMessage()); }
-
Congrats, but please remember what I said about asking for source code solutions. I'm sure you'll do better with this in the future.
- 11-30-2008, 12:10 AM #7
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
3d array filled with garbage values
By jon80 in forum New To JavaReplies: 5Last Post: 01-01-2009, 10:12 PM -
writing array values to another class
By ronald christian in forum New To JavaReplies: 27Last Post: 11-07-2008, 04:08 PM -
replacing array values
By Jononomous in forum New To JavaReplies: 1Last Post: 05-22-2008, 03:27 PM -
[SOLVED] How to read a file and compare Array values
By DonCash in forum Advanced JavaReplies: 2Last Post: 04-02-2008, 02:22 PM -
Assign a keyboard key to a JButton.
By gszauer in forum AWT / SwingReplies: 1Last Post: 12-15-2007, 10:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks