Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Jothiboss
Active Objects
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners


Design a class for complex nos in java in addition to methods for basic operations on complex number. Provide a method to return the number of active objects created

Advertisement
View Answers

July 8, 2010 at 10:25 AM


Hi Friend,

Try the following code:

public class ComplexNumber
{
private int a;
private int b;
public ComplexNumber(){
}

public ComplexNumber(int a, int b){
this.a =a;
this.b=b;
}
public String getComplexValue(){
if(this.b < 0){
return a+""+b+"i";
}
else{
return a+"+"+b+"i";
}
}

public static String addition(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a+num2.a;
int b1= num1.b+num2.b;
if(b1<0){
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";
}
}
public static void main(String args[]){
ComplexNumber com1 = new ComplexNumber(-2,-3);
ComplexNumber com2 = new ComplexNumber(-4,-5);
System.out.println(com1.getComplexValue());
System.out.println(com2.getComplexValue());
System.out.println("Addition of both Complex Numbers are :" +ComplexNumber.addition(com1,com2));
}
}

Thanks


Related Tutorials/Questions & Answers:
Active Objects - Java Beginners
Active Objects  Design a class for complex nos in java in addition to methods for basic operations on complex number. Provide a method to return the number of active objects created  Hi Friend, Try the following code
Active vibration
Active vibration  hello is it possible to active vibration from code ? if yes give me solution!!!   hiii To trigger vibration in iPhone, use System Audio Services (AudioToolbox/AudioServices.h). Call
Advertisements
active window means
active window means  active window means what?   The active window is the term used to describe the window that is currently being used
Count Active Thread in JAVA
Count Active Thread in JAVA In this tutorial, we are using activeCount() method of thread to count the current active threads. Thread activeCount() : Thread class provides you to check the current active thread by providing
Objects
Objects       Objects In this section we are going to illustrate how the real life objects are the key to understand object-oriented technology Objects are the part of our day to day
Login Authentication using existing Active Directory.
Login Authentication using existing Active Directory.  I need jsp... Active Directory. Here no need to create active directory.The JSP code should... or Active directory URL
problem. how to use active mq - JMS
problem. how to use active mq  how to use active mq with jms. right now i am using struts 2.0 to develop small applications and i am using tomacat... and active mq please send me
Logout if its not active for longer period in jsp
Logout if its not active for longer period in jsp  hi all, Please tell me how to log out the application if its not performing any activity for longer period in jsp i tried to use session.setMaxInactiveInterval(arg0); but still
Implicit objects
Implicit objects  What are the implicit objects
Data objects
Data objects   hello,, What are data objects?   hii, Sequences, Views, clusters, Tables, index and cluster are called data objects for a database
Java Objects
Java Objects  What are Data Transfer Objects and where are they used
classes and objects
classes and objects  Define a class named Doctor whose objects are records for a clinicâ??s doctors. Derive this class from the class Person... and Billing, whose objects are records for a clinic. Derive Patient from
Classes and Objects
Classes and Objects       Objects... the main() method.  A class can have more than one instances (objects), let us... techniques. A class defines the properties of  objects and methods used
count objects php
count objects php  How to Count and show objects in PHP
Are objects passed by value or by reference?
Are objects passed by value or by reference?  Are objects passed by value or by reference
What are the benefits of detached objects?
What are the benefits of detached objects?   Hi, What are the benefits of detached objects? Thanks
class with in its own objects?
class with in its own objects?  Is it a good idea to declare a class with in its own objects
Benefits of detached objects in hibernate
Benefits of detached objects in hibernate  What are benefits of detached objects in hibernate?   Detached objects can be passed across... Transfer Objects). You can later on re-attach the detached objects to another
Objects in Java
Objects in Java Whatever we can see in this world all the things are a object. And all the objects are categorized in a special group. That group is termed as a class. All the objects are direct interacted with its class that mean
implicit objects in jsp
implicit objects in jsp  hello, how many implicit objects in jsp???   hello, I am giving implicit object out,config,page,application,request,page context,response,session
Transient and detached objects
Transient and detached objects  Explain the difference between transient (i.e. newly instantiated) and detached objects in hibernate
Get Duplicate Objects from an ArrayList of Objects
Get Duplicate Objects from an ArrayList of Objects  public class Order { private String portId; private String action; private String idType; private String id; private BigDecimal amount; public String getPortId
Flex Objects
: #FFFFCC; } Objects are real entity conforming the template or blueprint defined by its class. The class defines the properties and behavior for its objects... objects of these classes according to the need of your application
Java Objects - Java Beginners
Java Objects  Hi I have the following question, What method in Java is used to destroy your objects. Thanks in advance
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Objects - Java Beginners
Objects  Hello, assist me crack this programming question. Develop a class to represents a human. The head, arms and legs should be properties of the human and should be represented by separate objects. All of your objects
Mapping objects in XML - Spring
Mapping objects in XML   Hello, I´ve read that you can define an object in the configuration XML as follows: tom Ok, but, if I want to set a different value for "name" each time I create
JSP Implicit Objects
JSP Implicit Objects  What are implicit objects in JSP? and provide List them? Thanks in advance   Hi, In the JSP, the web container are created some method that are contain information related to a particular
Objects - Java Beginners
of the human and should be represented by separate objects. All of your objects...) { //Declare and create a Headmain object //and Three ArmsMain objects
Avanced objects - Java Beginners
of the human and should be represented by separate objects. All of your objects should
 

 

 

DMCA.com