Prints all real solutions to the quadratic equation

Assignment Help JAVA Programming
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");
}
}

Reference no: EM13940472

Questions Cloud

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..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd