Click here to Skip to main content
15,914,160 members
Home / Discussions / Java
   

Java

 
GeneralRe: How to calculating Business Hours in java Pin
Nagy Vilmos22-Sep-11 0:37
professionalNagy Vilmos22-Sep-11 0:37 
AnswerRe: How to calculating Business Hours in java Pin
jschell22-Sep-11 8:41
jschell22-Sep-11 8:41 
GeneralRe: How to calculating Business Hours in java Pin
Nagy Vilmos22-Sep-11 22:57
professionalNagy Vilmos22-Sep-11 22:57 
GeneralRe: How to calculating Business Hours in java Pin
jschell23-Sep-11 12:19
jschell23-Sep-11 12:19 
GeneralRe: How to calculating Business Hours in java Pin
TorstenH.24-Sep-11 7:53
TorstenH.24-Sep-11 7:53 
GeneralJavascript in livecycle Pin
Incognito121-Sep-11 4:20
Incognito121-Sep-11 4:20 
GeneralRe: Javascript in livecycle Pin
Nagy Vilmos21-Sep-11 4:59
professionalNagy Vilmos21-Sep-11 4:59 
QuestionPlease check my program if it is correct Pin
mastdesi20-Sep-11 16:47
mastdesi20-Sep-11 16:47 
I have to do my first assignment for my java class for friday this week. So due in 3 days. I wrote the polynomial class but haven't done the driver for it yet as i don't know if my polynomial class is good. Please check and let me know if i have done correctly according to my assignment details (assignment pdf file can be downloaded here http://www.2shared.com/document/7YITxJL1/A1_online.html[^]). I am missing the numberOfTerms as i can't seem to figure that out.

Please help me out.

Polynomial.java
Java
public class Polynomial
{
	private int[] coeff = new int[5];
	public Polynomial()
	{
		coeff = null;
	}
	// constructor with 5 parameter 
	public Polynomial(int c0, int c1, int c2, int c3, int c4)
	{
		this.coeff[0] = c4;
		this.coeff[1] = c3;
		this.coeff[2] = c2;
		this.coeff[3] = c1;
		this.coeff[4] = c0;
	}
	// copy constructor  
	public Polynomial(Polynomial p)
	{
		coeff = p.coeff;

	}
	
	// Get Method
	public int getCoeff(int i)
	{
		return this.coeff[i];
	}
	
	// Set Method
	public boolean setCoef(int pos, int num)
	{
		if (pos <= 4 || pos >= 0 )
			{
			coeff[pos] = num;
			return true;
			}
		else
			return false;
	}

	// toString
	public String toString()
	{
		return coeff[4]+"X4"+" + "+coeff[3]+"X3"+" + "+coeff[2]+"X2"+" + "+coeff[1]+"X"+" + "+coeff[0];
	}
	
	// Equals
	public boolean equals(Polynomial p)
	{
		if ((p.coeff[4] != coeff[4]) ||(p.coeff[3] != coeff[3]) ||(p.coeff[2] != coeff[2]) ||(p.coeff[1] != coeff[1]) ||(p.coeff[0] != coeff[0]) )
			return false;
		return true;
	}
	
	// Add
	public Polynomial add(Polynomial p)
	{
		return (new Polynomial(p.coeff[4]+coeff[4],p.coeff[3]+coeff[3],p.coeff[2]+coeff[2],p.coeff[1]+coeff[1],p.coeff[0]+coeff[0]));
	}

	// Derivative
	public Polynomial derive()
	{
		return (new Polynomial(coeff[4]*4,coeff[3]*3,coeff[2]*2,coeff[1],0));
	}

	// Evaluate
	public double evaluate(double x){
		return coeff[4]*x*x*x*x+coeff[3]*x*x*x+coeff[2]*x*x+coeff[1]*x+coeff[0];
	}

}

AnswerRe: Please check my program if it is correct Pin
Richard MacCutchan20-Sep-11 21:53
mveRichard MacCutchan20-Sep-11 21:53 
AnswerRe: Please check my program if it is correct Pin
Nagy Vilmos20-Sep-11 23:30
professionalNagy Vilmos20-Sep-11 23:30 
GeneralRe: Please check my program if it is correct Pin
David Skelly21-Sep-11 3:44
David Skelly21-Sep-11 3:44 
GeneralRe: Please check my program if it is correct Pin
mastdesi21-Sep-11 8:33
mastdesi21-Sep-11 8:33 
AnswerRe: Please check my program if it is correct Pin
TorstenH.21-Sep-11 2:03
TorstenH.21-Sep-11 2:03 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos21-Sep-11 2:33
professionalNagy Vilmos21-Sep-11 2:33 
GeneralRe: Please check my program if it is correct Pin
David Skelly21-Sep-11 3:57
David Skelly21-Sep-11 3:57 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos21-Sep-11 5:01
professionalNagy Vilmos21-Sep-11 5:01 
GeneralRe: Please check my program if it is correct Pin
David Skelly21-Sep-11 5:53
David Skelly21-Sep-11 5:53 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos21-Sep-11 5:55
professionalNagy Vilmos21-Sep-11 5:55 
GeneralRe: Please check my program if it is correct Pin
David Skelly21-Sep-11 22:28
David Skelly21-Sep-11 22:28 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos21-Sep-11 22:58
professionalNagy Vilmos21-Sep-11 22:58 
GeneralRe: Please check my program if it is correct Pin
David Skelly22-Sep-11 1:31
David Skelly22-Sep-11 1:31 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos22-Sep-11 1:41
professionalNagy Vilmos22-Sep-11 1:41 
GeneralRe: Please check my program if it is correct Pin
mastdesi21-Sep-11 9:14
mastdesi21-Sep-11 9:14 
GeneralRe: Please check my program if it is correct Pin
TorstenH.21-Sep-11 19:20
TorstenH.21-Sep-11 19:20 
GeneralRe: Please check my program if it is correct Pin
TorstenH.21-Sep-11 19:19
TorstenH.21-Sep-11 19:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.