Question: exercise 10.8 from page 503 with these additions: create an \"exit\" b
ID: 3687465 • Letter: Q
Question
Question:
exercise 10.8 from page 503 with these additions:
create an "exit" button that shuts down the program.
create a "reset" button that clears all the fields and lets the user run the program with new amounts.
"InvestmentViewer.java" on p477
You should submit TWO java files. NOTHING ELSE.
Please put your name in the two files
•• Excercise 10.8 Add error handling to the program in Section 10.3.2. If the interest rate is not a floating-point number, or if it less than 0, display an error message, using a JOptionPane (see Special Topic 2.5).
** 10.3.2 Program are the pictures attached.
"InvestmentViewer.java" on p477: picture is also attached
Special Topic 2.5
section 3 2/InvestmentFrame3.java 1 inport java.awt.event.ActionEvent; 2 irport java.awt.event.ActionListener 3 import javax.swing. JButton; 4 import javax.swing.JFrame; 5 import javax.swing. JLabel; 6 import javax.swing.JPanel; 7 import javax.swing. JScrol1Pane; 8 import javax.swing. JTextArea; 9 import javax.swing.JTextField; 10 12 Aframe that shows the growth of an investment with variable interest, 13 sing a 14 15 public class InvestmentFrame3 extends JFrame 16 t 17 private static final int FRAME WIDTH 400; 18 private static final int FRAME-HEIGHT 250; 19 20 private static final int AREA ROWS = 10; 21 private using a text area. static final int AREA COLUMNS 30; 23 private static final double DEFAULT RATE = 5; 24 private static final double INITIAL BALANCE 1000; 25 26 private JLabel rateLabel; 27 private JTextField rateField; 28 private JButton button; 29 private JTextArea resultArea; 30 private double balance; 31 32 public InvestmentFrame3O 34 35 balance = INITIAL-BALANCE; resultArea = new JTextArea(AREA ROWS. AREA-COLUMS);Explanation / Answer
Error Handling in the program is given below: All the code remain same only the text given in bold is added to your program
class AddInterestListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
double rate;
try
{
rate = Double.parseDouble(rateField.getText());
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog("Intrest rate is not a floating point number");
return -1;
}
if(rate < 0)
{
JOptionPane.showMessageDialog("Intrest rate can not be negative number!");
return -1;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.