Question
In Java The Customer class. The Customer class represents a customer account. The Customer class will have a customer name (first and last), the customer's
In Java
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.
-
getFirstName: takes no input and returns a String that is the first name associated with the account.
-
setFirstName: takes a String as input and returns nothing. Changes the first name associated with the account.
-
getLastName: takes no input and returns String the last name associated with the account.
-
setLastName: takes a String as input and returns nothing. Changes the last name associated with the account.
-
getStock: takes no input and returns a Stock that is the stock associated with this customer.
-
setStock: takes a Stock as input and returns nothing. Changes the stock instance associated with this customer.
-
getSavings: takes no input and returns a Savings that is the savings account associated with this customer. The savings account will not change.
-
getLoan: takes no input and returns a Loan that is the loan associated with this customer. The loan will not change.
-
getCommissionAmount: takes no input and returns a double that is the commission amount for the account.
-
setCommissionAmount: takes a double as input and returns nothing. Changes the commission amount for the account.
-
getDate: takes no input and returns a Date instance.
-
setDate: takes a Date as input and returns nothing. Changes the Date on the account.
-
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.
-
deposit: takes a double as input and returns nothing. Adds the input amount to the savings balance.
-
payLoan: takes a double as input and returns nothing. Reduces the loan balance by the input amount.
-
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?)
-
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.
-
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.
- 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.
Here is the Stock Class
import java.util.Date;
public class Stock {
private String tickerSymbol; private double currentPrice; private Date dividendDate; private double dividendRate; private int currentShares = 0; private double costBasis = 0.0; private double capitalGains = 0.0;
Stock(String tickerSymbol, double currentPrice) { this.tickerSymbol = tickerSymbol; this.currentPrice = currentPrice; this.dividendDate = null; this.dividendRate = 0.0; }
Stock(String tickerSymbol, double currentPrice, Date dividendDate, double dividendRate) { this.tickerSymbol = tickerSymbol; this.currentPrice = currentPrice; this.dividendRate = dividendRate; this.dividendDate = dividendDate;
}
public String getTickerSymbol() { return tickerSymbol; }
public double getCurrentPrice() { return currentPrice; }
public void setCurrentPrice(double price) { this.currentPrice = price;
}
public double getDividendRate() { return dividendRate; }
public void setDividendRate(double rate) { this.dividendRate = rate;
}
public Date getDividendDate() { return dividendDate; }
public void setDividendDate(Date date) { this.dividendDate = date;
}
public int getNumberShares() { return currentShares; }
public double getCostBasis() { return costBasis; }
public double getCapitalGains() { return capitalGains; }
public double payDividend() { return dividendRate * currentShares; }
public double buy(int shares, double commission) { currentShares += shares; costBasis = costBasis + (shares * currentPrice) + commission; return ((shares * currentPrice) + commission); }
public double sell(int shares, double commission) { if (shares > currentShares) return 0; capitalGains += ((shares * currentPrice) - commission) - (costBasis * (shares / currentShares)); costBasis = costBasis - (costBasis * (shares / currentShares));
currentShares -= shares;
return ((shares * currentPrice) - commission); }
public double split(int numerator, int denominator) { if (numerator == 0 || denominator == 0) { return 0.0; } currentShares *= (numerator / denominator); if (currentShares % 1 == 0) { return 0; } else { double sellShares = currentShares % 1; capitalGains += ((sellShares * currentPrice)) - (costBasis * (sellShares / currentShares)); costBasis = costBasis - (costBasis * (sellShares / currentShares)); currentShares -= sellShares; return sellShares * currentPrice; }
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started