FieldLines



Today, Fieldline® is a worldwide hunting gear manufacturer and distributor and although they no longer have their department stores, they still continue in their longtime retail commitment to. Fieldlines.com: The Otherpower discussion board Bad Behavior has blocked 692 access attempts in the last 7 days. Page created in 0.103 seconds with 17 queries.


In this section, we introduce the Java mechanism that enables us to create user-defined data types.We consider a range of examples, from charged particles and complexnumbers to turtle graphics and stock accounts.

Basic elements of a data type.

To illustrate the process,we define in Charge.java a data typefor charged particles.Coulomb’s lawtells us that the electric potential at a point ((x, y)) due to a given charged particle is(V = kq /r), where (q) is the charge value, (r) is the distance from the point((x, y)) to the charge, and (k = 8.99 times 10^9) is the electrostatic constant.
  • API.The application programming interface is the contract with all clients and,therefore, the starting point for any implementation.
  • Class.In Java, you implement a data type in a class.As usual, we put the code for a data type in a file with the same name as the class,followed by the .java extension.
  • Access modifiers.We designate every instance variable and method within a class as either public(this entity is accessible by clients) or private(this entity is not accessible by clients).The final modifier indicates that the value of the variable will notchange once it is initialized—its access is read-only.
  • Instance variables.We declare instance variables to represent the cellpadding='2' cellspacing='0' width='95%'>
  • Spira mirabilis.Spiral.javatakes an integer n and a decay factor as command-line arguments,and instructs the turtle to alternately step and turn until it has wound around itself 10 times. This produces a geometric shape known as alogarithmic spiral,which arise frequently in nature.Three examples are depicted below: the chambers of a nautilus shell,the arms of a spiral galaxy, and the cloud formation in a tropical storm.
    This Wikipedia image is from user Chris 73,
    and is available via the CC by-SA 3.0 license.
    Photo: NASA and ESA
    Photo: NASA
  • Brownian motion.DrunkenTurtle.java plotsthe path followed by a disoriented turtle, who alternates between moving forward and turning in a random direction.This process is known as Brownian motion.DrunkenTurtles.java plotsmany such turtles, all of whom wander around.
FieldLines

Complex numbers.

A complex number is a number of the form x + iy, where x and y are real numbers andFieldLinesi is the square root of −1.The basic operations on complex numbers are to add and multiply them, as follows:
  • Addition:((x_0+iy_0) + (x_1+iy_1) = (x_0+x_1) + i,(y_0+y_1))
  • Multiplication:((x_0 + iy_0) cdot (x_1 + iy_1) = (x_0x_1 - y_0y_1) + i,(y_0x_1 + x_0y_1))
  • Magnitude:(left | x + iy right | = sqrt{x^2 + y^2})
  • Real part:(operatorname{Re}(x + iy) = x)
  • Imaginary part:( operatorname{Im}(x + iy) = y)
Complex.java is an immutable data typethat implements the following API:This data type introduces a few new features.
  • Accessing values of other objects of the same type.The instance methods plus() and times() each need to access values in two objects: the object passed as an argumentand the object used to invoke the method. If we call the method witha.plus(b),we can access the instance variables of ausing the names re and im, as usual.However, to access the instance variables of b,we use the code b.re and b.im.
  • Creating and returning new objects.Observe the manner in which plus()and times() provide return values to clients: they need to return a Complex value, so they each compute the requisite real and imaginary parts, use them to create a new object, and then return a reference to that object.
  • Chaining method calls.Observe the manner in which main()chains two method calls into one compact expressionz.times(z).plus(z0), which correspondsto the mathematical expression z2 + z0.
  • Final instance variables.The two instance variables in Complex arefinal, meaning that their values are set for eachComplex object when it is created and do not changeduring the lifetime of that object.
Fieldline pro seriesHttp://www.fieldlines.com

Mandelbrot set.

