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

Java

 
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 
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 
The copy constructor should do a 'deep' copy:
Java
// copy constructor
public Polynomial(Polynomial p)
{
    coeff = (int[])p.coeff.clone();

}


The toString method could be improved:
Java
public String toString() {
    return coeff[4] + "X^4 + " +
        coeff[3] + "X^3 + " +
        coeff[2] + "X^2 + " +
        coeff[1] + "X + " + coeff[0];
}


The override of the equals method is wrong, the signature must be equals(Object), a standard way to do this is:
Java
public boolean equals(Object obj) {
    if (obj == null || this.getClass() != obj.getClass()) {
        // either obj is null or a different types so can't be equal
        return false;
    }
    final Polynomial other = (Polynomial)obj;

    // compare the two arrays:
    return this.coeff.equals(other.coeff);
}


Sums are hard, your evaluate method can be easily improved:
Java
public double evaluate(double x){
    return (coeff[4] * x^4) +
        (coeff[3] * x^3) +
        (coeff[2] * x^2) +
        (coeff[1] * x) +
        coeff[0];
}


Layout makes code easy to read.
Easy to read makes mistakes easier to spot.
Easier to spot mistakes makes better code.

Finally get in the habit NOW of writing JavaDoc comments for all public methods.


Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

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 
GeneralRe: Please check my program if it is correct Pin
Nagy Vilmos21-Sep-11 21:48
professionalNagy Vilmos21-Sep-11 21:48 
GeneralRe: Please check my program if it is correct Pin
David Skelly21-Sep-11 4:17
David Skelly21-Sep-11 4:17 

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.