Thursday, June 2, 2011

CrazyEngineers Forum - Computer Science & IT Engineering

CrazyEngineers Forum - Computer Science & IT Engineering


Generate a binary tree using database

Posted: 01 Jun 2011 07:23 PM PDT

This question was asked during my last interview ,i was unable to answer this

Ok you have to create a database schema where you have to store a binary tree

and then you have to write 3 queries through which you have to traverse data in

preorder, inorder ,postorder

Solve this Sql Query -Part 2

Posted: 01 Jun 2011 06:55 PM PDT

Continued to my previous query http://www.crazyengineers.com/forum/...sql-query.html

Let us make this query a little bit tricky

Say i want to develop a single query, through which i can extract data of all the employee having 5th highest salary .

Remember it should be single query ,that next time if i want salary of employee having maximum salary among all,it should display it too

Note :-you have to mention which variables in query are required to be modified dynamically every time

Help needed in completing Matlab/Octave project

Posted: 01 Jun 2011 11:35 AM PDT

Hi I am in need of help for completing a matlab or octave project for my class. I have no idea on how to do it or have the slightest clue about them, so if someone can take a look at it and do it I would appreciate it. I am willing to pay for the completed work.

Write a Program for a Singleton Class

Posted: 01 Jun 2011 04:10 AM PDT

Hi All,

I am not sure if you all know about "Singleton" class program in java or not. Well, in brief for those who don't know, it is a class that lets only one object to be created always. The basic approach being used is just making the constructor of the class as "private"
Code:

/* Singleton Program **/
class Singleton{
    private static Singleton singletonObj;

    private Singleton(){
       
    }
    public void printMe(String val){
        System.out.println("Singleton Test val="+val);
    }
   
    public static synchronized Singleton getInstance(){
        if(singletonObj==null){
            singletonObj=new Singleton();
        }
        return singletonObj;
    }
}
/* Singleton class invoking program */
public class SingletonTest {
       
    public static void main(String[] args) throws Exception{
       
        Singleton s1=Singleton.getInstance();
        s1.printMe("1");
        Singleton s2=Singleton.getInstance();
          s2.printMe("2");
   
    }
}

Now here goes my actual question, if I put a constraint to modify the above "Sinlgleton" class in such a way that the constructor access level is not "private" rather as "public" then how will you modify the "Singleton" class program so as to make below program working. It should show proper message like "Object -2 cannot be created" instead of printing output as
Quote:

Singleton Test val=1
Singleton Test val=2
Code:

/* Singleton Program **/
class Singleton{
    private static Singleton singletonObj;

    public Singleton(){
       
    }
    public void printMe(String val){
        System.out.println("Singleton Test val="+val);
    }
   
    public static synchronized Singleton getInstance(){
        if(singletonObj==null){
            singletonObj=new Singleton();
        }
        return singletonObj;
    }
}
/* Singleton class invoking program */
 public class SingletonTest {
       
    public static void main(String[] args) throws Exception{
       
        Singleton s1=new Singleton();
        s1.printMe("1");
        Singleton s2=new Singleton();
        s2.printMe("2");

   
    }
 }

I have already given so much information in it, now just use little of Java knowledge and your brain how to handle this scenario.

No comments:

Post a Comment