Java programmes 2 Answer(s) 3 years 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,
2)ComplexNumber.java: 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 String substraction(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 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; vi=vi1+vi2; if(vi<0){ 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(com1.getComplexValue()); System.out.println(com2.getComplexValue()); 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
continue..
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(){ if(isEmpty()) 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++){ s.push(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... "); while(!s.isEmpty()){ System.out.println("Remove : " + s.pop()); }
} }
Related Pages:
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
char array java
char array java char array programmes in java
All capital letters should be replaced with the next letter
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
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 RoseIndia.net
You can start learning 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
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
making a web application using Web-Logic Server - Struts
making a web application using Web-Logic Server Hello , I am a beginner to the java platform so i am facing some problem in making a web aplication... help me for the same by showing the changes to be made in the programmes
Synchronization probleam - Java Server Faces Questions
Synchronization probleam
Hi friends
My java multithreading... so that it runs normally like any other programmes.
Here is my code..." to solve the probelm and visit to :
http://www.roseindia.net/java/example