Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will work with two Java source files: - Geometry java. This file contains the Geometry class definition. Within this class you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In this assignment you will work with two Java source files: - Geometry java. This file contains the Geometry class definition. Within this class you will implement five class methods. - Testgeometry jaya. This program uses the methods within the Geometry class, allowing a user to enter in the coordinates of two geometric points. The program then prints four things: 1. the distance between the two points, 2. the slope of the line that passes through the two points, 3. the y-intercept of the line that passes through the two points, unless the line is vertical; in which case the program prints the x-intercept of the line, and 4. the equation of the line (in slope-intercept form) that passes through the two points. You should not modify the code in Testgeometry. java. Your task is to implement the methods in Geometry. Java. The code within Testgeometry. java will use this functionality. The program found in Testgeometry. java will compile and run with the provided skeletal Geometry. java file, but the TestGeometry java program will not produce the correct results until you correctly implement the expected methods in Geometry , java. The required methods are: - floatEquals Remember that many floating-point numbers do not have an exact representation. This means the == operator may consider two floating-point numbers unequal even though we believe they should be equal. Complete the floatEquals method that returns true if its two double-precision floating-point arguments are within 0.0001 of each other; otherwise, the method should return false. - distance The distance between two points (x1,y1) and (x2,y2), is given in the following formula: (x2x1)2+(y2y1)2 Complete the method named distance that accepts four double-precision floating-point arguments x1,y1,x2, and y2, in that order, representing two geometric points (x1,y1), and (x2,y2). It should return the double-precision floating-point value representing the distance between the two points. You can compute the square root of a numeric value via the Math. sqrt method found in the Java standard library. - slope The slope of the line passing through two points (x1,y1) and (x2,y2), is the difference of the y values divided by the difference of the x values: m=x2x1y2y1 Complete the method named slope that accepts four double-precision floating-point arguments and returns the double-precision floating-point value representing the slope of the line passing through the two points represented by the arguments. Watch out for vertical lines! Return the predefined constant Double. POSITIVE_INFINITY to represent infinity if the line is vertical. Note: The method should throw an IllegalArgumentException if the caller passes parameters that represent two equal points. The following statement achieves the desired behavior: throw new IllegalArgumentException(); intercept An intercept is a number that represents a location on an axis where a line intersects that axis. The y-intercept of a line is the y value of the point where a crosses the y-axis. Complete the method named intercept that accepts four double-precision floating-point arguments representing the coordinates of two points. The method ordinarily returns the double-precision floating-point value representing the y-intercept of the line that that passes through the two points defined by the arguments. For non-vertical lines, we can compute the y-intercept from the y=mx+b form of a line. Solving for b, we get b=y - mx : b=ymx This means if we know the slope, m, we can plug in the (x,y) coordinates from either point to compute b. Vertical lines do not have a y-intercept, so the intercept method instead should return the x-intercept for vertical lines. If the two points form a vertical line, it is easy to determine the x-intercept. Note: The method should throw an IllegalargumentException if the caller passes parameters that represent two equal points. lineToString The equation of a line in slope-intercept form is where m is the line's slope, and b is the line's y intercept. y=mx+b Complete the method named linetostring that accepts two double-precision floating point arguments representing the slope and y-intercept of a line. The method should return a string object representing the equation of that line in slope-intercept form. Round all numbers to two places behind the decimal point. We know how to print a rounded floating-point number using system.out.printf: System.out.printf("Thenumberis89.4f",1.2345678); but what if instead of printing it you want to store the message in a string object exactly as it would be printed by system. out.printf? You can use the format method of the String class to achieve the desired results: Strings=string.format("Thenumberis89.4f",1.2345678); The format codes and the way the format string is handled works like those in system.out-printf. Your equation should be "pretty," meaning do make an equation like y=1.00x+3.00 rather render it as y=x3.00 and an equation like should be rendered as y=20.50x Place spaces around the equals symbol and the addition and subtraction symbols so the equation appears as you might see it in a mathematics textbook. This means you will need some conditional statements within your linerostring method to fine tune the exact output. If the first parameter passed to the method is Double.POSITIVE_INFINITY, it represents a vertical line. The second parameter then represents the x intercept instead of a y-intercept. A vertical line has the form x=b where b is the x-intercept. Your method should return a string that correctly represents the equation for vertical lines. As you begin developing your linetostring method do not worry about pretty formatting. First concentrate on getting the numbers correct, and after you are sure the results are mathematically sound then, if you have time, proceed to make the representation more attractive. If you do not have the time or interest to make the string "pretty," you may elect to receive 9/10 points for the assignment if your string is just mathematically correct. te that the distance, slope, and intercept methods should return their results in full precision; that is, do not round the values they compute. Only the neTostring method involves rounding. va's Double.POSITIVE_INFINITY constant is a special value in the IEEE 754 standard floating-point representation. Since it represents "infinity," it cannot rticipate in arithmetic with other floating-point numbers. If you need to determine if a value is Double. POSITIVE_INFIMITY (when you are checking if a line in rtical, for example), you should use the == operator, not the floatequals method. The == operator checks for the exact bit pattern of uble.POSITIVE_INFINITY

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Describe how self-defeating attitudes create a vicious cycle.

Answered: 1 week ago

Question

=+1. How can the process of movie utilization be described?

Answered: 1 week ago