# CSE 1321L:Assignment 6 –Classes solution

\$30.00

Original Work ?

## Description

Program 1: Design (pseudocode) and implement (source code) a class (name it QuadraticEquation) that represents a quadratic equation of the form of ax2+ bx + x = 0.  The class defines the following variables and methods:

1. Private data field a, b, and c that represent three coefficients.
2. A constructor for the arguments for a, b, and c.
3. Three get methods for a, b, and c.
4. Method getDiscriminant()returns the discriminant value, which is disc = b2 – 4ac.
5. Method getRoot1() returns first root if the discriminant is not negative. First root is defined as

R1 = (-b + SquareRoot (disc) ) / 2a

1. Method getRoot2() returns second root if the discriminant is not negative. Second root is defined as

R2 = (-b – SquareRoot (disc) ) / 2a

Note that if the discriminant values is negative, the roots are Undefined.

Write a test program (name it testEquation) to create objects and test the class methods. Organized your output following these sample runs.

Sample run 1 for 3x2+ 8x + 4:

a = 3
b = 8

c = 4

Root 1 = -0.6666666666666666

Root 2 = -2.0

Sample run 2 for 3x2+ 4x + 8:

a = 3
b = 4

c = 8

Root 1 is Undefined

Root 2 is Undefined

Sample run 3 for 2x2+ 8x + 2:

a = 2
b = 8

c = 2

Root 1 = -0.2679491924311228

Root 2 = -3.732050807568877

Program 2: Design (pseudocode) and implement (source code) a class called Counter.  It should have one private instance variable representing the value of the counter.  It should have two instance methods: increment() which adds on to the counter value and getValue()  which returns the current value.

After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head and Tails) to track the number of heads and tails.

Program 3: Design (pseudocode) and implement (source code) a class (name it BankAccount) that defines the following data fields and methods:

1. Private int data field named id to store the account ID (default value is 0).
2. Private double data field named balance to store the account balance (default value is 0.0).
3. Private double data field named annualInterestRate to store the interest rate (default value is 0.0%). Assume all accounts have same interest rate. Annual interest rate is percentage such as 3.2%, thus you need to divide by 100 to get double value 0.032).
4. Private Date data field named dateCreated to store the date when the account was created.
5. Non-argument constructor method that creates a default account (with default values).
6. Constructor method that creates an account with specified ID and initial balance.
7. Get and Set methods for variables id, balance, and annualInterestRate.
8. Get method for variable dateCreated.
9. Method named getMonthlyInterestRate() that returns the monthly interest rate (i.e., annualInterestRate / 12 , formatted as percentage (%)).
10. Method named getMonthlyInterest() that returns the earned monthly interest amount (i.e., balance * monthlyInterestRate, formatted as currency (\$)).
11. Method named withdraw() that withdraws a specific amount from the account.
12. Method named deposit() that deposits a specific amount to the account.
13. Method toString()to printout a meaningful description of an account object using all of its instance variables in the following format:

Account ID:         123456

Account Balance:     \$7,000.00

Interest Rate:      2.50%

Date Opened:         Sun Nov 2 14:18:16 EDT 2017

Now design (pseudocode) and implement (source code) a test program (name it TestBankAccount)to create an account object named myObject as follows:

–  Account ID is 123456;

–  The Initial balance is \$10,000

–  The annual interest rate is 2.5%.

–  Withdraw \$3,500

–  Deposit \$500

–  Print out the account balance

–  Print out the earned monthly interest

–  Print out the date the account was created

Submission:

Part 1: Pseudocode:

1. Review the assignment submission requirements and grading guidelines.
2. Upload the pseudocode files (Word doc or PDF) to the assignment submission folder in D2L.
3. The files must be uploaded to D2L by the due date.
4. The Pseudocode must be complete and following the standards listed at http://ccse.kennesaw.edu/fye/Pseudocode.php

Part 2: Source Code:

1. Review the assignment submission requirements and grading guidelines.
2. Upload the source code files to the assignment submission folder in D2L.
3. The files must be uploaded to D2L by the due date.