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

  Question superclass and provide a different implementa

Add a method addText to the Question superclass and provide a different implementa- tion of ChoiceQuestion that calls addText rather than storing an array list of choices.

  Create a 2-dimensional array for the volume of concrete

Your Company constructs concrete hemispherical domes that range in diameter from 40 to 90 feet and increments of 5 feet.

  Java program that reads from standard input

Write a JAVA program that reads from the standard input stream (System.in) the order of cards in a deck and outputs who will win as well as the number of rounds played. It is assumed that there are two players, Player 0 and Player 1.

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Write a java program called calctickets

write a java program called CalcTickets that prompts (asks) the user to enter a ticket number. The format of a valid ticket is C[C]DDDDD[C][C]

  Define responsive design

Define Responsive Design and clarify what techniques can be used to create a responsive design for a web application? Explain what makes jQuery Mobile different from other JavaScript libraries such as jQuery and jQueryUI

  Write a method shift that takes a stack of integers

Write a method shift that takes a stack of integers and an integer n as parameters and that shifts n values from the bottom of the stack to the top of the stack.

  The project involves benchmarking the behavior of java

The project involves benchmarking the behavior of Java implementations of one of the following sorting algorithms, bubble sort, selection sort, insertion sort, Shell sort, merge sort, quick sort or heap sort. You must post your selection in the "Ask ..

  Write a method called alldigitsodds that returns

Write a method called AllDigitsOdds that returns whether every digit of a positive integer is odd. Return true if the numbers consist entirely of odd digits (1,3,5,7,9)

  Implementing a relatively simple text-compression scheme

You will be implementing a relatively simple text-compression scheme - It should run from the command line.

  These are more specialized versions of the pizzaorders you

your pizza shop expands and now handles delivery orders and sit down orders in a restaurant setting. there are

  Technical community blog

Write a blog article for a coding/technical community blog

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