JAVA
Quadratic Equation
Design and write a Java code that solves a quadratic equation ??2 + ?? + ? = 0. Please use class and object definitions and do not use procedural style.
Let the roots of ??2 + ?? + ? = 0 be ? and ?.
Show that the following:
? + ? = − ?/?' ,
and
?? = ?/?' ,
for non-trivial of values of ?, ?, ?. Make sure that you address that complex numbers as objects.
//Java program
import java.util.Scanner;
class Complex{
private double real,imag;
public Complex(double r , double i) {
real = r;
imag = i;
}
public void setReal(double r) {
real = r;
}
public void setImag(double i) {
imag = i;
}
public double getReal() {
return real;
}
public double getImag() {
return imag;
}
public String toString() {
return real + " + "+imag+
"i\n";
}
}
class Quadratic{
private double a,b,c;
public Quadratic(double a,double b,double c) {
this.a = a;
this.b = b;
this.c = c;
}
public double discriminate() {
return b*b - 4*a*c;
}
public Complex getRoot1() {
double D = discriminate();
double real,imag;
if(D<0) {
real =
(b*-1)/(2*a);
imag =
Math.sqrt(D*-1)/(2*a);
return new
Complex(real,imag);
}
real = (b*-1 +
Math.sqrt(D))/(2*a);
return new Complex(real,0);
}
public Complex getRoot2() {
double D = discriminate();
double real,imag;
if(D<0) {
real =
(b*-1)/(2*a);
imag =
Math.sqrt(D*-1)/(2*a);
return new
Complex(real,imag);
}
real = (b*-1 -
Math.sqrt(D))/(2*a);
return new Complex(real,0);
}
}
public class QuadraticEquation {
public static void main(String args[]) {
Scanner in = new
Scanner(System.in);
Quadratic q;
double a,b,c;
System.out.print("Enter a :
");
a = in.nextDouble();
System.out.print("Enter b :
");
b = in.nextDouble();
System.out.print("Enter c :
");
c = in.nextDouble();
q = new Quadratic(a,b,c);
System.out.print("Root1 : "+
q.getRoot1());
System.out.print("Root1 : "+
q.getRoot2());
in.close();
}
}
JAVA Quadratic Equation Design and write a Java code that solves a quadratic equation ??2 +...
DQuestion 19 28 pts Problem 2. Quadratic Equations A quadratic equation has the form: a bc0 The two solutions are given by the formula: 2a Write a program with a loop that a) solves quadratic equations with coefficients read from the terminal, b) visualizes the corresponding quadratic function az2 brc0using the matplotlib module. Instructions Write all code for this problem in a file p2.py 1. The program consists of a main whtle loop (an infinite loop) in which the user...
Use Python Programming.
Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...
java code
Design a class named QuadraticEquation for a quadratic equation with real coefficients ax? + bx + x = 0 where a = 0. The class contains: (a) Private data fields a, b, and c that represent three coefficients. (b) A constructor taking arguments for a, b, and c. (c) Getter and setter methods for each attribute field. (d) A method named getDiscriminant() that returns the discriminant, 62 - 4ac. (e) A method named hasReal Solution that determines If...
reword m the program into a design document
diregard the m
Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...
Java Programming Question. I am writing a code to calculate the roots of the quadratic equation based on the values of the coefficients A, B, and C. I am supposed to enter 5 values for each coefficient, and the output should be five different answers (see example) using a for loop and if else statements. However, when I run my code, I am only able to enter one value for each coefficient and the output is one answer repeated five...
please answer this question with python.
Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...
use 5 digits pls thx
2. (Complez Numbers: Quadratic Equations; Scientific Calculators). Solve the quadratic equation 22 -(1-3i): -22 +3i- and verify your answer with Wa by using the command solve z"2-(1-31) -22+31 #0 z 3. (Complez Numbers: Extraction of Roots; Scientific Calculators). Use a scientific calculator to find approximations of all seven roots of degree seven of the complex number and show them on the complex plane (approximations of the real and imaginary parts of all the roots must...
1) Using the Quadratic class you have already developed, make it Comparable. A Quadratic is bigger than another Quadratic if it opens faster. 2) Write a driver for Quadratic.java. In the driver program create a few objects and compare them . then create a list of those objects and sort them. import java.util.*; import java.lang.*; class Quadratic{ private double a,b,c; // Determines/declares the class variables to store the coefficients Quadratic(){ // Determine/declare the default constructor ...
Write a C program, to solve the quadratic equation a x2 + b x + c = 0 of given coefficients a, b and c. When running the program, it prompts for the input of coefficients a,b,c as floating numbers. After inputting three floating numbers, it computes and prints out the solutions, then prompts for another round of input. Your program will quit when getting input 0,0,0. Your program should handle four situations: (1) a=0, not a quadratic equation; (2)...
A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...