Ads

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.

4. Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.

5. Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list. Provide necessary exception handling in both the implementations.

6. Write a Java program to read a file that contains DNA sequences of arbitrary length one per line (note that each DNA sequence is just a String). Your program should sort the sequences in descending order with respect to the number of 'TATA' subsequences present. Finally write the sequences in sorted order into another file.

7. Develop a simple paint-like program that can draw basic graphical primitives in different dimensions and colors. Use appropriate menu and buttons.

8. Develop a scientific calculator using even-driven programming paradigm of Java.

9. Develop a template for linked-list class along with its methods in Java.

10. Design a thread-safe implementation of Queue class. Write a multi-threaded producer-consumer application that uses this Queue class.

11. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers below 100,000 and writes them into a pipe. Design another thread that generates fibonacci numbers and writes them to another pipe. The main thread should read both the pipes to identify numbers common to both.

12. Develop a multi-threaded GUI application of your choice.

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.

4. Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.

5. Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list. Provide necessary exception handling in both the implementations.

6. Write a Java program to read a file that contains DNA sequences of arbitrary length one per line (note that each DNA sequence is just a String). Your program should sort the sequences in descending order with respect to the number of 'TATA' subsequences present. Finally write the sequences in sorted order into another file.

7. Develop a simple paint-like program that can draw basic graphical primitives in different dimensions and colors. Use appropriate menu and buttons.

8. Develop a scientific calculator using even-driven programming paradigm of Java.

9. Develop a template for linked-list class along with its methods in Java.

10. Design a thread-safe implementation of Queue class. Write a multi-threaded producer-consumer application that uses this Queue class.

11. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers below 100,000 and writes them into a pipe. Design another thread that generates fibonacci numbers and writes them to another pipe. The main thread should read both the pipes to identify numbers common to both.

12. Develop a multi-threaded GUI application of your choice.

Ads

View Answers

July 12, 2010 at 4:41 PM

Hi Friend,

1)StackExample

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());

}

}

}

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));

}

}

1)StackExample

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());

}

}

}

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));

}

}

July 12, 2010 at 5:01 PM

continue..

Please visit the following links:

http://www.roseindia.net/java/thread/InterthreadCommunication.shtml

http://www.roseindia.net/java/thread/CreationOfMultithreads.shtml

http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml

Hope that it will be helpful for you.

Thanks

Please visit the following links:

http://www.roseindia.net/java/thread/InterthreadCommunication.shtml

http://www.roseindia.net/java/thread/CreationOfMultithreads.shtml

http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml

Hope that it will be helpful for you.

Thanks

Ads

Related Tutorials/Questions & Answers: