import javax.swing.*;
public class trigFun
{
public static void main(String args[])
{
String s;
s=JOptionPane.showInputDialog(null, "Enter number to take factorial of");
int fact=Integer.parseInt(s);
System.out.println("Factorial of("+s+")="+factorial(fact));
s=JOptionPane.showInputDialog(null, "Enter a radian value");
double radian=Double.parseDouble(s);
System.out.println("sin("+radian+")="+sin(radian));
System.out.println("cos("+radian+")="+cos(radian));
System.out.println("tan("+radian+")="+tan(radian));
}
public static double factorial(int a)
{
double s=1;
for(double i=a; i>0; i--)
{
s=s*i;
}
return s;
}
public static double sin(double radian)//calculated using mclauren series
{
int sgn;
if (radian<-3.141592653589793)
sgn=0;
else
sgn=1;
if (sgn==0)
{
while(radian<-3.141592653589793)
{
radian=radian+6.283185307179586;
}
}
if (sgn==1)
{
while(radian>3.141592653589793)
{
radian=radian-6.283185307179586;
}
}
double result=0;
int j=1;
for (double i=1; i<=21;i=i+2)
{ //21 is a large arbitrary value
if(j%2==0)
{
result=result-1*(pow(radian, i))/((double)(factorial((int)(i))));
}
else
{
result=result+1*(pow(radian, i))/((double)(factorial((int)(i))));
}
j=j+1;
}
return result;
}
public static double cos(double radian)
{
int sgn;
if (radian<0)
sgn=0;
else
sgn=1;
if (sgn==0)
{
while(radian<-3.141592653589793)
{
radian=radian+6.283185307179586;
}
}
if (sgn==1)
{
while(radian>3.141592653589793)
{
radian=radian-6.283185307179586;
}
}
double res=0;
int j=1;
for (double i=0; i<=20;i=i+2)
{
if(j%2==0)
{
res=res-1*(pow(radian, i))/((double)(factorial((int)(i))));
}
else
{
res=res+1*(pow(radian, i))/((double)(factorial((int)(i))));
}
j=j+1;
}
return res;
}
public static double tan(double radian)
{
int sgn;
if (radian<0)
sgn=0;
else
sgn=1;
if (sgn==0)
{
while(radian<-3.141592653589793)
{
radian=radian+6.283185307179586;
}
}
if (sgn==1)
{
while(radian>3.141592653589793)
{
radian=radian-6.283185307179586;
}
}
return sin(radian)/cos(radian);
}
public static double pow(double b, double exp)
{ // an incomplete pow function that only calculates correctly for integer exp's
double res=1;
if(exp==0 && b==0)
return 1./0;
if(exp==0 && b !=0)
return 1;
for(int i=1; i<=exp; i++)
{
res=res*b;
}
return res;
}
}
Wednesday
//
Labels:
JAVA PROJECTS
//
1 comments
//
import javax.swing.*;
public class Sqroot
{
public static void main(String args[])
{
String s=JOptionPane.showInputDialog("Enter a number");
double no=Double.parseDouble(s);
System.out.println("Square root of " + no +"="+Sqroot(no));
}
public static double Sqroot(double no)
{ //square root Babylonian method
double esti=no;
double divi=2;
//below 100 is arbitrary, for very small decimals j values must be large
for(int j=0; j<100; j++)
{
esti=no/divi;
esti=(esti+divi)/2; //find average estimate & divisor
divi=esti;
}
return esti;
}
}
//
Labels:
JAVA PROJECTS
//
0
comments
//
/*
This is a simple Java program.
*/
class Example
{
// program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}
Save this with same name as that of class. In this case it is example.java
Running a program in java takes place in two important steps:
- Compiling a program by writing the code javac file-name.java
- Running a program by writing the code java file-name
Tuesday
//
Labels:
java
//
0
comments
//
Encapsulation is basically a process of binding together certain codes into one unit.
In Java the base of encapsulation is the class. A class defines the anatomy and behavior (knowledge and code) that will be aggregate by a set of objects. Each article of a accustomed class contains the anatomy and behavior authentic by the class, as if it were formed out by a cast in the appearance of the class.
Since the purpose of a class is to abbreviate complexity, there's mechanisms for hiding the complication of the accomplishing central the class. Each action or variable in a class may be apparent private or public. The accessible interface of a class represents everything that alfresco users of the class charge to know, or may know. The private methods & ability can alone be accessed by members that is a affiliate of the class. Therefore,any added member that is not a affiliate of the class cannot admission a clandestine action or variable.
//
Labels:
java
//
0
comments
//
Inheritance is the action by which class acquires the backdrop of addition class. This is important because it supports the abstraction of hierarchical classification. A lot of ability is fabricated acquiescent by hierarchical (that is, top-down) classifications. For example, a Golden Retriever is allotment of the allocation dog, which in about-face is allotment of the mammal class, which is beneath the beyond chic animal. Without the use of hierarchies, anniversary article would crave to ascertain all of its characteristics explicitly. However, by use of inheritance, an article crave alone ascertain those qualities that accomplish it unique aural its class. It can accede its accepted attributes from its parent. Thus, it is the inheritance apparatus that makes it achievable for article to be a specific instance of a added accepted case
//
Labels:
java
//
0
comments
//
An capital aspect of acquisitive programming is abstraction. Humans manage complexity through abstraction. For example, humans do not anticipate of a auto as a set of tens of bags of alone parts. They anticipate of it as a categorical article with its own alone behavior. This absorption allows humans to accomplish use of a auto to drive to the grocery store after getting afflicted by the complication of the locations that anatomy the automobile. They can avoid the data of how the engine, transmission, & braking systems work. In lieu they are chargeless to advance the article as a whole.This is what known as ABSTRACTION.
//
Labels:
java
//
0
comments
//
Object-oriented programming is at the amount of Java. In fact, all Java programs are object oriented. This isn't an advantage the way that it is in C++, for example. OOP is so integral to Java that you have to accept its basal attempt before you can address even simple Java programs.
BASIC PRINCIPLES OF OOPS :
- Abstraction
- Inheritance
- Encapsulation
- Polymorphism
//
Labels:
java
//
0
comments
//
Powered by Blogger.
