Question: Problem Description In this activity we are once again revisiting an activity from earlier in the semester. Write an application that prompts the user to
Problem Description
In this activity we are once again revisiting an activity from earlier in the semester. Write an application that prompts the user to enter the lengths of the sides of a triangle. A JButton labelled Calculate should compute the area of the triangle using Heron's formula below in which s represents half of the perimeter of the triangle, and a b and c represent the lengths of the three sides. Display the area to three decimal places using a DecimalFormat object and a JLabel. Your program should NOT attempt to perform the calculation when enter is pressed in on the text fields.
Program Design
Create a new file called TriangleCalculator.java, add a class called TriangleCalculator that extends JPanel and include a main method so that this class is a driver class as well. The screenshot below shows a sample GUI for this activity. You may use the same layout or design your own. Either way, your program must include the GUI components and functional behaviors listed here.
JButton: Include a JButton that will calculate the area based upon the values entered for each side in the JTextFields. See the error handling section below for how to address unexpected values.
JTextFields: Include JTextFields that will allow the user to specify the lengths of the sides a b and c These values should be parsed using Double.parseDouble
JLabels: Include JLabels to take each JTextField to identify sides a b and c
JLabel: Include a JLabel that includes the tagged value for area
Error Handling
When the Calculate JButton is pressed, it will read the current side lenth values from the three JTextField components. If the user specified a nonnumerical value for the volume, you should catch the NumberFormatException and display a JOptionPane with the message "Please enter numbers only!".
If the user specified a negative number, display a JOptionPane with the message "Please enter positive values only!".
If the user specified side lengths that do not form a triangle, such as display a JOptionPane with the message "Side lengths do not form a triangle!".
Implementation Guide
Expand the folder named TriangleCalculator and create a new file named TriangleCalculator.java and open it
Design a program to satisfy the requirements in the Problem Description and the Program Design above
Test the program and pay particular attention to boundaryedge cases and invalid input.
Commit the changes to your local repository with a message stating that Lab Activity is completed.
Push the changes from your local repository to the github classroom repository.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
