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

  Minimum size of instruction

An imaginary computer has the 16 data registers (R0 to R3), 1024 words in memory, and the 16 different instructions (add, subtract, etc.). Explain the minimum size of the instruction in bits.

  Dns servers and dhcp servers

Assume that both the DNS servers and the DHCP servers send your client PC and IP addresses. Write down the differences between these two addresses.

  How many address lines are needed to access memory

How many address lines are needed to access memory.

  Efficiency of variable n using big-o notation

Classify its efficiency in terms of the variable N utilizing the big-O notation. Also, suppose that statements represented by the ellipsis need four chief memory accesses with each access requiring 1 microsecond.

  Problems on relation and functional dependencies

Problems on  relation and functional dependencies

  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..

  Sense making in health care organizations

Evaluate the most suitable way that the “sense making” may be applied to the health care organizations. Give the specific examples in order to support your response.

  Benefit and drawback of each major operating system

Benefit and drawback of each major operating system

  You are a network support technician for a college

explain why each step is necessary. Suppose that your troubleshooting methodology leads you to determine that the problems was caused by a malfunctioning gateway. Suggest ways in which the problem could have been prevented.

  Linux advanced server vs windows 2003 server

Please give me 10 topic examples that I can select to write about in my class assignment. The example must be able to cover the directions that are listed below.

  Distinguish between erp and scm software

Distinguish between ERP and SCM software. In what ways do they complement each other? Discuss the need for, and ways to integrate, these products with other types of enterprise systems.

  Generate queries for new database

Generate Queries for New Database

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