Java programmes

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 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 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
Advertisements
programmes - Java Beginners
://www.roseindia.net/java/beginners/MatrixMultiply.shtml http://www.roseindia.net/java/beginners/MatrixSum.shtml http://www.roseindia.net/java/java-conversion/Dividing-of-two
programmes - Java Beginners
data science graduate programmes
data science graduate programmes  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: data science graduate programmes Try to provide me good examples or tutorials links
AWT programmes - Swing AWT
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
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 RoseIndia.net You can start learning java
iPhone Application Development
for developing programmes for Mac OS X. The two major tools used for developing...++, Fortran, Objective-C, Objective-C++, Java, AppleScript, Python and Ruby source code..., and Java. The third parties have added support for GNU Pascal, Free Pascal
Core Java Online Training
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... and developing programmes has become trendy jobs. To be a part of this contemporary
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
only be allowed to force the small programmes known as Java Applets to run...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
Classroom Training: Various programmes dedicated to attaining specialisation in Java...Java Training Institute - Creating Ace Programmers The Information Technology... aspects of the aspirants. Java, a high-level software producing computer language
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
JBBC ,MYSQL ND JAVA
saved in a mysql table... plz if u've any such programmes kindly help me
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
JSF Training
originated by Sun Microsystem for creating rich user interfaces for Java... to all the novice programmers who have basic knowledge of Core Java, Servlet and JSP... of RoseIndia. If you try to apply the codes for developing the programmes, we claim
The Best We Offer
our most visited website for Java professionals: http://www.roseindia.net. ADS..._TO_REPLACE_2 We offer quality customised corporate training programmes..., we do conduct short term development programmes at our own business premises
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
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
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language

Ads