Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and submit your code in a file called Intersect.java. Use the IO module to

ID: 670963 • Letter: W

Question

Write and submit your code in a file called Intersect.java. Use the IO module to read inputs. Use
System.out.println() to print your answer.
Write a program that calculates the intersection between 2 equations:
a degree2
(quadratic) polynomial i.e.
y = dx ^ 2 + fx + g
where d, f, and g are constants
and a degree1
(linear) equation i.e.
y = mx + b
where m is the slope and b is a constant
The above is just text, not code that could appear in a Java program.
Ask the user for the constant values in each equation. Output the intersection(s) as ordered pair(s) (x,y), or
"none" if none exists. Below is an example run.
java Intersect
Enter the constant d :
5
Enter the constant f :
- 3
Enter the constant g :
2
Enter the constant m :
1
Enter the constant b :
3
The intersection ( s ) is / are :
( 1 , 4 )
(- 0.20 , 2.8)

Explanation / Answer

public class Intersect
{
public static void main(String[] args)
System.out.println("Enter the constant d:");
int d = IO.readInt();
System.out.println("Enter the constant f:");
int f = IO.readInt();
System.out.println("Enter the constant g:");
int g = IO.readInt();
System.out.println("Enter the constant m:");
int m = IO.readInt();
System.out.println("Enter the constant b:");
int b = IO.readInt();
int A = d;
int B = f - m;
int C = g - b;
double t = -(f - m) / (2.0 * d);
double u = t * t - (g - b) / (double) d;
if (d == 0)
{
if (f == m)
{
if (g == b)
System.out.println("There is an infinite amount intersections");
else
System.out.println("There are no intersections");
}
else
{
double x = (b - g) / (double) (f - m);
double y = m * x + b;
System.out.println("The intersection is: (" + x + "," + y + ")");
}
}
else if (u < 0)
System.out.println("There are no intersections");
else if (u == 0)
{
double x = t;
double y = m * x + b;
System.out.println("The intersection is: (" + x + "," + y + ")");
}
else
{
double x1 = t + Math.sqrt(u);
double x2 = t - Math.sqrt(u);
double y1 = m * x1 + b;
double y2 = m * x2 + b;
System.out.println("The intersections are: (" + x1 + "," + y1 + ") (" + x2 + "," + y2 + ")");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote