Question

(Algebra: quadratic equations) Design a class named QuadraticEquation for a quadratic equation ax2+bx+c0a x^2+b x+c-0. The class contains:

  • Private data fields a,ba, b, and c that represent three coefficients.
  • A constructor with the arguments for a,ba, b, and cc.
  • Three getter methods for a, b, and c.
  • A method named getDiscriminant () that returns the discriminant, which is b24acb^2-4 a c.
  • The methods named getRoot1 ( ) and getRoot2 () for returning two roots of the equation

r1=b+b24ac2a and r2=bb24ac2ar_1=\frac{-b+\sqrt{b^2-4 a c}}{2 a} \text { and } \quad r_2=\frac{-b-\sqrt{b^2-4 a c}}{2 a}

These methods are useful only if the discriminant is nonnegative. Let these methods return 0 if the discriminant is negative.

Draw the UML diagram for the class then implement the class. Write a test program that prompts the user to enter values for a,ba, b, and cc and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0 , display the one root. Otherwise, display "The equation has no roots." See Programming Exercise 3.13.1 for sample runs.

Solution

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 10

To start, we're going to make a UML diagram of the class:

'slader'

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Related questions

computer science

The Account class) Design a class named Account that contains:

  • A private int data field named idid for the account (default 0 ).
  • A private double data field named balance for the account (default 0 ).
  • A private double data field named annualinterestRate that stores the current interest rate (default 0 ). Assume that all accounts have the same interest rate.
  • A private Date data field named datecreated that stores the date when the account was created.
  • A no-arg constructor that creates a default account.
  • A constructor that creates an account with the specified id and initial balance.
  • The accessor and mutator methods for id\mathrm{id}, balance, and annua InterestRate.
  • The accessor method for dateCreated.
  • A method named getMonth1yInterestRate () that returns the monthly interest rate.
  • A method named getMonth1yInterest() that returns the monthly interest. A method named withdraw that withdraws a specified amount from the account.
  • A method named deposit that deposits a specified amount to the account. Draw the UML diagram for the class then implement the class. (Hint: The method getMonthlyInterest () is to return monthly interest, not the interest rate. Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is annualinterestRate / 1212. Note annualinterestRate is a percentage, for example 4.5%4.5 \%. You need to divide it by 100100.)

Write a test program that creates an Account object with an account ID of 11221122 , a balance of $20,000\$ 20,000, and an annual interest rate of 4.5%4.5 \%. Use the withdraw method to withdraw $2,500\$ 2,500, use the deposit method to deposit $3,000\$ 3,000, and print the balance, the monthly interest, and the date when this account was created.