The Mandelbrot setis a specific set of complex numberswith many fascinating properties.The algorithm for determining whether or not a complex number (z_0) is in the Mandelbrot set is simple: Consider the sequence of complex numbers (z_0, z_1, z_2, ldots, z_t, ldots,)where (z_{i+1} = z_i^2 + z_0).For example, the following table shows the first few entries in thesequence corresponding to (z_0 = 1 + i):Now, if the sequence ( | z_i |) diverges to infinity, then (z_0)is not in the Mandelbrot set; if the sequence is bounded,then (z_0) is in the Mandelbrot set. For many points, the test is simple; for many other points, the test requires more computation, as indicated by the examples in the following table:To visualize the Mandelbrot set,we define an evenly spaced n-by-n pixel grid within a specified square and draw a black pixel if the corresponding point isin the Mandelbrot set and a white pixel if it is not.

But how do we determine whether a complex number is in the Mandelbrot set?For each complex number, Mandelbrot.javacomputes up to 255 terms in its sequence. If the magnitude ever exceeds 2,then we can conclude that the complex number is not in the set (because it is known that the sequence will surely diverge).Otherwise, we conclude that the complex number is in the set (knowing that our conclusion might be wrong on occasion).

Commercial data processing.

StockAccount.java implements a data type that might be used by a financialinstitution to keep track of customer information.


Exercises

FieldLines
  1. Develop an implementation Rectangle.javaof your Rectangle API fromExercise 3.2.1 that that represents rectangles with the x- and y-coordinatesof their lower-left and upper-right corners. Do not change the API.
  2. Implement a data type Rational.javanumbers that supports addition, subtraction, multiplication,and division.
  3. Write a data type Interval.javathat implements the following API:An interval is defined to be the set of all points on the line greater than or equal to min and less than or equalto max.In particular, an interval with max less thanmin is empty. Write a client that is a filter thattakes a floating-point command-line argument xand prints all of the intervals on standard input(each defined by a pair of double values) that contain x.
  4. Write a data type Point.javathat implements the following API:
  5. Modify the toString() method in Complex.javaso that it complex numbers in the traditional format.For example, it should print the value (3-i) as 3 - i instead of 3.0 + -1.0i, the value 3 as 3 insteadof 3.0 + 0.0i and the value 3i) as 3iinstead of 0.0 + 3.0i.
  6. Write a Complex client RootsOfUnity.javathat takes two double values a and band an integer n from the command line and printsthe nth root of (a + bi).
  7. Implement the following additions to Complex.java:

    Write a test client that exercises all of your methods.

  8. Suppose you want to add a constructor to Complex.javathat takes a double value as its argument and creates aComplex number with that value as the real part (and no imaginary part).You write the following code:But then the statement Complex c = new Complex(1.0); does not compile. Why?

    Solution: Constructors do not have return types, not even void.This code defines method named Complex(), not a constructor.Remove the keyword void.

