Add a main() method to Program 3.4.1 that unit-tests the Body data type. Program 3.4.1 Gravitational body
Question:
Add a main() method to Program 3.4.1 that unit-tests the Body data type.
Transcribed Image Text:
Program 3.4.1 Gravitational body public class Body { py private Vector r; private Vector v; private final double mass; public Body (Vector r0, Vector v0, double m0) { r = r0; v = v0; mass = m0; } public void move (Vector force, double dt) { // Update position and velocity. Vector a = force.scale(1/mass); v = v.plus (a.scale(dt)); r = r.plus (v.scale(dt)); } public Vector forceFrom(Body b) { // Compute force on this body from b. b } public void draw() { force dt G delta dist magnitude Body a this; double G = 6.67e-11; Vector delta = b.r.minus(a.r); double distdelta.magnitude(); double magnitude= (Ga.mass * b.mass) / (dist dist); Vector force = delta.direction ().scale (magnitude); return force; StdDraw.setPenRadius (0.0125); StdDraw.point (r.cartesian (0), r.cartesian (1)); position velocity V mass mass force on this body time increment acceleration this body another body gravitational constant vector from b to a distance from b to a magnitude of force
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (QA)
java public class Body private Vector 1 private Vector v private final double mass public BodyVector ...View the full answer
Answered By
Asd fgh
sadasmdna,smdna,smdna,msdn,masdn,masnd,masnd,m asd.as,dmas,dma.,sd as.dmas.,dma.,s ma.,sdm.,as mda.,smd.,asmd.,asmd.,asmd.,asm
5.00+
1+ Reviews
15+ Question Solved
Related Book For
Introduction To Programming In Java An Interdisciplinary Approach
ISBN: 9780672337840
2nd Edition
Authors: Robert Sedgewick, Kevin Wayne
Question Posted:
Students also viewed these Algorithm Design questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Define the contextual-equivalence relation ` M =ctx M0 : for pairs of PCF terms M, M0 , PCF types , and PCF type environments . [3 marks] (ii) For PCF terms M and N with respective typings ` M : and...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
The common stock of Fido Corporation was trading at $45 per share on October 15, 2010. A year later, on October 15, 2011, it was trading at $80 per share. On this date, Fidos board of directors...
-
Many animals, including humans, tend to avoid direct eye contact and even patterns that look like eyes. Some insects, including moths, have evolved eye-spot patterns on their wings to help ward off...
-
A steel tank of wall thickness \(10 \mathrm{~mm}\) contains water at \(90^{\circ} \mathrm{C}\). Calculate the rate of heat loss per \(\mathrm{m}^{2}\) of tank surface area when the atmospheric...
-
The induced emf in an inductor of inductance \(L\) varies with time according to \(\mathscr{E}_{\text {ind }}(t)=-2 C t\), where \(C\) is a positive constant. (a) If there is no current through the...
-
Lee contracts to paint Sallys two-story house for $2,500. Sally realizes that she will not have sufficient money, so she transfers her rights under this agreement to her neighbor Karen, who has a...
-
11. A planet is revolving around the sun in an elliptical orbit. The mass of planet is m, angular momentum of planet about sun is L, and length of semi major axis is a and eccentricity are e. Time...
-
Give an implementation of minus () for Vector solely in terms of the other Vector methods, such as direction() and magnitude().
-
Write a program that takes from the command line three integers between 0 and 255 that represent red, green, and blue values of a color and then creates and shows a 256-by-256 Picture in which each...
-
(a) In Figure 20-36 we see that the electric potential increases by 10.0 V as one moves 4.00 cm in the positive x direction. Use this information to calculate the x component of the electric field....
-
adam likes to skateboard on a street that drops 8 5 . 9 ft over a horizontal distance of 5 0 4 ft . what is the grade of the street?
-
You need to administer ampohotericin B 0.5 mg/kg Iv daily to a patient with histoplasmosis who weight 236 pounds. How many milligrams should you expect to administer each day
-
In review of Walmart's 2023 annual report found at, https://www.annualreports.com/Company/walmart-inc...
-
Suppose that {(t), (t)} is a fundamental set of solutions for y" + Py' + poy = 0. (a) Write $1 M Explain why this matrix is invertible (Hint: Think about Wronskians) (b) Suppose that = c1+ C22 is a...
-
Since f is well-conditioned near x = 0, then the large relative error from (a) must be because our 'algorithm' (i.e., the function f1) is unstable near x = 0. What is the cause of this? (Hint; The...
-
What did Klein do wrong?
-
Prairie Outfitters, Inc., a retailer, accepts paymnent through credit cards. During August, credit card sales amounted to $12,000. The processor charges a 3% fee. Assuming that the credit card...
-
Based on the following query: SELECT CUS_CODE, MAX(LINE_UNITS*LINE_PRICE) FROM CUSTOMER NATURAL JOIN INVOICE NATURAL JOIN LINE WHERE CUS_AREACODE = 615 GROUP BY CUS_CODE; How would you rewrite the...
-
The following data structure and constraints exist for a magazine publishing company. a. The company publishes one regional magazine each in Florida (FL), South Carolina (SC), Georgia (GA), and...
-
Describe the characteristics of predictive analytics. What is the impact of Big Data in predictive analytics?
-
The cumulative percentage of completion is found by dividing the Total Costs Incurred to Date by the Estimated Total Cost of the Project. The percentage-of-completion method may utilize a...
-
Prove that (2x + 3y)(4x 6xy + 9y^) + (2x 3y)(4x + 6xy + 999*) is equivalent to 1 for x not equal 16x to 0.
-
How Does SAS Incorporate the P-O-L-C Framework? First, by way of introduction, share your major concentration and how this course and program fit into your career goals. Next, read SAS: A New No. 1...
Study smarter with the SolutionInn App