Reference no: EM13940472
Write a Java program that prints all real solutions to the quadratic equation ax^2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminant (b^2 - 4ac) is negative, display a message stating that there are no real solutions.
Implement a class QuadraticEquation whose constructor receives the coefficients a, b, c of the quadratic equation. Supply methods getSolution1 and getSolution2 that get the solutions, using the quadratic formula, or 0 if no solution exists. The getSolution1 method should return the smaller of the two solutions.
Supply a boolean method hasSolutions that returns false if the discriminant is negative.
Use the following class as your tester class:
/**
This program tests the QuadraticEquation class.
*/
public class QuadraticEquationTester
{
public static void main(String[] args)
{
QuadraticEquation eq1 = new QuadraticEquation(2, 2, -4);
System.out.println(eq1.hasSolutions());
System.out.println("Expected: true");
System.out.println(eq1.getSolution1());
System.out.println("Expected: -2");
System.out.println(eq1.getSolution2());
System.out.println("Expected: 1");
QuadraticEquation eq2 = new QuadraticEquation(-2, -2, 4);
System.out.println(eq2.hasSolutions());
System.out.println("Expected: true");
System.out.println(eq2.getSolution1());
System.out.println("Expected: -2");
System.out.println(eq2.getSolution2());
System.out.println("Expected: 1");
QuadraticEquation eq3 = new QuadraticEquation(2, 2, 4);
System.out.println(eq3.hasSolutions());
System.out.println("Expected: false");
System.out.println(eq3.getSolution1());
System.out.println("Expected: 0");
System.out.println(eq3.getSolution2());
System.out.println("Expected: 0");
}
}
What offences could ketut, rhonda, trent, and tim be charged
: What offences could Ketut, Rhonda, Trent, and Tim be charged with under Victorian and federal drug laws? Explain your response using relevant legislation and case law. Deal with each person in turn.
|
Return on common stockholders equity
: The condensed financial statements of John Cully Company, for the years ended June 30, 2012 and 2011, are presented below.John Cully Company
|
Discuss how would create and implement such unit in agency
: Discuss how you would create and implement such a unit in this agency. Discuss other factors you would need to consider, such as who would lead it, and who would staff the unit? What resources would you give this unit and what authorities and goal..
|
What must be the rate of return earned by the firm
: If the sustainable growth rate is 5% and the plow back ratio is .4, what must be the rate of return earned by the firm on its new investments?
|
Prints all real solutions to the quadratic equation
: Write a Java program that prints all real solutions to the quadratic equation ax^2 + bx + c = 0. Read in a, b, c and use the quadratic formula
|
Ina machine company flexible budget
: The production budgeted for September was 6,000 units. During the month, the company produced 6,200 units. The conversion costs incurred were:
|
How awareness of worldwide patterns of race and racism
: Summarize why Winant believes that "the global racial situation remains volatile and undertheorized" (2006, p. 988). Explain if you agree or disagree with this belief, supporting your position.
|
Current state of water accounting in australia
: Your task is to research the current state of water accounting in Australia. At a minimum you should be able to report on: Who currently has oversight responsibility and authority to direct water accounting in Australia?
|
Write an essay on lemonade stand activity
: Lemonade Stand Activity. As you have read about in our lecture, we have used a lemonade stand to help us understand some basic concepts of business. As we pointed out, a lemonade stand has simple business; yet it can help us understand almost every f..
|