(Algebra: quadratic equations) Design a class named QuadraticEquation for a quadratic equation . The class contains:
- Private data fields , and c that represent three coefficients.
- A constructor with the arguments for , and .
- Three getter methods for a, b, and c.
- A method named getDiscriminant () that returns the discriminant, which is .
- The methods named getRoot1 ( ) and getRoot2 () for returning two roots of the equation
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 , and 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 for sample runs.
To start, we're going to make a UML diagram of the class:
The Account class) Design a class named Account that contains:
- A private int data field named 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 , 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 / . Note annualinterestRate is a percentage, for example . You need to divide it by .)
Write a test program that creates an Account object with an account ID of , a balance of , and an annual interest rate of . Use the withdraw method to withdraw , use the deposit method to deposit , and print the balance, the monthly interest, and the date when this account was created.
(Stopwatch) Design a class named StopWatch. The class contains:
- Private data fields startTime and endTime with getter methods.
- A no-arg constructor that initializes startTime with the current time.
- A method named start () that resets the startTime to the current time.
- A method named stop () that sets the endTime to the current time.
- A method named getElapsedTime () that returns the elapsed time for the stopwatch in milliseconds.
Draw the UML diagram for the class then implement the class. Write a test program that measures the execution time of sorting numbers using selection sort.