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

  Knowledge of agency level enterprise operating systems

information of advanced Relational Database management Systems (RDMS) operating over a wide-area network. (note: Please explain RDMS operating over a WAN.)

  Modify the pseudocode and optimize

offer valid reasons why the pseudocode is now more efficient.

  Developing the lan network for a company

You have been asked to develop a LAN with operation over the distance of around 100m. Compare and contrast the twisted pair cable, fiber-optics, and wireless for this application.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Program to implement the calculations

Write down a program which has a function named presentValue which carry out this calculation. The function must accept future value, annual interest rate, and number of the years as arguments.

  Commercial ids systems

Utilizing the Internet, search for the commercial IDS systems. What are the classification systems and descriptions are used.

  What role each play in failed projects

What character does each of the following play in failed projects.

  Identify the main elements of the us criminal

recognize the key elements of the US criminal justice system and explain how they relate to the job of the computer forensic investigator? Support the opinion or any arguments you may make.

  How important is the internet to most companies

How significent is the Internet to most companies? How have companies improved the sales / service / performance process utilizing the Internet.

  What is the worst-case delay for acknowledging an interrupt

What is the worst-case delay for acknowledging an interrupt

  Linked list based linear search algorithm

Write down an algorithm or the code segment for searching a circular linked list for a given item. Write down a recursive version of the linked list based linear search algorithm.

  Security devices for protection against different attack

Describe two or more attacks for which the routers (layer 3 devices) are vulnerable. Explain how these attacks are detected and prevented by the security devices.

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