
Questions about simple program
Ladies and gents:
I'm a student learning Java at the very beginner level. My tasking is to write a program that takes 3 user inputs for sides of a triangle and calculates area, perimeter, and the cosines of the angles.
Basically, we are asked to create a class called triangle, and a program that will use the triangle class multiple times.
I have having issues with the triangle class.
I've written the code, but I keep getting an error when I compile.
I've been though the program over and over looking for syntax errors and for other mistakes and can't figure it out. Can someone point me in the right direction? Thanks in advance.
JJ
The error is as follows (the carrat under the area line points at the L2):
Triangle.java: 32: ')' expected
area = Math.sqrt(s(sL1)(sL2)(sL3));
^
1 error
The program is below:
public class Triangle
{
public double perimeter (double L1, double L2, double L3);
{
// Perimeter calculations
perimeter = L1+L2+L3;
}
public double area (double L1, double L2, double L3);
{
// Area calculations
double s;
s = (perimeter/2);
area = Math.sqrt(s(sL1)(sL2)(sL3));
}
public double cos (double a, double b, double c);
{
// Cosine calculations
cos = (Math.pow(c,2)Math.pow(a,2)Math.pow(b,2))/(2*a*b);
}
}

All variable you use must be declared, you cannot just write:
area= ....;
area must be declared, the compiler must know what it is, an int, a double,
an instance of the MyxTron class...
So its like:
double area=0.0;
.
.
.
area= (something);
or just
double area=(something);
s(sL2) is ok in the math book, the computer
must have it like: s*(sL2)
Code:
public class Triangle {
// Perimeter calculations
public double perimeter(double L1, double L2, double L3) {
double p = L1 + L2 + L3;
return p;
}
// Area calculations
public double area(double L1, double L2, double L3) {
// perimeter is a method that returns (represents) a double
// value, but you must supply the parameters for it.
double s = (perimeter(L1, L2, L3) / 2);
return Math.sqrt(s * (s  L1) * (s  L2) * (s  L3));
}
// Cosine calculations
public double cos(double a, double b, double c) {
double quack =
(Math.pow(c, 2)  Math.pow(a, 2)  Math.pow(b, 2)) / ( 2 * a * b);
return quack;
// could just as well have written:
// return (Math.pow(c, 2)  Math.pow(a, 2)  Math.pow(b, 2)) / ( 2 * a * b);
}
}
Last edited by sjalle; 10022005 at 06:57 PM.
eschew obfuscation
Similar Threads

By blumoon02k in forum Java
Replies: 4
Last Post: 03242005, 04:39 PM

Replies: 2
Last Post: 03072002, 07:49 AM

By Gordon Reichhardt in forum VB Classic
Replies: 2
Last Post: 01082002, 10:06 AM

By W.Pierce in forum VB Classic
Replies: 1
Last Post: 12112001, 08:28 AM

Replies: 1
Last Post: 07182000, 05:13 PM
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Development Centers
 Android Development Center
 Cloud Development Project Center
 HTML5 Development Center
 Windows Mobile Development Center
