The Artima Developer Community
Sponsored Link

Java Answers Forum
Need help in java...im new to it plz help

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Sabi g

Posts: 3
Nickname: sabi77
Registered: May, 2010

Need help in java...im new to it plz help Posted: May 28, 2010 5:18 PM
Reply to this message Reply
Advertisement
I am using NetBeans IDE and i have a question that dont have clue with.

I have to design and implement a programme that displays a simple calculator to perform arithmetic operations with complex numbers: addition, subtraction, multiplication, and division. The program should contain a class Complex and a graphical user interface called ComplexGUI.

The question is as follows: Write a graphical user interface called ComplexGUI. The user should enter two complex numbers one after another. The programme should be able to perform the operations with complex numbers represented by objects of Complex class. The GUI should have the following behaviour:
1) Labels "Enter real and imaginary parts of(first or second) complex number separated by comma";

2) Text fields to enter reala and imaginary parts of the first and second numbers;

3) A button which is selected to add two complex numbers;

4) A button which selected to subtract two complex numbers;

5) A button which is selected to multiply two complex numbers;

6) A button which is selected to divide two complex numbers;

7) Label "Answer:"to display the result;
The class should include a main method that prepares a frame in which the panel is displayed.

I have attempted to do the class Compex and i have come up with the following code. Please check if i have done it right or not and correct any errors and help me with the ComplexGUI. Thank you

import java.util.Random;

public class Complex
{
private double real;
private double imag;

public Complex (double real, double imag)
{
this.real = real;
this.imag = imag;
}

public Complex()
{
Random Wheel = new Random();
for(int i=0; i<100; i++)
{
double d = Wheel.nextDouble() * 10.0d;
}
}

public double getReal()
{
return real;
}

public double getImaginary()
{
return imag;
}

public Complex add (Complex z)
{
return new Complex(real+z.real, imag+z.imag);
}

public Complex subtract(Complex z)
{
return new Complex(real-z.real, imag-z.imag);
}

public Complex multiply(Complex z)
{
return new Complex(real*z.real-imag*z.imag, imag*z.real+real*z.imag);
}

public Complex divide(Complex z)
{
return new Complex(real/z.real-imag/z.imag, imag/z.real+real/z.imag);
}

public java.lang.String toString()
{
return this.real + "+" + this.imag + "i";
}

}

Topic: Need help with this one more question...Im new to programming and learning Previous Topic   Next Topic Topic: Anonymous class

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use