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

  Program that computes and prints the value of 6!/5! using

Write a Java program that computes and prints the  value of 6!/5! using Scanner.

  Banking program that simulates the operation

Write a banking program that simulates the operation of your local bank. Declare the following class

  Programming exercises

Modify the rain program in Listing 10.7 so that it does the calculations using pointers instead of subscripts. (You still have to declare and initialize the array.)

  Write an algorithm for fining the middle node

Write an algorithm for fining the middle node of a doubly linked list given both the head and the tail of the list.And Write a  recursive  java function that counts the number of nodes in a circularly linked list.

  Design an object-oriented java application

You are to design an object-oriented Java application to let the user play a dice game that uses two dices. The player bets on a value and the dices roll

  Write program that uses a class named rectangle

Write program that uses a class named Rectangle. The class has floating point attributes length and width. it has member functions that calculate the perimeter and area of the rectangle. It also has set and get functions for both length and width.

  Write a program in java for searching of an item

Write a program in java for searching of an item in a list of n numbers using linear search.

  Write and describe the definition of what composition is

write and explain the definition of what composition is and how it is useful in writing an object-oriented program.

  Write a program to play a game of craps

Write a program to play a game of "craps," a dice game popular in casinos. Here are the rules - Use functions appropriately. The program should allow the user to play another round.

  Understanding of basic programming concepts

Demonstrate understanding of basic programming concepts by: 1. Constructing a simple flowchart that describes simple logic flow through a program;

  Classes using set and get methods

Create a java program that contains two classes using set and get methods. I need the program to return the area and perimeter of a rectangle. I wrote a program and he returned to me saying I used the wrong constructors and didn't create a the sec..

  Create a java program to calculate the circumference

Create a Java program based on the geometric shapes. The program should begin by prompting you for the shape you want to calculate the circumference.

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