Question: Code in Java. Code Methods DO NOT code the methods in any way other than what is instructed. Values that are returned by methods, and
Code in Java.
Code Methods DO NOT code the methods in any way other than what is instructed.
Values that are returned by methods, and used multiple times in the method that calls for the value, should be stored in local variables.
Variables used in more than one method should be class-level (fields). There are 7 class-level (fields) variables. The remaining variables are either local to the main() or some of the other methods in which they are used for processing. There are 4 variables in the main().
c. main(): The logical control structures remain in this method. The other methods are called by the main(). The methods are called in the order of the code that they replace in the main(). These methods contain the code that was originally in the main() (similar to DemoVoidMethods that was recoded into DemoValRecValRetMethods during lecture).
setCustName(): Prompt 1. Assign user entry to field.
login(): Prompt 2 and returns from the keyboard. It will be called by the main() in the
test expression that uses the login variable, so you no longer need a login variable.
password(): Prompt 3 and returns from the keyboard. It will be called by the main() in
the test expression that uses the password variable, so you no longer need a password
variable.
setShares(): Prompt 5, validate the input as an integer (refer to TestValidInput coded
during lecture) before returning from the keyboard.
setSharePrice(): Prompt 6, validate the input as a double (refer to TestValidInput coded
during lecture) before returning from the keyboard.
onlineTrade(): Prompt 7 and returns form the keyboard. It will be called by the main() in
the test expression that uses the onlineTrade variable, so you no longer need an
onlineTrade variable.
onlineFees(): Adds the onlineFee to totalOnlineFees and totalCost. onlineFee variable
scoped to this method.
brokerTrade(): Prompt 8 and returns form the keyboard. It will be called by the main()
in the test expression that uses the brokerTrade variable, so you no longer need a
brokerTrade variable.
commissions(): Receives stockCost and calculates the commission, totalCommissions
and totalCost. commission variable scoped to this method.
m. displayStockInfo(): Prints the final output. Scope variables associated with the date to
this method.
***OUTPUT WITH 2 UNSUCCESSFUL LOG-IN ATTEMPTS*** NOT PART OF OUTPUT YEE-TRADE, INC. - The Wild West of Electronic Trading Welcome to Yee-Trade's stock purchase calculator. What is your name? Hawkeye Pierce
Enter your log-in: Biff2008
Enter your password: Buffy2011
Invalid log-in or password! 1 attempt left.
Enter your log-in: LastChance
Enter your password: BetterWork
No more attempts left! Contact technical support at 1-800-111-2222.
Thank you for using Yee-Trade's stock purchase calculator!
***OUTPUT WITH CORRECT LOG-IN: EXCEPT FOR LOG-IN, AND INPUT VALIDATION*** NOT PART OF OUTPUT
YEE-TRADE, INC. - The Wild West of Electronic Trading Welcome to Yee-Trade's stock purchase calculator. What is your name? Hawkeye Pierce Enter your log-in: Buffett2011
Enter your password: Rank1Bill2008 Invalid log-in or password! 1 attempt left. Enter your log-in: Buffet2011 Enter your password: Rank1Bill2008 Do you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: y How many shares did you purchase? l000
You must only enter an integer for the number of shares: 1000 What is the price per share? 1t
You must only enter a double for the share price: 15 Is this an online trade? Enter 'Y' or 'N': y
Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: y How many shares did you purchase? 500 What is the price per share? 52 Is this an online trade? Enter 'Y' or 'N': n
Is this a broker assisted trade? Enter 'Y' or 'N': y Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: y How many shares did you purchase? 50 What is the price per share? 52 Is this an online trade? Enter 'Y' or 'N': n Is this a broker assisted trade? Enter 'Y' or 'N': n INVALID TRADE TYPE! Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: n
YEE-TRADE, INC. TOTAL COST OF STOCK PURCHASES FOR Hawkeye Pierce AS OF OCTOBER 18, 2018
Total Stock Cost: $41,000.00 Total Online Fees: $5.95 Total Commissions: $520.00
TOTAL COST: $41,525.95 Thank you for using Yee-Trade's stock purchase calculator!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
