QuadInJava
Helper file for Quad for those who want a starting point otherwise, most welcome to start from scratch.
Size 2.1 kB - File type text/x-javaFile contents
import java.util.Scanner;
public class Quad
{
//-----------------------------------------------------------------
// Skeleton of quad class.
// I only show you guys three exceptions in case you don't know
// quadratic rules.
// Think of what else throws an expection and catch them in your
// project. These should be shown to us when you execute the
// program. I can think of at least one very obvious one.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int a, b, c; // ax^2 + bx + c
double discriminant, root1, root2;
boolean restart;
//User input three integers.
Scanner scan = new Scanner (System.in);
do {
System.out.print ("Enter the coefficient of x squared: ");
a = scan.nextInt();
System.out.print ("Enter the coefficient of x: ");
b = scan.nextInt();
System.out.print ("Enter the constant: ");
c = scan.nextInt();
//should use try and catch
//if 'a' is zero then throw an exception saying
//a can't be zero
//else go on to compute discriminat and roots------------
//dicriminant, compute discriminant. Can use pow from math class
//if discriminant is zero than throw an exception saying
//discriminant is less than zero.
//two roots, compute two roots. Can use sqrt function from
//math class
System.out.println ("Root #1: " + root1);
System.out.println ("Root #2: " + root2);
//end of else--------------------------------------------
//end of try---------------
//catch an exception if there is no solution
//--------------------------------------------------------------------
//program continues if user enters true and exits if entered false.
System.out.println();
System.out.println("True to continue and False to exit");
restart = scan.nextBoolean();
} while(restart);
} //end of main
} //end of class
Click here to get the file