Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-2010, 01:36 PM
Member
 
Join Date: Feb 2010
Posts: 16
Rep Power: 0
Sean_J is on a distinguished road
Default Basic Java Computation Help Ap Computer Science
Hello Guys here is the problem that im stated with and in my code im getting errors because i cant find out how to input the code the correct way. Here is the problem.

Project… Compute This

Create a new project called ComputeThis having a class called Tester. The main method of Tester should calculate the value of the following formulas and present the answers as shown.
d1 = 3πsin(187°) + |cos(122°)|
…Remember that the arguments of sin and cos must
be in radians.
d2 = (14.72)3.801 + ln 72
…ln means log base e
The output of your code should appear as follows:
d1 = -0.618672237585067
d2 = 27496.988867001543


This is what i have so far as my code.

PHP Code:
public class lesson6
  
//Sean Josephson
  //2/8/2010
  //Lesson 6 Project
{
  public static 
void main(String args [])
  {
    
System.out.println d1=3Math.Pi doublesin(double toRadians(double187)+double abs(double cos(double122))
  }

Anything Helping correcting my brutal slaying of this advanced math method would be helpful.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-09-2010, 02:07 PM
Senior Member
 
Join Date: Feb 2010
Location: Ljubljana, Slovenia
Posts: 302
Rep Power: 1
m00nchile is on a distinguished road
Default
First of all, make sure your syntax gets a bit of a brushwork. All methods in Java are of the type:
Code:
method(argtype arg1, argtype arg2....);
//or with no arguments
method();
Next, while you can do a lot of things in a single line of code, it can get very illegible and hard to maintain, so I would reccomend slicing up your code into smaller bits and pieces.
Code:
public class Assignment {
   public static double toRadians(double degrees) {
       return (double)((Math.PI*2*degrees)/360);
   }
   public static void main(String[] args) {
      double sinargDegs = 187;
      double cosargDegs = 122;
      double sinarg = toRadians(sinargDegs);
      double cosarg = toRadians(cosargDegs);
      //rest of code for calculation
   }
}
You have quite a bit of help here, so I think you can go on from this to finishing your task by yourself.

EDIT: Fixed getting PI variable from Math class
EDIT2: Just browsed through Math api, there already is a toRadian() method there.

Last edited by m00nchile; 02-09-2010 at 03:34 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-09-2010, 04:31 PM
Member
 
Join Date: Feb 2010
Posts: 16
Rep Power: 0
Sean_J is on a distinguished road
Default
thanks m8 i actually finished htis up nicely and i got this as a result to get the correct output.
PHP Code:
public class lesson6
  
//Sean Josephson
  //2/8/2010
  //Lesson 6 Project
{
  public static 
void main(String args[])
  {
    
double a=Math.PI
    
double x=Math.toRadians(187);
    
double z=Math.toRadians(122);
    
double b=Math.sin(x);
    
double c=Math.cos(z);
    
double e=Math.abs(c);
    
double d1=3*(a)*(b)+(e);
    
System.out.println("d1"+" ""="+" "d1);
    
System.out.println(" ");
    
double ln=Math.log(72); 
    
double f=Math.pow(14.72,3.801);
    
double d2=(f)+ln;
    
System.out.println("d2"+" "+"="+" "+d2);
  }

Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-09-2010, 04:42 PM
Senior Member
 
Join Date: Feb 2010
Location: Ljubljana, Slovenia
Posts: 302
Rep Power: 1
m00nchile is on a distinguished road
Default
Just a minor nitpick,
You don't need to build strings like that, you could simply write:
Code:
System.out.println("d1 = "+d1);
Make life simpler for yourself
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-09-2010, 04:50 PM
Member
 
Join Date: Feb 2010
Posts: 16
Rep Power: 0
Sean_J is on a distinguished road
Default
Ha, that would have shortened it up a little already submitted it though :"(
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-09-2010, 07:35 PM
Senior Member
 
Join Date: Feb 2010
Location: Ljubljana, Slovenia
Posts: 302
Rep Power: 1
m00nchile is on a distinguished road
Default
It's no biggie, what you wrote is correct, just a bit overcomplicated
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-10-2010, 01:10 PM
Member
 
Join Date: Feb 2010
Posts: 16
Rep Power: 0
Sean_J is on a distinguished road
Default
Can someone post a revision of this that will use the least amount of memory?? (Very please and thank you) Just so i know what to not have to do in the future. (:
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Tags
java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The art and science of java islam-morad New To Java 9 12-01-2009 12:02 PM
Panic Attack Setting in Why did I take Computer Science...only to fail gallimaufry New To Java 5 10-25-2008 08:42 AM
Software Engineer...Computer Science Major giganews35 Introductions 2 09-14-2008 09:19 AM
Help On Computer Science Final!!!! Java Program Help!!!! BSOS New To Java 1 12-11-2007 04:54 AM
JAVA software solutions:For AP Comp. Science (Lewis,Loftus,Cocking) padutch New To Java 4 11-27-2007 11:59 PM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 08:46 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org