Skip to content

Instantly share code, notes, and snippets.

@bytecodeman
Last active December 3, 2021 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytecodeman/a5f5b5a92c0353d441400a791d1cb7f3 to your computer and use it in GitHub Desktop.
Save bytecodeman/a5f5b5a92c0353d441400a791d1cb7f3 to your computer and use it in GitHub Desktop.
Driver code fr the CSC-111 Quadratic Class Assignment
/*
* Name:
* Date:
* Course Number:
* Course Name:
* Problem Number:
* Email:
* Short Description of the Problem
*/
import java.util.Scanner;
public class QuadraticDriver {
private final static String TITLE = "Quadratic Equation Solver V1.0";
private final static String CONTINUE_PROMPT = "Do this again? [y/N] ";
//**********************************************
// Put as many methods you need here
//**********************************************
// Start your logic coding in the process method
private static void process(Scanner sc, String args[]) {
System.out.print("Enter coefficients of the Quadratic: ");
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
sc.nextLine(); // Clear Keyboard
Quadratic q = new Quadratic(a, b, c);
System.out.println("Quadratic Equation: " + q);
int noOfRoots = q.noOfRoots();
if (noOfRoots == 2) {
double r1 = q.getRoot1();
double r2 = q.getRoot2();
System.out.printf("Two Roots = %.3f, %.3f\n", r1, r2);
}
else if (noOfRoots == 1) {
double r = q.getRoot1();
System.out.printf("One Root = %.3f\n", r);
}
else {
System.out.println("No Real Roots\n");
}
}
//**********************************************
// Do not change the doThisAgain method
private static boolean doThisAgain(Scanner sc, String prompt) {
System.out.print(prompt);
String doOver = sc.nextLine();
return doOver.trim().equalsIgnoreCase("Y");
}
//**********************************************
// Do not change the main method
public static void main(String args[]) {
System.out.println("Welcome to " + TITLE);
Scanner sc = new Scanner(System.in);
do {
process(sc, args);
} while (doThisAgain(sc, CONTINUE_PROMPT));
sc.close();
System.out.println("Thank you for using " + TITLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment