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



Home Answers Viewqa Java-Beginners Java programmes
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


srimathi
Java programmes
2 Answer(s)      4 years and 7 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.

Advertisement
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
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA 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
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
java  diff bt core java and java
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
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   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
Advertisements
 

 

 

DMCA.com