Write a java program that prints all real solutions

Assignment Help Computer Engineering
Reference no: EM1329549

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

Questions Cloud

Employeeexception class whose constructor receives a string : build an Employee class with two fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, it throw an EmployeeException if the hourlyWage is less than 6.00 or over 50.00. Save the class as Employee..
Adopting the victims right amendment : Would adopting a victims right amendment to the U.S. constitution genuinely improve the plight of crime victims.
Estimate the relationship among inflation and unemployment : Estimate the relationship among inflation and unemployment.
It effectively in its logistical operations : How can we evaluate whether an organization is using IT effectively in its logistical operations
Write a java program that prints all real solutions : make 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 getSolu..
Supply chain management and knowledge management : What do you meant by the relationship between supply chain management and knowledge management, and how do they both relate to corporate strategies?
Ordinal data : Ordinal data are:
Laissez-faire leadership appropriate in which situation : Are there circumstances where laissez-faire leadership might be appropriate? (What are they?)
Determine major means of control : Global Supply Chain Management - Compare and contrast decision making at headquarters and at foreign subsidiary locations and determine major means of control

Reviews

Write a Review

Computer Engineering Questions & Answers

  Explain the software packages in detail

explain the software packages in detail. analysis of the advantages and disadvantages of each of the software packages used.

  Which method allow channel to synchronization sequence

Which method allow channel to synchronization sequence? Discuss the trade-offs between fibre optic and satellite communication in terms of costs, signal capacity, signalling method, interference, likelihood of failure and repair issues, multipoin..

  What benefits the network provide

Explain what kind of network you are on at work or at home. If you do not have access to a network, ask a friend or family member to explain the type of network they have access to.

  Performance improvement for the least amount of money

suppose in your computer, the most of your daytime processes spend 75 percent of their time running in the CPU and 25% waiting for service from disk.

  Sectors on the physical device

For any volume(s) situated on the EnCE Hard Drive, answer the following questions by writing question number and answer within a Notes Bookmark. Keep the Notes Bookmark within the bookmark folder created for that volume. Specify how many sectors a..

  Express and give an example of a web database.

Explain the difference between system design and system analysis.

  Program for calling the function

Suppose the availability of class named DataTransmitter which offers a static method, sendSignal which takes no arguments. Write down the code for calling this method.

  Explain protocol and network switching device

An area along the north wall of the coffee house has been set aside for the five computer stations, and since this is a very popular local hangout, it is expected that the computers, as well as wireless connections, would be in constant use. She i..

  New eap authentication

When a new EAP authentication is added, software do NOT have to be altered on the: No software has to be changed on ANY device, Authenticator, Central authentication server, Client.

  Computing the fmin value

Compute the minimum: Graphically, Numerically with the f min search function

  Write down a css rule

Write down a CSS rule

  Define the criteria for go vs. nogo

The final phase of a project is the close-out also known as the post mortem. When the project reaches this phase, the project has been successfully delivered and all tasks are complete. What do you think detail tasks in this phase must be.

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