AP Computer Science A is both a college-prep course for potential computer science majors and a foundation course for students planning to study in other technical fields such as engineering, physics, chemistry, and geology. The course emphasizes methodology, procedural abstraction, and in-depth study of algorithms, data structures, and data abstractions, as well as a detailed examination of a large case study program. Instruction includes preparation for the AP Computer Science A exam. In this course, students apply the programming tools they have learned to real-life examples on their own. Computer science is more than just programming; students who successfully complete the course will have an understanding of Java and the ability to adapt to any new programming language that they are taught in college.
import java.util.*;
public class Quadratic {
public static void main(String[] args) {
//declare variables.
double a, b, c, discriminant, root1, root2;
Scanner kb = new Scanner(System.in);
System.out.println("Enter the degree 2 coefficient of a quadratic equation:");
a = kb.nextDouble();
System.out.println("Enter the degree 1 coefficient of a quadratic equation:");
b = kb.nextDouble();
System.out.println("Enter the degree 0 coefficient of a quadratic equation:");
c = kb.nextDouble();
boolean openingup = (a > 0);
System.out.println("It is " + openingup + " to suggest that the parabola opens up.");
//we are assuming that the quadratic equation has a solution.
discriminant = b*b -4*a*c;
root1 = (-b + Math.sqrt(discriminant))/(2*a);
root2 = (-b - Math.sqrt(discriminant))/(2*a);
System.out.println("The first root is: " + root1+".");
System.out.println("The second root is: " + root2+".");
} //end main
} //end class