My assignment consists of this: I have to design a calculator that allows user to enter the number of triangles. Goals are the following:
-User enters x number of triangles
-Computer automatically generates 3 numbers from my list of numbers between 3 and 13.
-Computer displays those numbers on screen.
-It decides if the numbers represent the sides of a valid triangle. (For example, 5, 5, and 13 do NOT create a triangle).
-If the numbers do not represent a valid triangle, displays an error message
-If the numbers are valid, the program determines, and displays
a) Side classification of the triangle – equilateral, isosceles, or scalene, and
b) The angle classification of the triangle – right, acute, or obtuse
[Here's what I did, but something seems to have gone wrong,as computer only displays "Acute", or "Not valid".]
public class triangle_creator extends javax.swing.JFrame {
private static int side1 = (int) (11 * Math.random() + 3);
private static int side2 = (int) (11 * Math.random() + 3);
private static int side3 = (int) (11 * Math.random() + 3);
private static int userNum;
private static String userInput;
private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
//get number of triangles by user in amountInput field
userInput=amountInput.getText();
side1=Integer.parseInt(userInput);
side2=Integer.parseInt(userInput);
side3=Integer.parseInt(userInput);
//add all sides together
int sumTriangle= side1+ side2+ side3;
// generate error message
if(side1+ side2< side3){
outputArea.setText("Not valid");
}
else{
if (side1==side2 && side1==side3 && side2==side3 )
outputArea.setText("Equilateral");
if (sumTriangle==sumTriangle)
outputArea.setText("Isosceles");
if (side1!=side2&& side1!=side3&& side2!=side3)
outputArea.setText("Scalene");
if (side1*side1+ side2*side2==side3*side3){
outputArea.setText("Triangle is right");
}
else if (side3*side3< side1*side1+ side2*side2)
outputArea.setText("Triangle is acute");
else if (side3*side3> side1*side1+ side2*side2){
outputArea.setText("Triangle is obtuse");
}
else
outputArea.setText("Error");
}
I would really appreciate if you guys could give me at least one tip on how to make this work. Thaaanks!!! :)