NPTEL » Programming In Java Week 3 : Programming Assignment 2 Aug 2022

 

Week 3 : Programming Assignment 2

Due on 2022-08-18, 23:59 IST

Define a class Point with two fields x and y each of type double. Also, define a method distance(Point p1, Point p2) to calculate the distance between points p1 and p2 and return the value in double.

Complete the code segment given below. Use Math.sqrt( ) to calculate the square root.

import java.util.Scanner;


public class Circle extends Point{


public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

Point p1=new Point();

p1.x=sc.nextDouble();

p1.y=sc.nextDouble();

Point p2=new Point();

p2.x=sc.nextDouble();

p2.y=sc.nextDouble();

Circle c1=new Circle();

c1.distance(p1,p2);


  }


}


class Point{

  double x;

  double y;


public static void distance(Point p1,Point p2)

{

      double d;

  d=Math.sqrt((p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y));

  System.out.print(d);

    }

}



No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...