|
Please use the <pre> tags so the code is readable.
|
|
|
|
|
PLEASE!
...use Eclipse [^]or Netbeans[^] to code - both are FREE. Both would show you your problems right away while coding - you've got more than one problem here.
So please use it!
regards Torsten
I never finish anyth...
|
|
|
|
|
Hai, i have another probleam with my coding. The probleam is my coding have an error cannot find symbol. Here i attach my coding and i also highlight the line which cause me an error
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButangWarna extends Frame implements ActionListener {
JButton Bmerah, Bhijau;
public static void main(String arg[])
{
ButangWarna f = new ButangWarna("Background Colour"); /* cannot find symbol*/
f.addWindowListener(new WindowEventHandler());
f.setSize(400,200);
f.setVisible(true);
}
public void BiodataPelajar(String str)
{
Super(str);
setLayout(new FlowLayout());
Bmerah = new JButton("RED");
Bhijau = new JButton("Green");
add(Bmerah);
add(Bhijau);
Bmerah.addActionListener(this);
Bhijau.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object pilihan = e.getSource();
Color warna= getBackground();
if (pilihan ==Bmerah)
{
warna=Color.red;
}
else
if(pilihan==Bhijau)
{
warna=Color.green;
}
setBackground(warna);
repaint();
}
}
class WindowEventHandler extends WindowAdapter
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}
|
|
|
|
|
What is the exact text of the error message?
|
|
|
|
|
As far as I can see, ButangWarna does not have a constructor that accepts a String as a parameter.
|
|
|
|
|
The class doesn't have a constructor which takes String argument.
You might need to add a constructor like -
ButangWarna(String str)
{
}
Also, in method BiodataPelajar the Super call is invalid.
Two things to note.
1) They syntax is super();
2) There should be a constructor in the parent class which takes the same arguments.
public void BiodataPelajar(String str)
{
Super(str);
..
}
|
|
|
|
|
ankitjc wrote: There should be a constructor in the parent class which takes the same arguments.
Not true! If we have a derived class that has members not in the superclass (and that is the whole reason for having a derived class), then a constructor for the derived class can include parameters not passed to the superclass constructor. Look at any simple example in a book introducing derived classes.
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Take an example. There are two classes A and B.
public class A {
public A() {
}
}
and
public class B extends A {
static String str;
public B() {
super(str);
}
}
So what i wanted to say is, Unless a constructor exists in parent class(with args), you cant make a super call from derived class.
In the above example, super(str) in constructor of B wont compile because there isn't any constructor of class A which takes argument String.
|
|
|
|
|
No! I mean something like this
public class B extends A {
String str;
public B(String astr) {
super();
str = astr;
}
}
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I need to create project for video recording using JMF through Applet. But the client do not want to install JMF package on his machine. Please let me know how I can integrate entire JMF package including its dll in my project.So, that client do not need to install JMF.
|
|
|
|
|
how about using something else? The JMF is not wanted, so you should check for a alternative.
What is the client app about to do?
regards Torsten
I never finish anyth...
|
|
|
|
|
Thanks for replying. I just need to record video using a webcam through Applet. I cannot find it doing without JMF package. Can I record video without JMF package?Is there any other way?Please help me out with this issue.
Thanks and regards.
|
|
|
|
|
Alternative like Jffmpeg ....
|
|
|
|
|
sorry know how to using sprite in j2me????
please help me... thank
|
|
|
|
|
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
|
|
|
|