The program will all the user to enter the dimensions for the sides of the triangle.
-- I did this and got an email back from my instructor with
Quote
You need to create a separate java file called triangle and then put your logic in it and create an instance of it in your main java file.
Secondly, your math is not good. If you enter 1 1 1 you get zero as the area
that is due to integer division.."
import javax.swing.JOptionPane;
public class RAC08_01 {
public static void main(String[] args)
{
RAC08_01 triangle = new RAC08_01();
String side1;
String side2 ;
String base;
String height;
side1=JOptionPane.showInputDialog("Enter length of side 1");
side2=JOptionPane.showInputDialog("Enter length of side 2");
base=JOptionPane.showInputDialog("Enter length of the base");
height=JOptionPane.showInputDialog("Enter height of the triangle");
int number1;
int number2;
int number3;
int number4;
double area;
number1 = Integer.parseInt( side1 );
number2 = Integer.parseInt( side2 );
number3 = Integer.parseInt( base );
number4 = Integer.parseInt( height );
area=((number3*number4)/2);
System.out.println("The length of side 1 of your triangle is " + number1 + ", the length of side 2 is " + number2 + ", the length of the base is " + number3 +", the height of your triangle is " + number4);
System.out.println("The area of your triangle is " + area);
} }
I do not know how to create a java program with more then 1 .java page.... thanks for the help
This post has been edited by ryclegman: 10 March 2010 - 08:01 AM

New Topic/Question
Reply




MultiQuote








|