Module 7 Com 204.docx - COM 204 Module 7 Chapter 10...

This preview shows page 1 - 3 out of 16 pages.

COM 204 Module 7 Chapter 10 Exercise 6 A. Design a class named StockTransaction that holds a stock symbol (typically one to four characters), stock name, and price per share. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. public class StockTransaction( String stock_symbol; String stock_name; int price_per_share; Pseudocode: Declarations private string stockSymbol private string stockName private num perShareRate public void setStockSymbol(string symbol) stockSymbol-symbol if symbol.length>3 stockSymbol=symbol.subString(0,3) endif return public void setStockName(string name) perShareRate=rate return public string getStockSymbol() return stocksymbol public string getStockName() return stockName public num getPricePerShare() return pricePerShare End B. Design an application that declares two StockTransaction objects and sets and displays their values.
Image of page 1

Subscribe to view the full document.

Pseudocode: start Declarations Stock Transactions stock1 Stock Transactions stock2 stock1.setStockSymbol(“MON”) stock1.setStockName(“Inside Money”) stock1.setPricePerShare(243.56) stock2.setStockName(“Interest Money”) stock2.setPricePerShare(523.36) output “Stock 1 Details:” output “Stock Symbol : “, stock1.getStockSymbol() output “Stock Name : “, stock1.getStockName() output “Price per share : “, stock1.getPricePerShare() output “Stock 2 Details:” output “Stock Symbol : “, stock2.getStockSymbol() output “Stock Name : “, stock2.getStockName() output “Price per share : “, stock2.getPricePerShare() stop C. Design an application that declares an array of 10 StockTransaction objects. Prompt the user for data for each object, and then display all the values. Pseudocode: start Declarations num SIZE=10 StockTransaction stocks [10] num sub sub=0 while sub stocks[sub]=getDetails() sub=sub+1 endwhile displayAllDetails( stocks, SIZE) stop public static StockTransaction getDetails() Declarations Stock Transactions num sharePrice string stockName string stockSymbol output “Enter Stock Symbol…” input stockSymbol D. Design an application that declares an array of 10 StockTransaction objects. Prompt the user for data for each object, and then pass the array to a method that determines and displays the two stocks with the highest and lowest price per share.
Image of page 2
start Declarations num SIZE=10 Stock Transaction stocks[10] num sub sub =0 while sub stocks[sub]=getDetails() sub=sub +1 endwhile printHighLowStocks(stocks,SIZE) stop public static StockTransction getDetails() Declarations Stock Transactions num sharePrice string stockName string stockSymbol output “Enter Stock Symbol…” input stockSymbol output “Enter Stock Name..” input stockName output “Enter per share price…” input sharePrice s.setStockSymbol(stockSymbol) s.setStockName(stockName) s.setPricePerShare(sharePrice) return s public static void printHighLowStocks(StockTransaction[]stocks, num SIZE) Declarations num rate num min num max num minR num maxR num sub sub=1 min=0 max=0 minR=stocks[0].getPricePerShare() maxR=stocks[0].getPricePerShare()
Image of page 3
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern