Results 1 to 6 of 6
  1. #1
    meangrant is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default Quadratic Equation Code Question

    Hi, I'm taking a computer science course and I hit a brick wall with my program. Something is wrong and I have no idea how to fix it.


    import java.util.*;
    import static java.lang.Math.*;
    public class QuadraticEquationGEM
    {

    Scanner input= new Scanner(System.in);
    public static void main(String[] args)
    {
    //Declare variables
    double a=0.0; double b=0.0; double c=0.0;double d=0.0;double e=0.0;
    double r1=0.0; double r2=0.0;

    //Ask user for input
    System.out.println("Please input 3 doubles to solve the Quadratic formula.");
    //Read and store a,b,c
    a=console.nextDouble();
    b=console.nextDouble();
    c=console.nextDouble();
    //If a=0, make program quit
    if (a==0){
    System.out.println("The input for a cannot be zero.");
    //Else compute d
    }else{
    b=Math.pow(b,2);
    d=(b-4*a*c);
    //If d<0 no solution
    if (d<0){
    System.out.println("The disciminant cannot be less than 0.");
    //Else if d=0, one solution.
    }else if (d==0){
    r1=(-b/2*a);
    System.out.println("The single root is "+r1);
    //If discriminant fits requirements, find the two roots.
    }else{
    e=Math.sqrt(d);
    r1=((-b+e)/2*a);
    r2=((-b-e)/2*e);
    System.out.println("The first root is " +r1);
    System.out.println("The second root is " +r2);
    }
    }
    }
    }


    The error messages I receive are:


    QuadraticEquationGEM.java:32: cannot find symbol
    symbol : variable console
    location: class QuadraticEquationGEM
    a=console.nextDouble();
    ^
    QuadraticEquationGEM.java:33: cannot find symbol
    symbol : variable console
    location: class QuadraticEquationGEM
    b=console.nextDouble();
    ^
    QuadraticEquationGEM.java:34: cannot find symbol
    symbol : variable console
    location: class QuadraticEquationGEM
    c=console.nextDouble();
    ^
    3 errors

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You are using a variable called console but never declare it, never initialize it. If this is supposed to be a Scanner variable, you will want to check your notes and texts to see how it is declared and used.

  3. #3
    meangrant is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Alright, I switched input to Scanner, thank you for the help.

    Now, I have a different problem where

    QuadraticEquationGEM.java:36: incompatible types
    found : double
    required: boolean
    if (a=0.0){


    QuadraticEquationGEM.java:46: incompatible types
    found : double
    required: boolean
    }else if (d=0.0){
    ^
    2 errors

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There's a big difference between the assignment operator, =, and the equals operator, ==. Does this now make sense?

    Luck!

  5. #5
    meangrant is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    nm, I got it fixed.

  6. #6
    meangrant is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. quadratic equation, problems that i can't solve
    By kourai in forum New To Java
    Replies: 2
    Last Post: 10-14-2010, 02:31 PM
  2. quadratic equation whith Rational class
    By adamrain in forum New To Java
    Replies: 8
    Last Post: 12-22-2009, 06:35 PM
  3. Quadratic Equation
    By jpnym15 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 04:29 AM
  4. Quadratic GUI
    By ryn21 in forum New To Java
    Replies: 1
    Last Post: 10-30-2008, 06:58 AM
  5. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •