Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,345 members, 7,819,221 topics. Date: Monday, 06 May 2024 at 12:55 PM

Please Help With This Java Program. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Help With This Java Program. (1467 Views)

Java Program To Solve Quadratic Equation-dealwap / How To Create A Small Gui(graphical User Interface) Using Jframe In Java Program / Import Dll Into Java Program (2) (3) (4)

(1) (Reply) (Go Down)

Please Help With This Java Program. by Emyemyberry(m): 9:15pm On Aug 11, 2014
Write a java program that is capable of calculating the length of a triangle using cosine rule

hint1:let the lenghts be L1,L2, and L3

hint2sadL1)^2 = (L2)^2 (L3)^2 - 2(L2L3cosL)
thanks in advance,awaiting ur solutions.
Re: Please Help With This Java Program. by fattbabakay(m): 10:04pm On Aug 11, 2014
Guys just dey view dey commot...smh
Re: Please Help With This Java Program. by mj(m): 10:03am On Aug 12, 2014
Emyemyberry: Write a java program that is capable of calculating the length of a triangle using cosine rule

hint1:let the lenghts be L1,L2, and L3

hint2sadL1)^2 = (L2)^2 (L3)^2 - 2(L2L3cosL)
thanks in advance,awaiting ur solutions.

pls provide the fomular in plain text??
Re: Please Help With This Java Program. by Emyemyberry(m): 10:10am On Aug 12, 2014
mj:

pls provide the fomular in plain text??
here

Re: Please Help With This Java Program. by Olyboy16(m): 8:08pm On Aug 12, 2014
Emyemyberry: here
Ahem, the guy said in plain text! Not picture! I'm wilin to help
Re: Please Help With This Java Program. by Emyemyberry(m): 8:17pm On Aug 12, 2014
Olyboy16:
Ahem, the guy said in plain text! Not picture! I'm wilin to help
sori,bt i dnt undstnd wot you mean by plain inbtw,isn't my 1st post in plain?,pls xplahn.
Re: Please Help With This Java Program. by Emyemyberry(m): 8:17pm On Aug 12, 2014
Olyboy16:
Ahem, the guy said in plain text! Not picture! I'm wilin to help
sori,bt i dnt undstnd wot you mean by plain text inbtw,isn't my 1st post in plain?,pls xplahn.
Re: Please Help With This Java Program. by Olyboy16(m): 8:23pm On Aug 12, 2014
Emyemyberry: sori,bt i dnt undstnd wot you mean by plain text inbtw,isn't my 1st post in plain?,pls xplahn.
Owkay, write the formular out in ur post..u get dat?
Re: Please Help With This Java Program. by Olyboy16(m): 8:47pm On Aug 12, 2014
Oh, the cosine rule. Owkay.
 
public class cosine{
public int cosine(){
double a,b,c;
c=Math.sqrt((a**2+b**2) - ((2*a*b)*Math.cos(c)));
return c;
}

}


you'r welcome
Re: Please Help With This Java Program. by Intellab(m): 8:48pm On Aug 12, 2014
//Try this

import java.util.Scanner;
public class CosineTriangle
{
public static void main (string[]args)
{
//author Speed23
//Program to calculate length of triangle using cosine rule

/* Not Tested. But should work */

Scanner user_input = new Scanner(System.in);

float l1,l2,l3,ans;
System.out.print("Enter your l1"wink;
l1=user_input.next()f;
System.out.print("Enter your l2"wink;
l2=user_input.next()f;
System.out.print("Enter your l3"wink;
l3=user_input.next()f;

// Applying formular

ans= ((l1^2+l2^2-l3^2)/2*l1*l2) - cos(l1)

System.out.println("Answer is = "+ans);

}
}

1 Like

Re: Please Help With This Java Program. by sealteam66(m): 10:33pm On Aug 12, 2014
The first problem I had with your programme was how to calculate the cosine of a an angle in degree which I have solved

Math.cos((Math. PI)/angle)

Now before I speak about the programme, let agree that cosine rule is

C sq = A sq + B sq +2ABcosangle

where C is certainly the hypotenuse
A or B opposite or adjacent respectively
and angle is the angle between the adjacent and opposite, i.e. facing the hypotenuse
If you write a programme that calculates the lenght of a side using the formulae you will have a logical error because the programme wil be looking for hypotenuse always, when you could actually be looking for opposite or adjacent!
For the programme to work,
The programme would have to ask you which of the sides is being looked for either hypotenuse, adjacent or opposite
after which it accepts value, computes and displays the result
What I've done is the algorithm design, which is the first step in programming
After this you commence coding

Call me on 08090642393, let me know that is in it for me
Re: Please Help With This Java Program. by Olyboy16(m): 12:55am On Aug 13, 2014
sealteam66: The first problem I had with your programme was how to calculate the cosine of a an angle in degree which I have solved

Math.cos((Math. PI)/angle)

Now before I speak about the programme, let agree that cosine rule is

C sq = A sq + B sq +2ABcosangle

where C is certainly the hypotenuse
A or B opposite or adjacent respectively
and angle is the angle between the adjacent and opposite, i.e. facing the hypotenuse
If you write a programme that calculates the lenght of a side using the formulae you will have a logical error because the programme wil be looking for hypotenuse always, when you could actually be looking for opposite or adjacent!
For the programme to work,
The programme would have to ask you which of the sides is being looked for either hypotenuse, adjacent or opposite
after which it accepts value, computes and displays the result
What I've done is the algorithm design, which is the first step in programming
After this you commence coding

Call me on 08090642393, let me know that is in it for me
wat the?? Call u? For few lines of codes?? This is cwious!! Wish i had my computer here.
You dont need to know wich part of d triangle to solve! Its cosine rule for God's sake. It was designed to solve sides of an isoceles triangle!! Na wa 4 u o. Nd u dey form boss
Re: Please Help With This Java Program. by LordRahl001: 4:38pm On Aug 13, 2014
This should work perfectly.


import java.util.Scanner;
public class CosineAssignment
{
//L1^2=L2^2+L32-2L2L3cosL


public static void main(String[] args)
{
double l1, l2, angle;

Scanner in=new Scanner(System.in);

System.out.println("Supply The First Length:"wink;
l1=in.nextDouble();

System.out.println("Supply The Second Length:"wink;
l2=in.nextDouble();

System.out.println("Please Supply The Angle"wink;
angle=in.nextDouble();

double l1sq=squares(l1); //squaring The First Length
double l2sq=squares(l2); //squaring The Second Length

double cos_angle=Math.cos(Math.toRadians(angle)); //getting the cosine of the angle

double cs=l1sq+l2sq;

double csv=(2*l1*l2*cos_angle);

double ans=Math.sqrt(cs-csv);

System.out.println("The Length is: "+ans);
}


private static double squares(double fig){
return fig*fig; //this is just to square the lengths.
}
}

Hope i am not late??
Re: Please Help With This Java Program. by LordRahl001: 4:40pm On Aug 13, 2014
Olyboy16: Oh, the cosine rule. Owkay.
 
public class cosine{
public int cosine(){
double a,b,c;
c=Math.sqrt((a**2+b**2) - (2*a*b*Math.cos(c)));
return c;
}

}


you'r welcome
Your cosine would return a wrong value.
Re: Please Help With This Java Program. by LordRahl001: 4:47pm On Aug 13, 2014
sealteam66: The first problem I had with your programme was how to calculate the cosine of a an angle in degree which I have solved

Math.cos((Math. PI)/angle)

Now before I speak about the programme, let agree that cosine rule is

C sq = A sq + B sq +2ABcosangle

where C is certainly the hypotenuse
A or B opposite or adjacent respectively
and angle is the angle between the adjacent and opposite, i.e. facing the hypotenuse
If you write a programme that calculates the lenght of a side using the formulae you will have a logical error because the programme wil be looking for hypotenuse always, when you could actually be looking for opposite or adjacent!
For the programme to work,
The programme would have to ask you which of the sides is being looked for either hypotenuse, adjacent or opposite
after which it accepts value, computes and displays the result
What I've done is the algorithm design, which is the first step in programming
After this you commence coding

Call me on 08090642393, let me know that is in it for me
its definitely not about hypothenuse its just about you finding the length facing the angle. basically, its represented as:
The lengths a,b and c
The angles are A,B and C
so 2 sides and an angle are give and u are asked to get the length of the last side.
most times the unknown side always have its angle known or computed somehow
so the Formula actually is:
to find length c

c=SQRT(a*2b*2+2abcosC)

so thats the right formula. The Cases were misleading tho!!
Re: Please Help With This Java Program. by Olyboy16(m): 7:35pm On Aug 13, 2014
LordRahl001:
Your cosine would return a wrong value.
No it wont, check my codes very well.
Re: Please Help With This Java Program. by LordRahl001: 7:50pm On Aug 13, 2014
Olyboy16:
No it wont, check my codes very well.
I figured u'd say that but in java, Math.cos() expects d variable in radians but u r supply diff nomenclature here!! Try it out and c d output. Coz 60 shud give u 0.5 but Math.cos() will give u another thing entirely. Cheers,
Re: Please Help With This Java Program. by Olyboy16(m): 7:59pm On Aug 13, 2014
LordRahl001: I figured u'd say that but in java, Math.cos() expects d variable in radians but u r supply diff nomenclature here!! Try it out and c d output. Coz 60 shud give u 0.5 but Math.cos() will give u another thing entirely. Cheers,
Thanks. I'm much of a consumer based softwares guy in java..thanks

1 Like

Re: Please Help With This Java Program. by LordRahl001: 8:22pm On Aug 13, 2014
Olyboy16:
Thanks. I'm much of a consumer based softwares guy in java..thanks
you are welcome sir!!!
Re: Please Help With This Java Program. by Emyemyberry(m): 12:23am On Aug 14, 2014
LordRahl001: This should work perfectly.


import java.util.Scanner;
public class CosineAssignment
{
//L1^2=L2^2+L32-2L2L3cosL


public static void main(String[] args)
{
double l1, l2, angle;

Scanner in=new Scanner(System.in);

System.out.println("Supply The First Length:"wink;
l1=in.nextDouble();

System.out.println("Supply The Second Length:"wink;
l2=in.nextDouble();

System.out.println("Please Supply The Angle"wink;
angle=in.nextDouble();

double l1sq=squares(l1); //squaring The First Length
double l2sq=squares(l2); //squaring The Second Length

double cos_angle=Math.cos(Math.toRadians(angle)); //getting the cosine of the angle

double cs=l1sq+l2sq;

double csv=(2*l1*l2*cos_angle);

double ans=Math.sqrt(cs-csv);

System.out.println("The Length is: "+ans);
}


private static double squares(double fig){
return fig*fig; //this is just to square the lengths.
}
}

Hope i am not late??
omg,thanks alot boss,more grace to you
Re: Please Help With This Java Program. by Emyemyberry(m): 12:28am On Aug 14, 2014
Special thanks to olyboy16 , intellab , lordRahl001

1 Like

Re: Please Help With This Java Program. by LordRahl001: 9:58am On Aug 14, 2014
Emyemyberry: omg,thanks alot boss,more grace to you
u are welcome boss!!! God bless you too.

1 Like

Re: Please Help With This Java Program. by sealteam66(m): 10:28pm On Aug 16, 2014
LordRahl001:
u are welcome boss!!! God bless you too.

Emyemyberry I acted like a dick head, i believe you have resolved the issue, If you still want the program, I can write it for you, absolutely FREE!
Re: Please Help With This Java Program. by Emyemyberry(m): 8:07am On Aug 17, 2014
sealteam66:

Emyemyberry I acted like a dick head, i believe you have resolved the issue, If you still want the program, I can write it for you, absolutely FREE!
thanks man for the concern,hope you can do smthing wt the "if statement" for the question
Re: Please Help With This Java Program. by fattbabakay(m): 9:58am On Aug 17, 2014
sealteam66: The first problem I had with your programme was how to calculate the cosine of a an angle in degree which I have solved

Math.cos((Math. PI)/angle)

Now before I speak about the programme, let agree that cosine rule is

C sq = A sq + B sq +2ABcosangle

where C is certainly the hypotenuse
A or B opposite or adjacent respectively
and angle is the angle between the adjacent and opposite, i.e. facing the hypotenuse
If you write a programme that calculates the lenght of a side using the formulae you will have a logical error because the programme wil be looking for hypotenuse always, when you could actually be looking for opposite or adjacent!
For the programme to work,
The programme would have to ask you which of the sides is being looked for either hypotenuse, adjacent or opposite
after which it accepts value, computes and displays the result
What I've done is the algorithm design, which is the first step in programming
After this you commence coding

Call me on 08090642393, let me know that is in it for me
Hypotenuse?? Na right angled triangle??
Re: Please Help With This Java Program. by sealteam66(m): 1:05pm On Aug 17, 2014
Emyemyberry: thanks man for the concern,hope you can do smthing wt the "if statement" for the question

Elaborate on the if statement

(1) (Reply)

Mail Crypt - Safest Way To Send Vital Information / Dump For Oracle Database 11g: SQL Fundamentals I 1Z0-051 / Nigerians, Other African Developers Shine At Facebook’s Annual F8 Conference

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 45
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.