121 lines
3.0 KiB
Java
121 lines
3.0 KiB
Java
/**
|
|
* CS1322: Programming Assignment #0 - Fall 2002
|
|
*
|
|
* <PRE>
|
|
* P0Phase3.java
|
|
* Class P0Phase3 - A class designed to learn methods and
|
|
* casting, as well as working with expressions.
|
|
*
|
|
* Revisions: 1.0 Aug. 26, 2002
|
|
* Created the P0Phase3 class
|
|
*
|
|
* 1.1 Aug. 26, 2002
|
|
* Finished, Compiled, Tested
|
|
*
|
|
* </PRE>
|
|
*
|
|
* Collaboration Statement:
|
|
* I worked on the homework assignment alone, using only
|
|
* course materials.
|
|
*
|
|
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @version Version 1.1, Aug. 26, 2002
|
|
*/
|
|
|
|
public class P0Phase3 {
|
|
|
|
///////////
|
|
//Methods//
|
|
///////////
|
|
|
|
/**
|
|
* Truncate double value into an int
|
|
*
|
|
* <br><br>
|
|
* @param d, value to be truncated
|
|
* @return truncated value d
|
|
*/
|
|
public int roundOff(double d){
|
|
return ((int) d);
|
|
}
|
|
|
|
/**
|
|
* Divide dividend by divisor
|
|
*
|
|
* <br><br>
|
|
* @param dividend, value to be divided
|
|
* @param divisor, parts that the divisor will be split into
|
|
* @return quotient of dividend and divisor
|
|
*/
|
|
public double divide(int dividend, int divisor){
|
|
return (((double)dividend / divisor));
|
|
}
|
|
|
|
/**
|
|
* Mulitply x by 2.5
|
|
*
|
|
* <br><br>
|
|
* @param x value to be multiplied by 2.5
|
|
* @return value of x*2.5
|
|
*/
|
|
public double twoANDAHalfTimes(int x){
|
|
return ((double)(x*2.5));
|
|
}
|
|
|
|
/**
|
|
* Square the value x
|
|
*
|
|
* <BR><BR>
|
|
* @param x value to be squared
|
|
* @return value of the square
|
|
*/
|
|
public double square(double x){
|
|
return (x*x);
|
|
}
|
|
|
|
/**
|
|
* Find the value of the quadratic
|
|
* <br><br>
|
|
* @param x,a,b,c values to be used in quadratic
|
|
* @return value of the equation with given values
|
|
*/
|
|
public double quadratic(double x, int a, int b, int c){
|
|
//no typecasting needed, the equation is promoted
|
|
//to double because x is a double
|
|
return (a*(x*x) + b*x + c);
|
|
}
|
|
|
|
/**
|
|
* Solve the Quadratic Equation with given values
|
|
* <br><br>
|
|
* @param a,b,c values to be used in quadratic equation
|
|
* @return value of the quadratic
|
|
*/
|
|
public double solveQuadr(double a, double b, double c){
|
|
return (-b + Math.sqrt((b*b) - (4*a*c)))/(2*a);
|
|
}
|
|
//////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Debugging main for class P0Phase3.
|
|
* This method will rigorously test my code.
|
|
*
|
|
* <br><br>
|
|
* @param args IGNORED
|
|
*/
|
|
public static void main(String[] args) {
|
|
//Create variable to test out class
|
|
P0Phase3 tester = new P0Phase3();
|
|
|
|
//test methods
|
|
System.out.println(tester.roundOff(5.454));
|
|
System.out.println(tester.divide(10,3));
|
|
System.out.println(tester.twoANDAHalfTimes(5));
|
|
System.out.println(tester.square(2));
|
|
System.out.println(tester.quadratic(2,2,3,4));
|
|
System.out.println(tester.solveQuadr(1,2,1));
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class P0Phase3
|