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

  The game of pig

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

  What are the gui components in java

What are the GUI components in Java? Explain at least two of them

  Converts a number entered in roman numerals

Write a program that converts a number entered in Roman numerals to decimal form. Your program should consist of a class, say RomanType. An object of romanType should do the following: a. Store the number as a Roman numeral.b. Convert and store the ..

  Complete the method definitions in linkedqueue.java

Complete the method definitions in LinkedQueue.java. Some things to think about- In enqueue() and dequeue() you have to maintain both the front and back pointers - this takes a little thought. In particular, in enqueue be careful of the case where..

  Technical community blog

Write a blog article for a coding/technical community blog

  Construct java program named collegelist

Construct a set of classes for a college to use in many student service and personnel applications. Classes you require to design include following:

  Draw a uml diagram of each of the shapes

Draw a UML diagram of each of the Shapes, Rectangle and Square classes using the code that has been provided. Complete this using the examples that have been provide in the lecture slides - Sample program is provided that creates a list of shapes ..

  The department of community affair- jail report

The Department of Community Affairs (DCA) for the State of Georgia performs many functions including gathering statistics and doing research. DCA provides a monthly jail report that provides some interesting information about jails in the state.

  Write a program deal that takes an integer and prints

Write a program Deal that takes an integer, save it in "kHands" from the keyboard and prints kHands poker hands (five cards each hand) from a shuffled deck, separated by blank lines Screenshot of the program and hands.

  Write an advanced java program for the game blackjack

Write an advanced java program for the game blackjack according to the following below data flow diagram

  Enhance the test score applicaion

Enhance the Test Score applicaion so it uses a "while" or a "do-while" loop plus a for loop - Change the while statement to a do-while statement, andtest this change. Does this work any better than the while loop?

  What things are you struggling to understand

Discuss your experiences with the programming assignment - what things are you struggling to understand?

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