This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can someone shed some light on this program

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell what this program accomplishes, i am somewhat confused!

**
* Title: Hemal Mehta

* Description:

* Copyright: Copyright (c)

* Company:

* @author
* @version 1.0
*/
package Proj1;
public class complex
{
private double real, imaginary;
private complex c1_1, c2_2;
private complex(double r, double i)
{
real=r;
imaginary=i;
}
protected complex(complex c1, complex c2)
{
c1_1=c1;
c2_2=c2;
}
protected complex add1(complex c1, complex c2)
{
return new complex(c1,c2);
}
public complex add(complex c)
{
return new complex(c.real+c.imaginary,c.real+c.imaginary);
}
public static void main(String[] args)
{
complex c1=new complex(1.0,2);
complex c2=new complex(3,4);
complex c3=c1.add(c2);
complex c10=c2.add1(c1,c2);
complex c8=new complex(-1,-2);
complex c9=new complex(1,2);
complex c4=new complex(c1,c2);
complex c5=new complex(c8,c9);
}
}
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't really think this is a program. its a package but then again it has a main method
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your code is about complex numbers whose general syntax
is --------x+iy-----------
where x is its real part & y is its imaginary part.
and you want to perform some mathematical operation on them like
addition , Subtraction , multiplication , division , etc.
I make some modification to your code (commented some thing from that & adding some thing from my side)as i written addition& subtraction operation , you can write other operations also.
code
------------------------------------
<pre>
/**
* Title: Govinda

* Description:

* Copyright: Copyright (c)

* Company:

* @author
* @version 1.0
*/
package Proj1;
public class complex
{
private double real, imaginary;
private complex c1_1, c2_2;
public complex(double r, double i)
{
real=r;
imaginary=i;
}
/*public complex(complex c1, complex c2)
{
c1_1=c1;
c2_2=c2;
}*/ // i don't understand the purpose of this constructor.
public complex add(complex c)
{
return new complex(c.real+this.real,c.imaginary+this.imaginary);
}
public complex subtract (complex c)
{
return new complex(this.real-c.real ,this.imaginary-c.imaginary);
}
public String toString() {
return "\nThe Real part of Complex Number is "+ real +"\n"+
"The Imaginary part of Complex Number is "+ imaginary ; }
public static void main(String[] args)
{
complex c1=new complex(1.0,2);
System.out.println("Complex number c1 is"+c1);
complex c2=new complex(3,4);
System.out.println("Complex number c2 is"+c2);
complex c3=c1.add(c2);
System.out.println("The addition of c1 & c2 produced "+c3);
complex c8=new complex(-1,-2);
System.out.println("Complex number c8 is"+c8);
complex c9=new complex(1,2);
System.out.println("Complex number c9 is"+c9);
System.out.println("The subtraction of c8 & c9 produced "+c8.subtract(c9));
/*complex c4=new complex(c1,c2);
complex c5=new complex(c8,c9);
by this code if you want to add two complex numbers and return new one then write an another method to do so */

}
}
</pre>
when trying to run this code place in its appropriate package ,
give proper command line with package name and see the result.
one more thing your classpath should pointing to that package Proj1.
ooooop's sheeeeeeeeeeeee silence

Originally posted by Hemal Mehta:
Can anyone tell what this program accomplishes, i am somewhat confused!

**
* Title: Hemal Mehta

* Description:

* Copyright: Copyright (c)

* Company:

* @author
* @version 1.0
*/
package Proj1;
public class complex
{
private double real, imaginary;
private complex c1_1, c2_2;
private complex(double r, double i)
{
real=r;
imaginary=i;
}
protected complex(complex c1, complex c2)
{
c1_1=c1;
c2_2=c2;
}
protected complex add1(complex c1, complex c2)
{
return new complex(c1,c2);
}
public complex add(complex c)
{
return new complex(c.real+c.imaginary,c.real+c.imaginary);
}
public static void main(String[] args)
{
complex c1=new complex(1.0,2);
complex c2=new complex(3,4);
complex c3=c1.add(c2);
complex c10=c2.add1(c1,c2);
complex c8=new complex(-1,-2);
complex c9=new complex(1,2);
complex c4=new complex(c1,c2);
complex c5=new complex(c8,c9);
}
}


 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hemal,
The program is just one way of creating objects.
Explaination goes like this
package Proj1;
public class complex{
private double real, imaginary;
private complex c1_1, c2_2;
//Constructor
private complex(double r, double i){
real=r;
imaginary=i;
System.out.println("in constr real=" + real + " img=" + imaginary );
}
//Constructor
protected complex(complex c1, complex c2){
/*Here real, imaginary are not set for the object hence when you create object with this constructor,you can't get values real and imaginary variables.Still if you want the data then u should refer through c1_1 and c2_2 object reference. */
c1_1=c1;
c2_2=c2;
}
//method
protected complex add1(complex c1, complex c2){
return new complex(c1,c2);
}
//method
public complex add(complex c){
System.out.println("c2 values real=" + c.real+" img=" + c.imaginary);
return new complex(c.real+c.imaginary,c.real+c.imaginary);
}
public static void main(String[] args){

complex c1=new complex(1.0,2);

complex c2=new complex(3,4);
complex c3=c1.add(c2);

complex c10=c2.add1(c1,c2);

complex c8=new complex(-1,-2);
complex c9=new complex(1,2);
complex c4=new complex(c1,c2);
complex c5=new complex(c8,c9);
}
}

Note: The Hemal's original program does't contain any result for output hence the program after running becomes mum.

HTH
Prasad

------------------

[This message has been edited by Prasad Ballari (edited November 26, 2000).]
[This message has been edited by Prasad Ballari (edited November 26, 2000).]
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic