|
I could give you the benefit of my experience. But I won't. I'll give you many other peoples'. Start here[^].
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
thanks, oh you know how to manipulate sprite?..
because i can't sprite from many image.....
|
|
|
|
|
You don't use many images for a sprite, you use 1 large image which contains all the frames you need. I suggest you start by following Peter's link.
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
can I make an application using speech recognition techneqiues
with java ???? or I've to make it with c#
|
|
|
|
|
Yes, look here[^] for help.
|
|
|
|
|
|
|
I can't figure out a few things.
- When i do the derivative it still keeps the exponents like x^4 when it should be x^3, when it should be doing -1 for the exponents.
- the toString method is suppose to return only the non zero terms.
- in poly 6 i want to store coefficients/values of 1 multiplied by 3
- and compare each polynomial to each other and report whether they are the same. like compare 0 with 1-7 and then 1 with 2-7 and so on.
I can seem to figure out a way for it without getting a error when compiling. Been trying for hours today and in the end thought of asking here for some assistance.
assignment pdf file can be downloaded here http://www.2shared.com/document/7YITxJL1/A1_online.html
Almost completed Driver Class
import java.util.*;
public class Driver
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Polynomial[] poly = new Polynomial[8];
int[] tmp = new int[5];
System.out.println("Enter a polynomial");
for(int i=0; i<5;i++)
{
System.out.print("Coefficient for X^" + i + ": ");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[0] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
System.out.println("Enter a polynomial");
for(int i=0; i<5;i++)
{
System.out.print("Coefficient for X^" + i + ": ");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[1] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
Random obj= new Random();
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[2] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[3] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[4] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
poly[5] = new Polynomial(poly[0].add(poly[2]));
poly[7] = new Polynomial(poly[4].derive());
System.out.print("Enter a double value for X: ");
double x = input.nextDouble();
poly[6] = new Polynomial(poly[1]);
System.out.println("Polynomial 0 : " + poly[0] + " has " + poly[0].numberOfTerms() + " terms and evaluates to " + poly[0].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 1 : " + poly[1] + " has " + poly[1].numberOfTerms() + " terms and evaluates to " + poly[1].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 2 : " + poly[2] + " has " + poly[2].numberOfTerms() + " terms and evaluates to " + poly[2].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 3 : " + poly[3] + " has " + poly[3].numberOfTerms() + " terms and evaluates to " + poly[3].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 4 : " + poly[4] + " has " + poly[4].numberOfTerms() + " terms and evaluates to " + poly[4].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 5 : " + poly[5] + " has " + poly[5].numberOfTerms() + " terms and evaluates to " + poly[5].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 6 : " + poly[6] + " has " + poly[6].numberOfTerms() + " terms and evaluates to " + poly[6].evaluate(x) + " for x = " + x);
System.out.println("Polynomial 7 : " + poly[7] + " has " + poly[7].numberOfTerms() + " terms and evaluates to " + poly[7].evaluate(x) + " for x = " + x);
}
}
Almost Completed Polynomial Class
public class Polynomial
{
private int[] coeff = new int[5];
public Polynomial()
{
coeff[0] = 0;
coeff[1] = 0;
coeff[2] = 0;
coeff[3] = 0;
coeff[4] = 0;
}
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;
}
public Polynomial(Polynomial p)
{
coeff = (int[])p.coeff.clone();
}
public int getCoeff(int i)
{
return this.coeff[i];
}
public boolean setCoef(int pos, int num)
{
if (pos <= 4 || pos >= 0 )
{
coeff[pos] = num;
return true;
}
else
return false;
}
public String toString()
{
return coeff[4] + "X^4 + " +
coeff[3] + "X^3 + " +
coeff[2] + "X^2 + " +
coeff[1] + "X + " + coeff[0];
}
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;
}
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]));
}
public Polynomial derive()
{
return (new Polynomial(coeff[4]*4,coeff[3]*3,coeff[2]*2,coeff[1],0));
}
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];
}
public int numberOfTerms()
{
int n = 0;
if (coeff[4] != 0)
n +=1;
if (coeff[3] != 0)
n +=1;
if (coeff[2] != 0)
n +=1;
if (coeff[1] != 0)
n +=1;
if (coeff[0] != 0)
n +=1;
return n;
}
}
|
|
|
|
|
mastdesi wrote:
poly[6] = new Polynomial(poly[1]);
Possible better solution would be to add another method to Polynomial :
public Polynomial multiply(int multiple) {
return new Polynomial(this.getCoeff(0) * multiple,
this.getCoeff(1) * multiple,
this.getCoeff(2) * multiple,
this.getCoeff(3) * multiple,
this.getCoeff(4) * multiple,
this.getCoeff(5) * multiple);
}
then you can use:
poly[6] = poly[1].multiply(3);
Also the print out at the end can be greatly simplified:
for (int p = 0;
p < 8;
p++) {
System.out.println("Polynomial " + p + " : " + poly[p] +
" has " + poly[p].numberOfTerms() +
" terms and evaluates to " + poly[p].evaluate(x) +
" for x = " + x);
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
|
|
|
|
|
i though of adding the multiply method to the polynomial class but the assignment doesnt say to put it there. Is there another way to do it? It might be a mistake from the teachers end, don't know.
any suggestions on the other questions i had.
thank you very much for your help. Today is the last day to submit this assignment.
|
|
|
|
|
Hi,
i want to calculate the Business Hours of the days. i know the start date and the hours need to add to the business hours.
Here my requirement is that i want to add pre defined hours to business working hours of current date.
below are input i know
1) i know the startdate means that current data is the start date.
2) i know the hours which needs to add to the business hours
3) we need to exclude the weekends and holidays as well.
Above mentioned inputs i know so how can we achieve this with java.
please post solution if anybody know.
thanks in advance.
REGARDS,
Teja
|
|
|
|
|
<sing>homework homework we love homework!
show us what you've got fella!!
regards Torsten
I never finish anyth...
|
|
|
|
|
Member 4231700 wrote: how can we achieve this with java.
The same as with any language: first figure out the algorithm needed to calculate your output from the different inputs, then convert that to code, compile and test ...
Here[^] is a Java class that you may find useful.
|
|
|
|
|
You are so going to struggle in this class.
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
|
|
|
|
|
|
Very droll Sir, very droll.
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
|
|
|
|
|
Member 4231700 wrote: i know the start date and the hours need to add to the business hours.
I can only presume that you are using a fixed number of hours in a day. So algorithmically you want the following
days = today - start
hours = days * 8;
To compute the number of days taking holidays and weekends into account means you must have a 'calendar' for the holidays. That is something that you create that specifies a list of dates which represent holidays. You can get weekend days from the DateTime class.
To calculate the 'days' the algorithm is as follows.
1. workingDay = Start Date
2. is workingDay < current day, if no then stop
3. is workingDay is not holiday and is not weekend day then add 8 hours
4. Increment workingDay.
5. Go to 2.
Member 4231700 wrote: so how can we achieve this with java.
1. Design the class(es) you need from the above description adding appropriate input/output as well.
2. Code the design from 1.
3. Unit test the code from 2.
|
|
|
|
|
jschell wrote: 5. Go to 2.
Go to? You used a 'king go to! Back of the class and write out 100 times "Using GO TO is neither big nor clever and I will not do it again."
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
|
|
|
|
|
I also used the English language.
Perhaps you were confusing it with a programming language.
|
|
|
|
|
that was probably a homage to the old days when we all played with our C64's.
regards Torsten
I never finish anyth...
|
|
|
|
|
How do I add a javascript to an adobe livecycle form that will give me an enlarrged pop up image as I hover the mouse over an image.
|
|
|
|
|
Wrong forum, ask in JavaScript next-door.
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
|
|
|
|
|
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
public class Polynomial
{
private int[] coeff = new int[5];
public Polynomial()
{
coeff = null;
}
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;
}
public Polynomial(Polynomial p)
{
coeff = p.coeff;
}
public int getCoeff(int i)
{
return this.coeff[i];
}
public boolean setCoef(int pos, int num)
{
if (pos <= 4 || pos >= 0 )
{
coeff[pos] = num;
return true;
}
else
return false;
}
public String toString()
{
return coeff[4]+"X4"+" + "+coeff[3]+"X3"+" + "+coeff[2]+"X2"+" + "+coeff[1]+"X"+" + "+coeff[0];
}
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;
}
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]));
}
public Polynomial derive()
{
return (new Polynomial(coeff[4]*4,coeff[3]*3,coeff[2]*2,coeff[1],0));
}
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];
}
}
|
|
|
|
|
This forum is here to help with technical problems, not to provide a free program verification service. If your code does not work in some way then please explain where and why and people will try to help you.
|
|
|
|
|
The copy constructor should do a 'deep' copy:
public Polynomial(Polynomial p)
{
coeff = (int[])p.coeff.clone();
}
The toString method could be improved:
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:
public boolean equals(Object obj) {
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
final Polynomial other = (Polynomial)obj;
return this.coeff.equals(other.coeff);
}
Sums are hard, your evaluate method can be easily improved:
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
|
|
|
|
|