Monday, February 24, 2020

WEEK 4 ASSIGNMENT

QUESTION 1:


import java.io.*;
import java.util.*;
import static java.lang.System.*;

QUESTION 2:


// Create an object of Calendar class. 
java.util.Calendar current ;

// Use getInstance() method to initialize the Calendar object.
current = java.util.Calendar.getInstance();

// Initialize the int variable year with the current year
year = current.get(current.YEAR);

QUESTION 3:


interface ExtraLarge{
String extra = "This is extra-large";
void display();
}

class Large {
    public void Print() {
        System.out.println("This is large");
    }
}

class Medium extends Large {
    public void Print() {
      super.Print();  
        System.out.println("This is medium");
    }
}
class Small extends Medium {
    public void Print() {
        super.Print();  
        System.out.println("This is small");
    }
  }


class Question43 implements ExtraLarge{
    public static void main(String[] args) {
        Small s = new Small();
        s.Print();
  Question43 q = new Question43();
  q.display();
    }
  public void display(){
    System.out.println(extra);
  }
}


QUESTION 4:


// Call show() of First interface.
First.super.show();
// Call show() of Second interface.
Second.super.show();

QUESTION 5:


// Interface ShapeX is created
interface ShapeX {
 public String base = "This is Shape1";
 public void display1();
}

// Interface ShapeY is created which extends ShapeX
interface ShapeY extends ShapeX {
 public String base = "This is Shape2";
 public void display2();
}

// Class ShapeG is created which implements ShapeY
class ShapeG implements ShapeY {
 public String base = "This is Shape3";
 //Overriding method in ShapeX interface
 public void display1() {
  System.out.println("Circle: " + ShapeX.base);
 }
 // Override method in ShapeY interface
  public void display2(){
  System.out.println("Circle: " + ShapeY.base);}
}

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


Tuesday, February 11, 2020

PROGRAMMING IN C++ WEEK 3

HELLO!! FRIENDS HERE I HAVE PASTED ONLY THE SOLUTION AND NOT THE COMPLETE PROGRAM SO PASTE IT CAREFULLY IN YOUR SOLUTION.

QUESTION 1:

mutable int bill;                  // LINE-1

public:
    Customer(int _cust_id, string _name, int _bill)
        : cust_id(_cust_id), name(_name), bill(_bill) {}

    void changeBill(int s)const {    // LINE-2

        bill = s;
    }

    void display()const {            // LINE-3 

QUESTION 2:

public:
Point(int _x, int _y) : x(_x), y(_y){} 

// Copy constructor 
Point( const Point& p2 ) : x( p2.x*10 ), y( p2.y*10 ){} 

QUESTION 3:

class Point {
    mutable int x;    // LINE-1

    mutable int y;    // LINE-2
public:
    Point(int _x, int _y) : x(_x), y(_y){}

    void changePoint(int _x, int _y)const {    // LINE-3

        x = _x;
        y = _y;
    }

    void showPoint()const {    // LINE-4

QUESTION 4:

// LINE-1: define parametrized constructor 
Rectangle::Rectangle(int _h, int _w)
{
  hp=&_h;
  wp=&_w;
}


// LINE-2: define destructor
Rectangle::~Rectangle()
{
  
}

// LINE-3 define function area()
int Rectangle::area()
{
  int a;
  a=(*hp)*(*wp);
  return a;
}

Sunday, February 2, 2020

PROGRAMMING IN JAVA WEEK 1 ASSIGNMENT SOLUTION

Here I have pasted only the answer and not the complete program so please paste the stuff carefully, I have tried to copy the whole program but it is not selecting the whole program at once.

QUESTION 1 :

//Calculate the perimeter 
perimeter=2*Math.PI*radius;

//Calculate the area
area=Math.PI*radius*radius;

if(area>0&&perimeter>0)
        {
          System.out.println(perimeter);
          System.out.print(area);
        }

else
        {
          System.out.print("please enter non zero positive number");
        }

QUESTION 2:

//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.

if(x>y&&x>z)
          result=x;

else if(y>x&&y>z)
          result=y;
          
        else 
          result=z;
          
        System.out.print(result);

QUESTION 3 :

//Use for or while loop do the operation

for(int i=0; i<n*2; i=i+2)
        {
          if(i%3==0)
            sum=sum+i;
        }

System.out.print(sum);

QUESTION 4:

//Use while loop check the number is Armstrong or not.

int i=n;
int count=0; 
while(i>0)
        {
          i=i/10;
          count++;
        }
i=n;
int rem;
int sum=0;
while(i>0)
        {
          rem=i%10;
          i=i/10;
          int a=rem;
          for(int j=0; j<count-1; j++)
            rem=rem*a;
          sum=sum+rem;
        }
          
//store the output(1 or 0) in result variable.
if(sum==n)
          result=1;
else
          result=0;

System.out.print(result);

QUESTION 5:

 //Initialize maximum element as first element of the array.
   //Traverse array elements to get the current max.

int mm=arr[0];
int sum=0;
for(i=0; i<arr.length; i++)
    {
      sum=sum+arr[i];
      if(arr[i]>mm)
        mm=arr[i];
    }
   //Store the highest mark in the variable result.
result=mm;
   //Store average mark in avgMarks.
mark_avg=sum/arr.length;

System.out.println(result);
System.out.print(mark_avg);