Creative Exercises

  1. Electric potential visualization.Write a program Potential.javathat creates an array of charged particles from values givenon standard input (each charged particle is specified by its x-coordinate, y-coordinate, and charge value) and produces a visualization of the electric potential in the unit square.To do so, sample points in the unit square. For each sampled point,compute the electric potential at that point (by summing theelectric potentials due to each charged particle) and plot thecorresponding point in a shade of gray proportional to the electric potential.


  2. Quaternions.In 1843, Sir William Hamilton discovered an extension to complexnumbers called quaternions.Quaternions extend the concept of rotation in three dimensions tofour dimensions. They are used in computer graphics, control theory,signal processing, and orbital mechanics, e.g., command for spacecraft attitude control systems. are related to Pauli spin matrices in physics.Create a date type Quaternion.javato represent quaternions.Include operations for adding, multiplying, inverting, conjugating,and taking the norm of quaternions.

    A quaternion can be represented by a 4-tuple of real numbers ((a_0, a_1, a_2, a_3)),which represents (a_0 + a_1 i + a_2 j + a_3 k). The fundamental identity is(i^2 = j^2 = k^2 = ijk = -1).

    • Magnitude:( left | a right | = sqrt{a_0^2 + a_1^2 + a_2^2 + a_3^2} )
    • Conjugate:( a^* = (a_0, -a_1, -a_2, -a_3))
    • Inverse:( a^{-1} = (a_0,/, left | a right |^2, -a_1,/, left | a right |^2, -a_2,/, left | a right |^2, -a_3,/, left | a right |^2))
    • Sum:( a + b = (a_0+b_0, a_1+b_1, a_2+b_2, a_3+b_3))
    • Hamilton product: $$begin{align}a times b ; = ; (& a_0b_0 - a_1b_1 - a_2b_2 - a_3b_3, & a_0b_1 + a_1b_0 + a_2b_3 - a_3b_2, & a_0b_2 - a_1b_3 + a_2b_0 + a_3b_1, & a_0b_3 + a_1b_2 - a_2b_1 + a_3b_0)end{align}$$
    • Quotient: ( a,/,b = a^{-1} times b )
  3. Dragon curve.Write a program Dragon.java thatreads in a command-line parameter N and plots the order N dragoncurve using turtle graphics. The dragon curve was first discoveredby three NASA physicists (John E. Heighway, Bruce A. Banks, and William G. Harter) and later popularized by Martin Gardner in ScientificAmerican (March and April 1967) and Michael Crichton in Jurassic Park.

    This is a sophisticated program that uses two mutually recursive functions.

    Program SequentialDragon.java is aniterative version of the dragon curve. It is a hacker's paradise.

  4. Hilbert curves.A space-fillingcurve is a continuous curve in the unit square that passes through every point.Write a recursive Turtle clientHilbert.java(or SingleHilbert.java)that produces these recursive patterns, which approach a space-filling curvethat was defined by the mathematician David Hilbert at the end of the 19th century.
  5. Gosper island.Write a recursive Turtle clientGosperIsland.java that produces these recursive patterns.
  6. Chaos with Newton's method.The polynomial (f(z) = z^4 - 1) has 4 roots at 1, −1, i,and −i.We can find the roots using Newton's method in the complexplane: (z_{k+1} = z_k - f(z_k) ,/ , f'(z_k)).Here (f(z) = z^4 - 1) and (f'(z) = 4z^3).The method converges to one of the 4 roots depending on the startingpoint (z_0).Write aprogram NewtonChaos.javathat takes a command-line argument n and creates ann-by-n image corresponding to the square ofsize 2 centered at the origin. Color each pixel white, red,green, or blue according to which of the four roots the correspondingcomplex number converges (black if no convergence after100 iterations).
  7. Color Mandelbrot plot.Create a file of 256 integer triples that represent interesting Color values,and then use those colors instead of grayscale values to plot each pixelin ColorMandelbrot.java Read the values to create an array of 256 Color values,then index into that array with the return value of mand().By experimenting with various color choices at various places in the set,you can produce astonishing images. See mandel.txt for an example.
    -1.5 -1.0 2.0 2.00.10259 -0.641 0.0086 0.0086
  8. Julia sets.The Julia set for a given complex number cis a set of points related to the Mandelbrot function.Instead of fixing z and varying c, we fix c and vary z.Those points z for which the modified Mandelbrot function stays boundedare in the Julia set; those for which the sequence diverges to infinity are not in the set.All points z of interest lie in the 4-by-4 box centered at the origin.The Julia set for c is connected if and only if c is in the Mandelbrot set!Write a program ColorJulia.javathat takes two command-line arguments a and b,and plots a color version of the Julia set for c = a + bi, using the color-table method described in the previous exercise.
    -1.25 0.00-0.75 0.10

