Active Objects

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
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!!!ADS_TO_REPLACE_1   hiii To trigger vibration in iPhone, use System Audio Services (AudioToolbox/AudioServices.h
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
ModuleNotFoundError: No module named 'active'
ModuleNotFoundError: No module named 'active'  Hi, My Python... 'active' How to remove the ModuleNotFoundError: No module named 'active'... to install padas library. You can install active python with following command
Version of com.plugback>active dependency
List of Version of com.plugback>active dependency
ModuleNotFoundError: No module named 'Active-Alchemy'
ModuleNotFoundError: No module named 'Active-Alchemy'  Hi, My... named 'Active-Alchemy' How to remove the ModuleNotFoundError: No module named 'Active-Alchemy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'active_directory'
ModuleNotFoundError: No module named 'active_directory'  Hi, My... named 'active_directory' How to remove the ModuleNotFoundError: No module named 'active_directory' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'active-learning'
ModuleNotFoundError: No module named 'active-learning'  Hi, My... named 'active-learning' How to remove the ModuleNotFoundError: No module named 'active-learning' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'active-sample'
ModuleNotFoundError: No module named 'active-sample'  Hi, My... 'active-sample' How to remove the ModuleNotFoundError: No module named 'active-sample' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Active-SQLAlchemy'
ModuleNotFoundError: No module named 'Active-SQLAlchemy'  Hi, My... named 'Active-SQLAlchemy' How to remove the ModuleNotFoundError: No module named 'Active-SQLAlchemy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'active-subspaces'
ModuleNotFoundError: No module named 'active-subspaces'  Hi, My... named 'active-subspaces' How to remove the ModuleNotFoundError: No module named 'active-subspaces' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'active_redis'
ModuleNotFoundError: No module named 'active_redis'  Hi, My Python... 'active_redis' How to remove the ModuleNotFoundError: No module named 'active_redis' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'active-sessions'
ModuleNotFoundError: No module named 'active-sessions'  Hi, My... named 'active-sessions' How to remove the ModuleNotFoundError: No module named 'active-sessions' error? Thanks   Hi, In your python
Maven Dependency active >> 1.0.2-BETA
You should include the dependency code given in this page to add Maven Dependency of com.plugback >> active version1.0.2-BETA in your project
Maven Dependency active >> 1.0.1-BETA
You should include the dependency code given in this page to add Maven Dependency of com.plugback >> active version1.0.1-BETA in your project
Maven Dependency active >> 1.0.3-BETA
You should include the dependency code given in this page to add Maven Dependency of com.plugback >> active version1.0.3-BETA in your project
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
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
ModuleNotFoundError: No module named 'middleware-active-directory'
ModuleNotFoundError: No module named 'middleware-active-directory'  ...: No module named 'middleware-active-directory' How to remove the ModuleNotFoundError: No module named 'middleware-active-directory' error? Thanks
ModuleNotFoundError: No module named 'odoo10-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo10-addon-partner-bank-active' ...: ModuleNotFoundError: No module named 'odoo10-addon-partner-bank-active' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active' ...: ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo12-addon-res-company-active'
ModuleNotFoundError: No module named 'odoo12-addon-res-company-active' ...: ModuleNotFoundError: No module named 'odoo12-addon-res-company-active' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-res-company-active' error
ModuleNotFoundError: No module named 'python-active-com-api'
ModuleNotFoundError: No module named 'python-active-com-api'  Hi...: No module named 'python-active-com-api' How to remove the ModuleNotFoundError: No module named 'python-active-com-api' error? Thanks   Hi
ModuleNotFoundError: No module named 'python-active-com-api'
ModuleNotFoundError: No module named 'python-active-com-api'  Hi...: No module named 'python-active-com-api' How to remove the ModuleNotFoundError: No module named 'python-active-com-api' error? Thanks   Hi
ModuleNotFoundError: No module named 'python-active-directory'
ModuleNotFoundError: No module named 'python-active-directory'  Hi...: No module named 'python-active-directory' How to remove the ModuleNotFoundError: No module named 'python-active-directory' error? Thanks   
ModuleNotFoundError: No module named 'test_active_state_recipes'
ModuleNotFoundError: No module named 'test_active_state_recipes'  Hi...: No module named 'test_active_state_recipes' How to remove the ModuleNotFoundError: No module named 'test_active_state_recipes' error? Thanks  
ModuleNotFoundError: No module named 'active-semi-supervised-clustering'
ModuleNotFoundError: No module named 'active-semi-supervised-clustering' ...: ModuleNotFoundError: No module named 'active-semi-supervised-clustering' How to remove the ModuleNotFoundError: No module named 'active-semi-supervised-clustering'
ModuleNotFoundError: No module named 'ardexa-check-active'
ModuleNotFoundError: No module named 'ardexa-check-active'  Hi, My... named 'ardexa-check-active' How to remove the ModuleNotFoundError: No module named 'ardexa-check-active' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-active-link'
ModuleNotFoundError: No module named 'django-active-link'  Hi, My... named 'django-active-link' How to remove the ModuleNotFoundError: No module named 'django-active-link' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-active-navigation'
ModuleNotFoundError: No module named 'django-active-navigation'  Hi...: No module named 'django-active-navigation' How to remove the ModuleNotFoundError: No module named 'django-active-navigation' error? Thanks  
ModuleNotFoundError: No module named 'django-active-path'
ModuleNotFoundError: No module named 'django-active-path'  Hi, My... named 'django-active-path' How to remove the ModuleNotFoundError: No module named 'django-active-path' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-active-users'
ModuleNotFoundError: No module named 'django-active-users'  Hi, My... named 'django-active-users' How to remove the ModuleNotFoundError: No module named 'django-active-users' error? Thanks   Hi
ModuleNotFoundError: No module named 'kaldi-active-grammar'
ModuleNotFoundError: No module named 'kaldi-active-grammar'  Hi...: No module named 'kaldi-active-grammar' How to remove the ModuleNotFoundError: No module named 'kaldi-active-grammar' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active' ...: ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo13-addon-partner-bank-active'
ModuleNotFoundError: No module named 'odoo13-addon-partner-bank-active' ...: ModuleNotFoundError: No module named 'odoo13-addon-partner-bank-active' How to remove the ModuleNotFoundError: No module named 'odoo13-addon-partner-bank-active'
ModuleNotFoundError: No module named 'python-active-directory'
ModuleNotFoundError: No module named 'python-active-directory'  Hi...: No module named 'python-active-directory' How to remove the ModuleNotFoundError: No module named 'python-active-directory' error? Thanks   
ModuleNotFoundError: No module named 'webapi_active_query_builder'
ModuleNotFoundError: No module named 'webapi_active_query_builder'  ...: No module named 'webapi_active_query_builder' How to remove the ModuleNotFoundError: No module named 'webapi_active_query_builder' error? Thanks
ModuleNotFoundError: No module named 'active-campaign-python'
ModuleNotFoundError: No module named 'active-campaign-python'  Hi...: No module named 'active-campaign-python' How to remove the ModuleNotFoundError: No module named 'active-campaign-python' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-active-login-required'
ModuleNotFoundError: No module named 'django-active-login-required'  ...: No module named 'django-active-login-required' How to remove the ModuleNotFoundError: No module named 'django-active-login-required' error
ModuleNotFoundError: No module named 'django-active-tab'
ModuleNotFoundError: No module named 'django-active-tab'  Hi, My... named 'django-active-tab' How to remove the ModuleNotFoundError: No module named 'django-active-tab' error? Thanks   Hi, In your
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
Maven Repository/Dependency: com.plugback | active
Maven Repository/Dependency of Group ID com.plugback and Artifact ID active. Latest version of com.plugback:active dependencies. # Version Release Date 1 1.0.1-BETA 11
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
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
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' ...: ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' How to remove the ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' ...: ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' How to remove the ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'odoo8-addon-base-ir-filters-active'
ModuleNotFoundError: No module named 'odoo8-addon-base-ir-filters-active' ...: ModuleNotFoundError: No module named 'odoo8-addon-base-ir-filters-active' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-base-ir-filters-active
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' ...: ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' How to remove the ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' ...: ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice' How to remove the ModuleNotFoundError: No module named 'jenkins-job-builder-active-choice'
ModuleNotFoundError: No module named 'odoo11-addon-project-task-type-active'
ModuleNotFoundError: No module named 'odoo11-addon-project-task-type-active...: ModuleNotFoundError: No module named 'odoo11-addon-project-task-type-active' How...-active' error? Thanks   Hi, In your python environment you

Ads