Program that prints real solutions to the quadratic equation

Assignment Help JAVA Programming
Reference no: EM13940517

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: EM13940517

Questions Cloud

Dalton playground equipment : At Dalton Playground Equipment, the powder-coating process is a bottleneck. Typically, it takes approximately two hours to switch between jobs.
Fixed overhead and the variable overhead rate : The XYZ Tool Manufacturing Co. shows the following factory overhead costs at various levels of direct labor hours for the last four months:Direct Labor
Differentiation between market structures competitive : Differentiation between market structures, competitive strategies and the positive or negative impact on the organization with industry specific analysis. Identification of the competitive strategies and the effectiveness of the same. Recommendations..
Conflict between the project managers : 1. What caused the conflict between the project managers and the other employees? 2. How would you design the authorities of a project manager at BEC?
Program that prints 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. If the discriminant (b^2 - 4ac) is negative, display a message stating that there are no real solutions..
Discuss osha''s recommendations for effective fall : Discuss OSHA's recommendations for effective fall protection relative to a workplace fall incident that you are familiar with (if you do not know of a fall from heights that happened in your present or past workplace,
What is justification with regards to commission of crimes : What is Justification with regards to the commission of crimes and what are the different types (examples) of criminal defenses that fall under the category of Justification? In other words, is there any valid legal justification for committing a ..
Case study on newly arrived refugees : The task is to write an essay demonstrating your ability to apply theory and analysis of your allocated case. This is a paper in which you must provide a defense of your chosen theory and should include arguments as to why this represents the best..
Explain how cvp analysis can be used for managerial planning : Explain how CVP analysis can be used for managerial planning. Describe the difference between the units sold approach to CVP analysis and the sales revenue approach.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Modify the homestead furniture store application

Design an application for the homestead furniture store that gets sales transaction data including an account number customer name and purchase price.

  Build the gui layout of the gamecreate a class called

build the gui layout of the gamecreate a class called pipegameapp.java which will be the main game user interface. the

  Display all of the elements of the arraylist

Once the user does this (hits enter without typing anything), the program will display all of the elements of the ArrayList, both the index and String values, in a table. It will do this via a single loop.

  Make a fourth button called special

Make a fourth button called "special" that does something else notdescribed in the assignment, such as change the background color.

  Prompts the user for three first names

Write an application that prompts the user for three first names and concatenates them in every possible two-name combination so that new parents can easily compare them to find the most pleasing baby name. Save the file as BabyNameComparison.java

  Implement a class icecreamcone

Implement a class IceCreamCone with methods getSurfaceArea() and getVolumn(). In the constructor, supply the height and radius of the cone. Be careful when looking up the formula for the surface area

  1 linked listsin this problem you will write a class that

1 linked listsin this problem you will write a class that implements an ordered list of strings. your class will able

  Write an application that extends jframe

Write an application that extends JFrame and that displays a phrase in every font size from 6 through 20.

  Implementing a binary tree write a generic implementation

Implementing a Binary Tree Write a generic implementation of a binary tree class using an internal node class TreeBinUMUC and NodeTreeBin

  Create your program using eclipse

Create your program using Eclipse. Name your project Assignment5 and the Java class Loops. Use the Scanner class to get input from the user and use System.out to print to the console window.

  Computer network and data communication

What are the question for computer network and data communication

  Java application to display multiple choice questions

Write down the application which displays series of TEN(10) multiple choice questions: questions must cover all the Java. Each question must have four possible answers and only one answer must be correct.

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