Web Exercises

  1. IP addresses.Create a data type for IPv4 (Internet Protocol, version 4) addresses.An IP address is a 32-bit integer.
  2. Dates.Create a data type Date that represents a date.You should be able to create a new Date by specifying themonth, day, and year. It should supports methods to compute the number of days between two dates, return the day of the week thata day falls on, etc.
  3. Time bombs.UNIX represents the date with a signed integer measuring the numberof seconds since January 1, 1970.Write a client program to calculate when this date will occur.Add a static method add(Date d, int days) to your date datatype that returns a new date which is the specified number of daysafter the date d. Note that there are 86,400 seconds in a day.
  4. Qubits.In quantum computing, a qubit plays the role of a bit.It is a complex number a + bi such that |a + bi| = 1. Once we measurea qubit, it 'decides' to be a 1 with probability a2 and a 0 withprobability b2. Any subsequent observations will alwaysyield the same value. Implement a data type Qubit that hasa constructor Qubit(a, b) and a boolean method observethat returns true or false with the proscribedprobabilities.
  5. Biorhythms.A biorhythm is a pseudo-scientific profile of thethree natural cycles of your body: physical (23 days),emotional (28 days), and intellectual (31 days).Write a program that takes six command line inputs M, D, Y, m, d, and ywhere (M, D, Y) is the month (1-12), day (1-31), and year (1900-2100)of your birthday and (m, d, y) is today's month, day, and year. It should then print out your biorhythm on a scale of -1.0 to 1.0according to the formula: sin (2 π age / cycle length).Use the date data type created in the previous exercise.
  6. Particle.Create a data type for elementary or composite particles(electron, proton, quark, photon, atom, molecule).Each particle should have an instance variable to store itsname, its mass, its charge, and its spin (multiple of 1/2).
  7. Quark.Quarks are the smallest known building blocks of matter.Create a data type for quarks.Include a field for its type (up, down, charm, strange, top, or bottom)and its color (red, green, or blue).The charges are +2/3, -1/3, +2/3, -1/3, +2/3, -1/3, respectively.All have spin 1/2.
  8. Biorhythms.Plot your biorhythm in turtle graphics over a 6 week interval.Identify critical days when your rhythm goes from positiveto negative - according to biorhythm theory, this is when youare most prone to accident, instability, and error.
  9. Vector3.Include normal vector operations for 3-vectors, includingcross product.The cross product of two vectors is another vector.a cross b = ||a|| ||b|| sin(theta) n,where theta is angle between a and b, and n isunit normal vector perpendicular to both a and b.(a1, a2, a3) cross(b1, b2, b3) =(a2 b3 - a3 b2, a3 b1 - a1 b3, a1 b2 - a2 b1).Note that |a cross b| = area of the parallelogram withsides a and b.Cross product arises in definition of torque, angularmomentum and vector operator curl.
  10. Four-vector.Create a data type for four-vectors. A four-vector is a four-dimensional vector (t, x, y, z)subject to Lorentz transformations. Useful in special relativity.
  11. Euclidean points.Create a data type EuclideanPoint.java that representsa d-dimensional point. Include a method so that p.distanceTo(q)returns the Euclidean distance between points p and q.
  12. Vector field.A vector fieldassociates a vector with every point in a Euclidean space.Widely used in physics to model speed and direction ofa moving object or or strength and direction of aNewtonian force.
  13. Soda machine.Create a data type SodaMachine that has methodsinsertCoin(), getChange(), buy(), etc.
  14. Months.Write a data type Month that represents one ofthe twelve months of the year. It should have fields forthe name of the month, the number of days in the month,and the birthstone.
    MONTHDAYSBIRTHSTONE
    January31Garnet
    February28Amethyst
    March31Aquamarine
    April30Diamond
    May31Emerald
    June30Alexandrite
    July31Ruby
    August31Peridot
    September30Sapphires
    October31Opal
    November30Topaz
    December31Blue Zircon


  15. Gauss multiplication.Implement complex multiplication using only 3 floating pointmultiplications (instead of 4). You may use as many as 5 floatingpoint additions.Answer: Gauss gave the following method to multiply(a + bi)(c + di). Set x1 = (a + b)(c + d), x2 = ac, x3 = bd.Then the product is given by x + yi where x = x2 - x3, y = x1 - x2 - x3.
  16. Tensors.Create a data type for tensors.
  17. UN Countries.Create a data type Country for UN countries. Include fields for 3 digit UN Code, 3 letter ISOabbreviation, country name, and capital.Write a program Country.java that readsin a list of countries and stores them in an array of type Country.Use the method String.split to help parse the input file.
  18. Area codes.Create a data type fortelephone area codes in North America.Include fields for the area code, the city, and state, and the two letter state abbreviation.Or for internationalphone codes. Include a field for zone, code, and country.
  19. Congressional districts.Create a data type for places, counties, and congressional districts.Include fields for place name, county name, county code, zip code, congressional district, etc.Use the data sets from the1998 FIPS55-DC3 Index: Pennsylvania(2MB) orall 50 states plus DC and 9 outlying areas(30MB).
  20. Latitudes and longitudes.For USA latitudes and longitudes, use theTIGER database orwww.bcca.orgorgazetteer.For the rest of the world, useearth-info.
  21. Astronomy.Data forasteroids,meteors, andcomets.
  22. Fortune 1000 companies.Create a data type the for Fortune 1000. Include fields for company name and sales revenuein millions of dollars. Data taken from April 15, 2002 issueof Fortune. Note: currently need to parse data.
  23. Molecular weight.Write a program so that the user enters a molecule H2 O and the programcalculates its molecular weight.
  24. Some potentially useful datafiles:aroma therapies,nutritional information,meteorological glossary,psychiatric disorders,words translated in 15 languages,dictionary of emoticons,meanings of common names,World Almanac facts about countries.
  25. Student records.Create a data type Student.java to represent students in an introductory computer science course.Each student record object should represent a first name,last name, email address, and section number.Include a toString() method that returns a string representationof a student and a less() method that compares two students by section number.
  26. Impedance.Impedance is the generalization of resistance from DC circuitsto AC circuits.In an AC circuit, the impedance of a componentmeasures its opposition to the flow of electrons at a givenfrequency ω. The impedance has two components: the resistanceand the reactance.The resistance R of a circuit component measures itsopposition to the movement of electrons (friction againstmotion of electrons) when a given voltage is applied.The reactance X of a circuit component measures itsability to store and release energy as the current and voltagefluctuate (inertia against motion of electrons).

    In circuits with resistors only, the currentis directly proportional to the voltage. However, with capacitorsand inductors, there is a +- 90 degree 'phase shift' betweenthe current and voltage.This means that when the voltage wave is at its maximum, thecurrent is 0, and when the current is at its maximum the voltageis 0. To unify the treatment of resistors (R), inductors (L), and capacitors (C)it is convenient to treat the impedance as thecomplex quantity Z = R + iX.the impedance of an inductor is iwL and theimpedance of a capacitor is 1/iwC.To determine the impedance of a sequence of circuit elementsin series, we simply add up their individual impedances.Two important quantities in electrical engineering are themagnitude of the impedance and the phase angle.The magnitude is the ratio of the RMS voltage to the RMS current -it equals the magnitude of the complex impedance. The phase angle is the amount by which the voltage leads or lagsthe current - it is the phase of the complex impedance.Program CircuitRLC.java does a computationinvolving complex numbers and impedance of circuits withresistors, inductors, and capacitors in series.

    Exercise: RLC circuit in parallel. 1/Z = 1/Z1 + 1/Z2 + ... 1/Zn.

    Exercise (for objects): repeat series-parallel network forRLC circuits with impedances instead of resistance

  27. Diffusion of particles in a fluid.Simulate diffusion of particles in a fluid.See BrownianParticle.javain Section 9.8.
  28. Electric field lines.Michael Faraday introduced an abstraction called electric field linesto visualize the electric field.By Coulombs law, the electric field at a point induced by a pointcharge qi is given by Ei = k qi / r2,and the direction points to qi if qi is negative andaway from qi it is positive.If there are a group of n point charges, the electric field at a point isthe vector sum of the electric fields induced by the n individualpoint charges. We can compute it by summing up the components in the x- and y-directions. The figure below illustrates the field lines for two equalpositive point charges (left) and two point charges of opposite signs (right).The second configuration is called an electric dipole:the charges cancel each other out, and the electric field weakens veryquickly as you move away from the charges. Examples of dipoles can be foundin molecules where charge is not evenly distributed. Oscillating dipolescan be used to produce electromagnetic waves to transmit radio and television signals.

    Program FieldLines.javadraws 10 electric field lines coming out of each charge.(We take some liberties since traditionally the number of field linesper unit area should be proportional to the magnitude of the field strength.)Each line starts on a 1-pixel circle around the charge, at twelve equallyspaced angles.The electric field at a point (x, y) from a point charge qi is given byEi = k qi / r2, where qi is the magnitude of thecharge i and r is the radial distance from it. The field due to several charges is thevector sum of the field due to each, and can be found by adding the x- andy-components. After calculating the electric field strength, we move in thedirection of the vector field and draws a spot. We repeat this process untilwe reach the boundary of the region or another point charge.The figures below illustrate the electric potential and field lines forseveral random charges of equal magnitude.

  29. Koch snowflake with rainbow of colors.

    The Koch snowflake of order n consists of three copies of the Koch curve of over n.We draw the three Koch curves one after the other, butrotate 120° clockwise in between.Below are the Koch snowflakes of order 0, 1, 2, and 3.Write a program KochRainbow.javathat plots the Koch snowflake in a continuous spectrum of colors from red, toorange, yellow, green, blue, and indigo, and violet.

  30. Anti-Koch snowflakes.The anti-Koch snowflake is generated exactly likethe Koch snowflake, except that clockwise and counterclockwiseare interchanged. Write a program AntiKoch.java thattakes a command line parameter N and plots the anti-Koch snowflakeof order N using Turtle graphics.
  31. Randomized Koch snowflakes.A randomized Koch snowflake is generated exactly likethe Koch snowflake, except that we flip a coin to generate the clockwise and counterclockwise direction at each step.
  32. Turtle graphics.
    1. Minkowski sausage. (Sausage.java)
    2. Cesaro broken square.
  33. More turtle graphics.Write a program to produce each of the following recursive patterns.
    1. Levy tapestry. (Levy.java)
    2. Fudgeflake.
  34. Turtle graphics (hard).Write a program to produce each of the following recursive patternswithout lifting the pen or tracing over the same line segment morethan once.
    1. Sierpinski arrowhead.
    2. Sierpinski curve.
  35. Mandelbrot trajectory.Write an interactive program Trajectory.javathat plots the sequence of points in the Mandelbrot iteration in the complex plane.If the user clicks on (x, y), plot the sequence of iterates for z = x + iy.
  36. Faster Mandelbrot.Speed up Mandelbrot by performing the computation directly instead of usingComplex. Compare. Incorporate periodicity checking or boundarytracing for further improvements. Use divide-and-conquer: choose 4 corners of a rectangle and a few random points inside; if they'reall the same color, color the whole rectangle that color; otherwisedivide into 4 rectangles and recur.
  37. Random walker.Write a data type RandomWalker that simulates the motion ofa random walker in the plane that starts at the origin and makesa random step (left, right, up, or down) at each step.Include a method step() that moves the random walkerone step and a method distance() that returns the distancethe random walker is from the origin.Use this data type to formulate a hypothesis as to how far (asa function of N) the random walker is from the origin after N steps.(See also Exercise 1.x.)
  38. Big rational numbers.Create a data type BigRational.javafor positive rational numbers, where the numerators and denominators can be arbitrarily large.Hint: use java.math.BigInteger
  39. Deluxe turtle graphics.Extend Turtle in various ways.Make DeluxeTurtle that adds color, etc.Add a version that supports error checking.For example, throw a TurtleOutOfBoundsexception if turtle goes outside designated boundary.
  40. Write a program FourChargeClient.javathat takes a double command-line argument r,creates four Charge objects that are each distance rfrom the center of the screen (0.5, 0.5), and prints the potential atlocation (0.25, 0.5) due to the combined four charges.All four charges should have the same unit charge.
  41. Why does program Bug1.java create a java.lang.NullPointerException when executed?

    Answer: the programmer probably intended to make theno argument constructor set the string to hello. However,it has a return type (void) so it is an ordinary instance methodinstead of a constructor.It just happens to have the same name as the class.

  42. Why does program Bug2.java create a java.lang.NullPointerException when executed?
  43. Implement a data type Die for rolling a fair die, saywith 6 sides. Include a mutator method roll() and an accessor method value.
  44. Implement a mutable data type LFSR for a linearfeedback shift register.
  45. Implement a mutable data type Odometer.
  46. Complex trigonometric functions.Add methods to Complex.javasupport trigonometric and exponential functions on complex numbers.
    • (exp(a + ib) = e^a cos(b) + i , e^a sin(b))
    • (sin(a + ib) = sin(a) cosh(b) + i cos(a) sinh(b))
    • (cos(a + ib) = cos(a) cosh(b) - i sin(a) sinh(b))
    • (tan(a + ib) = sin(a + ib) ;/; cos(a + ib))
  47. Implement a data type VotingMachine for tabulating votes.Include mutator methods voteRepublican(),voteDemocrat(), and voteIndependent().Include an accessor method getCount() to retrieve thetotal number of votes.
  48. What happens when you try to compile and execute the following code fragment?

    Answer: it complains that x may not be initialized, and does not compile.

  49. What happens when you try to compile and execute the following code fragment?

    Answer: it compiles and prints out null.

  50. What is wrong with the following code fragment?

    Answer: it produces a NullPointerException because we forgot use newto create each individual Dog object.To correct, add the following loop after the array initializationstatement.

  51. What does the following code fragment print?
  52. What's wrong with the following code fragment that swapsthe Student objects x and y?

    Answer: First, the data type Student does nothave a no-argument constructor. If it did, then it would technicallybe correct, but the new Student() line is unnecessary and wasteful.It allocates memory for a new student object,sets swap equal to that memory address, then immediatelysets swap equal to the memory address of x.The allocated memory is no longer accessible. The following versionis correct.

  53. Find inputs to the Mandelbrot update formula that make itconverge (z0 = 1/2 + 0i), cycle with a period of 1 (z0 = -2 + 0i),cycle with a period of 2 (z0 = -1 + 0i),or stay bounded without converging (z0 = -3/2 + 0i).
  54. Point3D.Create a data type for points in 3 dimensional space.Include a constructor that takes three real coordinates x, y, and z.Include methods distance, distanceSquared, anddistanceL1 for the Euclidean distance, Euclidean distancesquared, and the L1-distance.
  55. Create a data type PhoneNumber.javathat representsa US phone number. The constructor should take three string arguments,the area code (3 decimal digits), the exchange (3 decimal digits)and the extension (4 decimal digits). Include a toStringmethod that prints out phone numbers of the form (800) 867-5309.Include a method sothat p.equals(q) returns true if the phone numbersp and q are the same, and false otherwise.
  56. Redo PhoneNumber.javabut implement it using three integer fields. Make the constructor take three integer arguments. Comment on the advantagesand disadvantages of this approach over the string representation.

    Answer: more efficient with time and memory.More hassle to handle leading 0s correct in constructor andtoString method.

  57. Write a program to draw the field lines for a uniform field.Arrange N evenly-spaced particles with charge e in a vertical column,and arrange N particles with charge -e in a vertical column so thateach charge on one side is lined up with a corresponding charge on theother side.This simulates the field inside a plane capacitor.What can you say about the resulting electric field?A. Almost uniform.
  58. Equipotential surfaces.An equipotential surface is the set of allpoints that have the same electric potential V. Given a group of Npoint charges, it is useful to visualize the electric potentialby plotting equipotential surfaces (aka contour plots).Program Equipotential.javadraws a line every 5V by computing the potential at each gridpoint and checking whether the potential is within 1 pixel of a multiple of5V. Since the electric field E measures how much the potential changes,E * eps is the range that the potential changes in a distance of 1 pixel.It relies on the helper programDeluxeCharge.java.

    It is also interesting to plot the field lines and the equipotential linessimultaneously. The field lines are always perpendicular the the equipotentiallines.

  59. Color palettes.Create Mandelbrot and Julia sets using different color palettes.For example, this scheme was proposed by Hubert Grassmannand produces a striking image of the Julia set

Fieldline Sling Pack


Last modified on April 23, 2020.
Copyright © 2000–2019Robert SedgewickandKevin Wayne.All rights reserved.

Field Lines Matlab

Whether you’re in a boat, on the ground, or in a tree stand, you’ll be more comfortable and more patient if you’ve got something soft to sit on. Fieldline’s Sportsman’s Seat features an inflatable inner tube to which you can add or remove air for maximum comfort. The seat cover is made of durable 1,000-denier Cordura¿¿ and has a carrying handle and a hook that can be attached to a belt loop. Available in Realtree¿¿, Mossy Oak¿¿, and Advantage¿¿ camouflage patterns. About $24; call (805) 529-6734.

Fieldline Range Bag

MORE TO READ