Question

Long Question Q1: 25 points (1O points for part a, 15 points for part b). riate JavaSeript code to deline a Point class Repre

0 0
Add a comment Improve this question Transcribed image text
Answer #1

prog.html:

<html>
<script>

class Point {
constructor(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
}

static distanceTo(a, b) {
    const dx = Math.pow((a.x - b.x),2);
    const dy = Math.pow((a.y - b.y),2);
    const dz = Math.pow((a.z - b.z),2);

    return Math.pow((dx+dy+dz),1/2);
}
static clone(a)
   {
   const p = new Point(a.x,a.y,a.z);
   return    p;
   }
}

const p1 = new Point(5, 5, 5);
const p2 = new Point(10, 10, 10);

console.log(Point.distanceTo(p1,p2));
console.log(Point.clone(p1));
</script>
</html>

Output:

R Elements Console Sources Network Performance Memory Application Security Audits Adblock Plus Itop Filter Default levels 8.6

program.html:

<html>
<script>
var a = [1,2,3,4];
var ind=2;
function hasNext(ind)
{
if(ind ==a.length-1)
return false;
else
return true;
}
function getNext(ind)
{
if(ind == a.length-1)
return null;
else
return a[ind+1];
}
console.log("The next element of "+a[ind]+" is "+getNext(ind));
console.log("The elements has next element: "+hasNext(ind));
</script>
</html>


Output:

Elements Console Sources Network Performance Memory Application Security Audits Adblock Plus OFilter Default levels ▼ The nex

Add a comment
Know the answer?
Add Answer to:
Long Question Q1: 25 points (1O points for part a, 15 points for part b). riate JavaSeript code t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be in Java. Show proper reasoning with step by step process. Comment on the code...

    Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for ...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

  • INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the...

    INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...

  • Python 3.5 Code Part A: 10 points A tick is a short line that is used...

    Python 3.5 Code Part A: 10 points A tick is a short line that is used to mark off units of distance along a line. Write a function named drawTick() that uses a turtle parameter to draw a single tick of specified length perpendicular to the initial orientation of the turtle. The function drawTick() takes two parameters: 1. a turtle, t, that is used to draw 2. an integer, tickLen, that is the length of the tick When drawTick() is...

  • \\ this is the code i need help to get this part working the rest works...

    \\ this is the code i need help to get this part working the rest works but this and im not sure what is missing or how to make it work. this is what they asking for to do and there is two errors the ones shown in the pictures this is all the information I have from zybooks\\ Q3. (54 Points) Complete a public class to represent a Movie as described below. (a-e 4 pts each) (f-h 8 pts...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • mathlab please copy and paste the code and output Q1. (50 points) Consider the following mathematical...

    mathlab please copy and paste the code and output Q1. (50 points) Consider the following mathematical sequence for any mumber fathe sequence, the first number is 1 = 0. The remaining terms are computed via the following method. The second number of the sequence is given by 1 /2 f iseve Ty - 3x + 1 if, is add The third number of the sequence is given by 1 /2 fils even 133ry + 1 ifr, is odd Thus, the...

  • Python: Arrays and Lists (do code on repl.it) Part C (4 points) - more advanced lists...

    Python: Arrays and Lists (do code on repl.it) Part C (4 points) - more advanced lists You will need a Python repl to solve part C. In Python, define a function named secondHighest which accepts a list of numbers, and returns the second highest number from the list. If the highest value occurs more than once, then it is also the second highest (see example). Assume the input list will always have length at least two (so there is always...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT