My code will not run properly. I need help fixing the errors in my code import java.util.Scanner; public class Quad

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

My code will not run properly. I need help fixing the errors in my code import java.util.Scanner; public class Quad

Post by answerhappygod »

My code will not run properly. I need help fixing the errors in
my code
import java.util.Scanner;

public class Quad
{
private int a;
private int b;
private int c;

public Quad()
{
a = 1;
b = 1;
c = 1;

public Quad (int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;

public double root1()
{
double top = -b +
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;
}

public double root2()
{
double top = -b -
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;

@Override
public String toString()
{
return a + "x^2 + " + b +
"x + " + c;
}
}
class Main
{
public static void main(String[]
args)
{
Scanner in = new
Scanner(System.in);
System.out.print("Enter
the value of a: ");
int a =
in.nextInt();
System.out.print("Enter
the value of b: ");
int b =
in.nextInt();
System.out.print("Enter
the value of c: ");
int c =
in.nextInt();
Quadratic n1 = new
Quadratic(a,b,c);
System.out.println("n1 = "
+ n1.toString());
System.out.println("root1
= " + n1.root1());
System.out.println("root2
= " + n1.root2());
System.out.println("disc =
" + n1.discriminant());
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply