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

  Approximate the volume of cheese in a rectangular hunk

You will create a program that will approximate the volume of cheese in a rectangular hunk of Swiss cheese. For this approximation you will assume that the holes in the Swiss cheese are of two types: spherical bubbles (all of the same size) or cyl..

  What could you do to kill more mutants

What are the implications related to suite of unit test cases when some mutants are not killed and What could you do to kill more mutants?

  Rectangular and cylindrical coordinates

Write a program to convert between rectangular and cylindrical coordinates, based upon user input.

  Write a program to track hourly employee arrival

A company hires you to write a program to track hourly employee arrival and departure times from work. In essence, you are tasked to make an online time clock.

  In this project you need to write a program called

in this project you need to write a program called ecc.javato implement elliptic curve

  Data structures and algorithms

Code analysis and programming.

  Java swing components and file processing

Java Swing Components and File Processing, Write a program named GuessGame.java that plays the game "guess the number" as follows. Your program chooses the number to be guessed by selecting an integer at random in the range 1-1000. The program then..

  Part iyou have to write a computer program that will figure

part iyou have to write a computer program that will figure out the total of an order when given the amount of the

  Java programming-gamesystem

JTabbed Panes for GUI Components Part 2: --- Create a JFrame program with a JTabbed pane on it with two panels that mimics a control box for a game system.

  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 to register students for a college

Students have names, addresses and courses. Implement the interface class RegisterStudent. RegisterStudent has one method, public boolean register, which returns the boolean value of true or false if the student is successfully registered for the ..

  An advantage of a two-dimensional array

A two-dimensional array can have a different number of columns in every row. Do you see that as an advantage or a disadvantage

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