COM 204 ASSIGNMENT 7 ASSIGNMENT 2 MODULE 7.docx - COM-204-OL01 Professor 06\/2019 Assignment 7 Chapter 10 Exercise 6 A Design a class named

COM 204 ASSIGNMENT 7 ASSIGNMENT 2 MODULE 7.docx -...

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

COM-204-OL01 Professor 06/2019 Assignment 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. Pseudocode: start Declarations
Image of page 1
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 15 StockTransaction objects. Prompt the user for data for each object, and then display all the values. Pseudocode: start Declarations num SIZE=15 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 15 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. start Declarations
Image of page 2
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()
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 16 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes