Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Java-Assignment-005.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
56 changes: 56 additions & 0 deletions src/Quadratic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Quinn McKay
2/23/2024
Java Assignment 05
*/

import java.util.Scanner;
public class Quadratic {

public static void main(String [] args){

double a;
double b;
double c;

System.out.print("Let's calculate the roots of a quadratic equation using the formula ");
System.out.println("x = -b +-sqrt{b^2 - 4ac} / 2a");
System.out.println();

Scanner a_value = new Scanner(System.in);
System.out.print("First, enter the value of a: ");
a = a_value.nextDouble();
System.out.println();

Scanner b_value = new Scanner(System.in);
System.out.print("Next, enter the value of b: ");
b = b_value.nextDouble();
System.out.println();

Scanner c_value = new Scanner(System.in);
System.out.print("Last, enter the value of c: ");
c = c_value.nextDouble();
System.out.println();

double x_1;
double x_2;
double xb2_4ac;
double xsqrt;
xb2_4ac = Math.pow(b,2) - (4 * a * c);
xsqrt = Math.sqrt(xb2_4ac);
x_1 = (-b + xsqrt) / (2 * a);
x_2 = (-b - xsqrt) / (2 * a);

if (a == 0){
System.out.println("Error- a can not equal 0 in this scenario.");
} if (xb2_4ac < 0){
System.out.println("Error- cannot find square root of a negative number.");
} else if (!(a == 0 && xb2_4ac < 0)){
System.out.println("Great know lets find the two x values");
}
System.out.println();

System.out.println("The value of the first x is " + x_1);
System.out.println("The value of the second x is "+ x_2);
}
}