Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'d really appreciate the help. I\'m having a difficult time doing this, and I\

ID: 3635720 • Letter: I

Question

I'd really appreciate the help. I'm having a difficult time doing this, and I'm all over the place. Please help, thanks!

Instructions:
1. Ask the user for initial principal amount and annual percentage rate.

2. Program will go through the for-loop (see Interest) but instead of displaying in the screen, write to a text file.

3. Program will then open the same text file, read the data and append to the outputTextArea variable and then JOption display on the screen inside a JOptionPane message dialog (see Interest).



Here's the template to edit:

import java.text.NumberFormat; //class for numeric formatting
import java.util.Locale; //class for country-specific information
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class Interest {

public static void main(String[] args) {

double amount, //amount of deposit at end of each year
principal, //initial amount before interest
rate; //rate of interest
String input;

//create NumberFormat for currency in US dollar format
NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );

//create JTextArea to display output
JTextArea outputTextArea = new JTextArea();

input = JOptionPane.showInputDialog("Please enter Principal: ");
principal = Double.parseDouble(input);

input = JOptionPane.showInputDialog("Please enter Interest Rate (Format: 0.00) ");
rate = Double.parseDouble(input);

//set first line of to display output
outputTextArea.setText("Year Amount on deposit ");

//calculate amount on deposit for each of ten years
for (int year = 1; year<= 10; year++)
{
amount = principal * Math.pow(1.0 + rate, year);

// append one line of text to outputTextArea
outputTextArea.append( year + " " +
moneyFormat.format(amount) + " ");
}// end for

//display results
JOptionPane.showMessageDialog(null, outputTextArea,
"Compount Interest", JOptionPane.INFORMATION_MESSAGE);

System.exit(0); //terminate the application

}//end of main


}//end of Interest.java

Explanation / Answer

inlinecode] import java.awt.*; import javax.swing.*; import BreezySwing.*; public class Interest extends GBFrame { // Declare variables for the window objects private JLabel BeginLabel; private JLabel YearLabel; private JLabel RateLabel; private JLabel CmpLabel; private DoubleField BeginField; private DoubleField YearField; private DoubleField RateField; private DoubleField CmpField; private JButton CalcButton; private JButton ClrButton; private JTextArea output; // Define the other instance variables private double totalInterest; //The total of all sales // Constructor public Interest(){ // Define the table's header line String header = Format.justify('l', "Year", 8) + Format.justify('l', "Begin Amount", 17) + Format.justify('l', "Interest", 14) + Format.justify('l', "End Amount", 14) + " "; // Instantiate the window objects BeginLabel = addLabel ("Beginning Amount" ,1,1,1,1); YearLabel = addLabel ("Years" ,2,1,1,1); RateLabel = addLabel ("Rate" ,3,1,1,1); CmpLabel = addLabel ("Compound Rate" ,4,1,1,1); BeginField = addDoubleField (0 ,1,2,1,1); YearField = addDoubleField (0 ,2,2,1,1); RateField = addDoubleField (0 ,3,2,1,1); CmpField = addDoubleField (0 ,4,2,1,1); CalcButton = addButton ("Calculate" ,5,1,1,1); ClrButton = addButton ("Clear Table" ,5,2,1,1); output = addTextArea (header ,1,3,3,5); // Disable the text area because we don't want the user to change it. // Set the focus to name field in preparation for the user's first input. output.setEditable(false); BeginField.requestFocus(); //Change color so I won't forget.. //BeginField.setBackground(Color.red); //BeginField.setSelectionColor(Color.blue); // Initialize the totals to 0. totalInterest = 0; } // Respond to the command buttons public void buttonClicked (JButton buttonObj){ if (buttonObj == CalcButton){ processInputs(); BeginField.requestFocus(); //Move the cursor to the begin field }if (buttonObj == ClrButton){ clearInputs(); } } // Read the inputs, compute the commissions, format and display the // name, sale, and commission. private void processInputs(){ // Declare the local variables double IntEarned = 0; // interest double Rate; // rate double Cmp; // compound rate double Begin; // beginning amount double Year; // years double End; // ending amount // Read the user input Begin = BeginField.getNumber(); Rate = RateField.getNumber(); Year = YearField.getNumber(); for (int Tyrs = 0; Tyrs
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote