Saturday, February 15, 2020

WEEK 3 ASSIGNMENT SOLUTION

HEY! GUYS HERE IS THE CODE OF ALL THE QUESTIONS:

QUESTION 1:

if (n<=1) 
            return (1-n); 
        return fib(n - 1) + fib(n - 2); 

QUESTION 2:

class Point{
  double x,y;
 
  public double distance(Point p1, Point p2)
                {
                  
                  double root=(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
                  root=Math.sqrt(root);
                  System.out.print(root);
                  return root;
                }
}

QUESTION 3:


//Create a derived class constructor which can call the one parametrized constructor of the base class
double height;
Test1(double l, double h){
  super(l);
  this.length=l;
  this.height=h;
}

//Create a derived class constructor which can call the two parametrized constructor of the base class
Test1(double l, double b, double h){
  super(l,b);
  this.length=l;
  this.breadth=b;
  this.height=h;
}
  
  

//Override the method calculate() in the derived class to find the volume of a shape instead of finding the area of a shape

double calculate(){
  
  return length*breadth*height;}

QUESTION 4:


QuestionScope a= new QuestionScope();
System.out.println(a.sum(n1,n2));
System.out.print(QuestionScope.multiply(n1,n2));

QUESTION 5:


static void swap(Question obj)
        {
          int temp;
          temp=obj.e1;
          obj.e1=obj.e2;
          obj.e2=temp;
        }


3 comments:

  1. Your Affiliate Profit Machine is waiting -

    Plus, making profit with it is as easy as 1, 2, 3!

    Here's how it all works...

    STEP 1. Input into the system what affiliate products the system will promote
    STEP 2. Add PUSH BUTTON traffic (it LITERALLY takes 2 minutes)
    STEP 3. Watch the affiliate system explode your list and sell your affiliate products on it's own!

    Are you ready to make money automatically??

    Get the full details here

    ReplyDelete