Question: Please make sure the code works and bout exercises 2 and 3 are complete. I have attached the code needed for them. Thanks Exercise 2-
Exercise 2- st bealidating Stock Information Using Mutators (3 points) ed duringt during the lab period a copy of files for Exercise 1 into a new folder for Exercise 2. strategy to validate user inputs is to test the attribute value in its corresponding method. Us mutator valid, save the new value in the appropriate attribute and return a value of true. If the tor method. Use the rules for valid data from Exercise 1. if the value of the attribute is Enter nane of stocki Apple y value is invalid, do NOT change of false. Do not print an errort e methodl Modify the muta ta jiut jua truastece the attribute and return a valueten ta message in the mutator for price and number of sharesaet yres d seaese Enter price of steck: 530-48 as described above. of shares Must be 18 and 1te0 inclusively and a nultiple of u 12. However, there are no stock: Apsle mutators for name and symbol Entr price af stock: $a.4 as they are set in the constructor. While a constructor can contain if statements, there is no return enevayEa jias value. Enter nunber of shares: 28 Same: Apple Symbol: APPL 13. Add a default constructor to the Stock class. Set the value of the name and symbol to the empty String. 14. Add mutators for the name and symbol using the rules for valid data from Exercise 1. 15. Modify the code in the main method in the TradeStock class to use the default constructor to create an empty object. 16. Then use the mutators to validate the user-entered data. Test the return value to determine if the user input is valid. If the return value is false, print the same error messages as in Exercise 1 and terminate the program. 17. The output of the program should be exactly the same as Exercise 1. Remember to test the program thoroughly with valid and invalid data. Have instructor or TA sign here when Exercise 2 works correctly
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
