Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, really need help with the Customer class The Date class. The Date class will represent a date. (Java has both Date and Calendar

In Java, really need help with the Customer class

  1. The Date class. The Date class will represent a date. (Java has both Date and Calendar in the API, but both are more complex than needed for this homework.) A Date contains a day, month, and a year. The Date class should have the following methods:
    1. getDay: takes no input and returns an int that is the day of the date. The day should be a value between 1 and 31.

    2. getMonth: takes no input and returns an int that is the month of the date. The month should be between 1 and 12.

    3. getYear: takes no input and returns an int that is the year of the date.

    4. incrementDay: takes no input and returns nothing. The method adds 1 to the day of the date. If the day exceeds the number of days for the month (assume no leap years), the day is set to 1 and the month is incremented. If the month exceeds 12, the month is set to 1 and the year is incremented.

    5. toString: overrides the toString method inherited from Object so that the string returned is the date in "xx/xx/xxxx" format.

    6. equals: overrides the equals method inherited from Object so that the method returns true if the input is a Date object (our Date, not the API Date) with the same month and day (the year may be different). Otherwise the method returns false.

    The Date class should have one constructor:
    1. It has input int day, int month, int year and initializes the Date object with the given inputs. You may assume that the inputs are all valid values.

  2. The Stock class. The Stock class represents a stock. The Stock class will have a ticker symbol, a current price, a dividend rate, the date the dividend is paid, the number of shares owned, the cost basis of the stock, and the capital gains earned by the stock. The class should have the following methods:

    1. getTickerSymbol: takes no input and returns a String that is the stock market ticker symbol. The ticker symbol will never change.

    2. getCurrentPrice: takes no input and returns a double that is the current price for a share of the stock.

    3. setCurrentPrice: takes a double as input and returns nothing. Changes the current price of a share of the stock.

    4. getDividendRate: takes no input and returns a double that is the dividend rate for the stock.

    5. setDividendRate: takes a double as input and returns nothing. Changes the dividend rate for the stock.

    6. getDividendDate: takes no input and returns a Date that is the dividend date for the stock, or the method returns null if the stock does not pay dividends.

    7. setDividendDate: takes a Date as input and returns nothing. Changes the dividend date for the stock. If the stock does not pay dividends, the dividend date should be null.

    8. getNumberShares: takes no input and returns an int that is the number of shares owned in the stock.

    9. getCostBasis: takes no input and returns a double that is the cost basis for the owned shares.

    10. getCapitalGains: takes no input and returns a double that is the total capital gains earned so far.

    11. payDividend: takes no input and returns a double. Returns the dividend rate multiplied by the number of shares.

    12. buy: takes an int and a double as input and returns a double. The input values are the number of shares being purchased and the commission. Increases the number of shares owned in the stock by the number of shares purchased. Increases the cost basis for the stock by (number of shares purchased x the current price) + commission. Returns the (number of shares purchased x the current price) + commission.

    13. sell: takes an int and a double as input and returns a double. The inputs are the number of shares being sold and the commission. If number of shares being sold is greater than the number currently owned, returns 0 and makes no other changes. Otherwise, the number of shares owned is decreased by number of shares sold. The cost basis is decreased by the ratio of number of shares sold to the number of shares originally owned. (For example, if you sell 1/3 of your shares, the cost basis should decrease by 1/3.) The capital gains is increased by the difference between (number of shares sold x the current price) - commission and the amount that the cost basis decreased. Returns (number of shares sold x the current price) - commission.

    14. split: takes two int values as input and returns a double. The input values are the numerator and the denominator of the split fraction. If either input value is zero, nothing is done and 0 is returned. Otherwise, the number of owned shares changes by the ratio numerator / denominator. (For example, split(2,1) should double the number of shares while split(1,2) should result in one half the number of shares.) If the resulting number of shares contains a fractional share (not a whole number), then the fractional share must be sold so that the final number of shares is a whole number. This is exactly like selling shares normally, except that no commission is charged. The amount returned is the amount of money made from the sale (amount sold times price), and if there is no fractional share because the result of the split is a whole number, then 0 should be returned.

    The Stock class should have two constructors:
    1. One has two inputs: a String (the ticker symbol) and a double (the current price).

    2. One has four inputs: a String (the ticker symbol), a double (the current price), a Date (the dividend date), and a double (the dividend rate).

  3. The Cash class. The Cash class represents an account that deals in money. The Cash class will have a balance, an interest rate, and a record of the amount of interest earned. The class should have the following methods.

    1. getBalance: takes no input and returns a double that is the current balance in the account.

    2. getInterestRate: takes no input and returns a double that is the interest rate.

    3. setInterestRate: takes a double as input and returns nothing. Changes the interest rate.

    4. transfer: takes a double as input and returns nothing. Reduces the current balance by the input amount.

    5. getInterestEarned: takes no input and returns a double that is the amount of interest accrued this month.

    6. processDay: takes no input and returns nothing. If the account balance is positive, multiplies the balance by the interest rate (divided by 365) and adds the amount to the current monthly interest.

    7. processMonth: takes no input and returns nothing. Adds the current monthly interest to the balance and sets the current monthly interest to zero.

    The Cash class should have a single constructor that takes one double (the interest rate) as input.

  4. The Savings class. The Savings class is a Cash class that represents money deposited or earned by the customer. The Savings class has the same properties and behaviors of the Cash class plus the following two additional methods:

    1. deposit: takes a double as input and returns nothing. Increases the balance by the input amount.

    2. withdraw: takes a double as input and returns a boolean. If the input amount is less than or equal to the current balance, reduces the balance by the input amount and returns true. Otherwise returns false and makes no change to the balance.

    The Savings class should have a single constructor that sets the interest rate.
  5. The Loan class. The Loan class is a Cash class the represents money borrowed by the customer. The Loan class has all the same properties and behaviors of the Cash class in addition to the loan limit, the overdraft penalty as well as whether the loan is overdrafted. The class should have all the methods of Cash except the processDay and processMonth will need additional behavior as listed below and there will be four new getter/setter methods to correspond to the additional features of the Loan class:

    1. getLoanLimit: takes no input and returns a double that is the loan limit.

    2. setLoanLimit: takes a double as input and returns nothing. Changes the loan limit .

    3. getOverdraftPenalty: takes no input and returns a double that is the overdraft penalty.

    4. setOverdraftPenalty: takes a double as input and returns nothing. Changes the overdraft penalty.

    5. processDay: takes no input and returns nothing. This method should have the same behavior as in the Cash class plus if the current balance exceeds the loan limit, then the method should record that the loan is overdrafted for this month.
    6. processMonth: takes no input and returns nothing. This method should have the same behavior as in the Cash class plus if the loan was ever overdrafted since the last time processMonth was called, then the overdraft penalty should be added to the balance.

    The Loan class should have a single constructor that takes three double inputs: the interest rate, the loan limit, and the overdraft penalty.

  6. The Customer class. The Customer class represents a customer account. The Customer class will have a customer name (first and last), the customer's stock, the customer's savings, the customer's loan, the commission, and the date. The class should have the following methods.

    1. getFirstName: takes no input and returns a String that is the first name associated with the account.

    2. setFirstName: takes a String as input and returns nothing. Changes the first name associated with the account.

    3. getLastName: takes no input and returns String the last name associated with the account.

    4. setLastName: takes a String as input and returns nothing. Changes the last name associated with the account.

    5. getStock: takes no input and returns a Stock that is the stock associated with this customer.

    6. setStock: takes a Stock as input and returns nothing. Changes the stock instance associated with this customer.

    7. getSavings: takes no input and returns a Savings that is the savings account associated with this customer. The savings account will not change.

    8. getLoan: takes no input and returns a Loan that is the loan associated with this customer. The loan will not change.

    9. getCommissionAmount: takes no input and returns a double that is the commission amount for the account.

    10. setCommissionAmount: takes a double as input and returns nothing. Changes the commission amount for the account.

    11. getDate: takes no input and returns a Date instance.

    12. setDate: takes a Date as input and returns nothing. Changes the Date on the account.

    13. currentValue: takes no input and returns a double that is the Savings balance plus the Stock number of shares times the Stock current price and subtracted by the Loan balance.

    14. deposit: takes a double as input and returns nothing. Adds the input amount to the savings balance.

    15. payLoan: takes a double as input and returns nothing. Reduces the loan balance by the input amount.

    16. withdraw: takes a double as input and returns a boolean. If the input amount is less than or equal to the savings balance, reduces the savings balance by the input amount and returns true. Otherwise returns false and makes no change to the savings balance. (Hint: how much do you need to code?)

    17. sellShares: takes a int and a String as input and returns nothing. The input is the number of shares being sold and the String is the ticker symbol of the stock that is being sold. If the customer's stock's ticker symbol matches that input to this method, then call the stock's sell method with the amount of shares input to this method and the customer's commission amount. The amount returned by the sell method should be added to the customer's savings.

    18. buyShares: takes an int and a String as input and returns a boolean. The inputs are the number of shares to purchase and the ticker symbol of the stock being purchased. If the ticker symbol of the customer's stock matches the input ticker symbol and if the total value of the customer (from the currentValue) method is equal or larger than the amount it would take to purchase the stock ((the number of shares times the stock's price) plus the commission), the stock's buy method is called, the saving balance is reduced by the amount returned from the buy method, and the buyShares method returns true. On the other hand if either the input ticker is not the same as the customer's stock's ticker, or if the cost of the puchase is larger than the customer's current value, the method returns false and no other processing is done.

    19. incrementDate: takes no input and returns nothing. Calls the associated method of the Date class to increment the date. If the date now equals the stock's dividend date, call the payDividend method of the stock and deposit the amount returned into the savings. If the savings balance is negative, transfer that balance to the loan (increasing the balance of the loan), and set the savings balance to zero. Then call the processDay method of both the savings and loan instances. Finally, if the month changed as a result of the increment, call the processMonth method of the savings and loan instances.

    The Customer class should have one constructors that sets the first name, the last name, the commission, the stock, the savings, the loan, and the date of the account.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

If you were Rob Whittier, how would you resolve this dispute?

Answered: 1 week ago