Share on Google+Share on Google+

Java programmes
2 Answer(s)      6 years and 10 months ago
Posted in : Java Beginners
1. Develop a Java package with simple Stack and Queue classes. Use JavaDoc
comments for documentation.
2. Design a class for Complex numbers in Java. In addition to methods for basic
operations on complex numbers, provide a method to return the number of active
objects created.
3. Design a Date class similar to the one provided in the java.util package.


View Answers

June 7, 2010 at 3:41 PM

Hi Friend,

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

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

public static String addition(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a+num2.a;
int b1= num1.b+num2.b;
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";

public static String substraction(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a-num2.a;
int b1= num1.b-num2.b;
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";

public static String multiplication(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a*num2.a;
int b1= num1.b*num2.b;
int vi1 = num1.a * num2.b;
int vi2 = num2.a * num1.b;
int vi;
return a1-b1+""+vi+"i";
} else {
return a1-b1+"+"+vi+"i";

public static void main(String args[]){
ComplexNumber com1 = new ComplexNumber(-2,-3);
ComplexNumber com2 = new ComplexNumber(-4,-5);
System.out.println("Addition of both Complex Numbers are :" +ComplexNumber.addition(com1,com2));
System.out.println("Substraction of both Complex Numbers are :" +ComplexNumber.substraction(com1,com2));
System.out.println("Multiplication of both Complex Numbers are :" +ComplexNumber.multiplication(com1,com2));

June 7, 2010 at 4:50 PM


1) class Stack{
protected int st[];
protected int index;

public Stack(int capacity){
st = new int[capacity];
index = -1;
public boolean isEmpty(){
return index == -1;
public void push(int i){
if(index+1 < st.length)
st[++index] = i;
public int pop(){
return 0;
return st[index--];
public int peek(){
if (index == -1)
return 0;
return st[index];
class StackExample{
public static void main(String[] args){
Stack s = new Stack(10);
System.out.println("Adding values in stack using push() method... ");
for(int i=1;i<=5;i++){
System.out.println("Add : " + i);
System.out.println("Top element on stack: "+s.peek());
System.out.println("Removing single value from stack using pop() method... ");
System.out.println("Remove: " + s.pop());
System.out.println("Removing all values from stack using pop() method... ");
System.out.println("Remove : " + s.pop());


Related Tutorials/Questions & Answers:
java programmes - Java Beginners
java programmes  Can you please send me the programmes for IT Deptartment.The subject code is IT2305.Based on new syllabus as per Anna University for 2008 regulation.It contains 12 programmes
Java programmes - Java Beginners
Java programmes  1. Develop a Java package with simple Stack and Queue classes. Use JavaDoc comments for documentation. 2. Design a class for Complex numbers in Java. In addition to methods for basic operations on complex
programmes - Java Beginners
Java GUI - Java Beginners
Java Gui - Java Beginners
char array java
char array java  char array programmes in java All capital letters should be replaced with the next letter
where to start - Java Beginners
where to start  Myself being a java beginner want to know wat... of java.Shall i get a series of questions or programmes for a beginner to work on.   Hi, Thanks for using You can start learning java
Core Java Online Training
for such programmes is provided through Struts, Server Pages (JSPs), Servlet API, etc. by Java...Ascend as an Expert Developer with Core Java Online Training - Online and class room training for students in India A high level programming language, Java
generics - Java Beginners
generics  simple notes on Generics as well some programmes, with its added advantages for java...  Hi Friend, If you want to take an element from the Collection, you have to cast the type of element that is stored
java bean - EJB
java bean  difference between java bean and enterprice java bean  first of all dont compare java bean with enterprise java bean because enterprise java bean is a techonology where we can develope business logic
iPhone Application Development
for developing programmes for Mac OS X. The two major tools used for developing..., Objective-C++, Java, AppleScript, Python and Ruby source code with a variety of programming models, including but not limited to Cocoa, Carbon, and Java
Oracle Corp. introduces updated version of Java
to force the small programmes known as Java Applets to run in the browser, when...To overcome the recent security loop holes of Java, software giant Oracle Corp. has released a new and updated version of Java Programming Language
Java Training Institute - Creating Ace Programmers
Java Training Institute - Creating Ace Programmers The Information Technology... aspects of the aspirants. Java, a high-level software producing computer language... for the products of IT. At Java Training Institute the quality development
java  diff bt core java and java
java  what is java
Java   Whether Java is pure object oriented Language
java  different between java & core java
java  explain technologies are used in java now days and structure java
java   why iterator in java if we for loop
JAVA  how the name came for java language as "JAVA
java  what is java reflection
java  is java open source
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java  write a java program using filenotfoundexception
Java  how to draw class diagrams in java
java   difference between class and interface
java  why multiple inheritance is not possible in java
java  explain object oriented concept in java
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null