CSE 500 – Fall 2004

PROGRAMMING HW3


This programming assignment requires you to write code in 1 class as described below. It should be sent via email to your instructor before the due date. Programs that do not compile cannot be graded.


ATTENTION: Any changes made to this document from the original posting are denoted in blue.


The Robust Market Cap Calculator

INTRODUCTION

At the end of trading at the New York Stock Exchange on Friday, January 30th, a share of Microsoft (ticker symbol MSFT) stock was priced at $27.65 while a share of IBM (ticker symbol IBM) stock was priced at $99.22, but Microsoft is a much larger company than IBM, so what do these numbers mean? Well, to understand them, we have to understand a few terms:

·        Ticker Symbol – An abbreviation of a company name used when listing stock prices. These symbols must be one to five characters in length and made-up of letters only. No numbers or symbols are permitted as part of this symbol.

·        Shares Outstanding – “The number of authorized shares in a company that are held by investors, including employees and executives of that company.” In other words, it is the number of pieces that public ownership of a company is divided.

·        Market Cap – The total market value of the company. This can be calculated by multiplying the stock price by the number of shares outstanding. So, for example, for IBM & Microsoft:

StockPriceMicrosoft = $27.65/share

SharesOutstandingMicrosoft = 10,812,470,000 shares

MarketCapMicrosoft = 27.65 * 10,812,470,000

                                  = $298,964,795,500.00

                                  = $298.965 billion

StockPriceIBM = $99.23/share

SharesOutstandingIBM = 1,720,423,000 shares

MarketCapIBM = 99.23 * 1,720,423,000

                                  = $170,717,574,290.00

                                  = $170.716 billion

As we see above, Microsoft Corp is worth $120 billion more than IBM, though IBM has the higher individual stock price. In this assignment, your program will prompt the user for information about two different companies on the NYSE. It will then calculate the market cap for each company and state which one is larger.

NOTE:            The term robust is a buzzword that software industry companies commonly use to market their products. Basically it means it is immune to user error. So, when I say I want your programs to be robust, it means that if the user (you or myself) enters improper input, your program should not produce a runtime error and crash. In fact, there should be no reason for runtime errors in your programs. Before launching a new software product, it has to be poked and prodded in all sorts of ways to make sure it will work properly. Software that is particularly robust anticipates the various garbage input that may occur, and handles it such that rather than simply produce garbage output, or have the program crash, it deals with it such that the program may continue unscathed. Good coders get used to coding in this fashion.

 

CODING

Define a class named RobustMarketCapCalculator such that it does the following:

·        Provides a Graphical User Interface that prompts the user for information about 2 companies. Including:

o       Stock Ticker Symbol

o       Price Per Share in Dollars (real number)

o       Shares Outstanding (whole number)

You will have to create a JFrame and place components inside of it. For collecting data, you will probably want to use JTextFields. You may then have a JButton that would submit the data. In addition, you’ll want a JTextArea for presenting the results.

NOTE:            Should the user enter improper information, for example, a word instead of a number, or a real number instead of an integer, your program should inform the user of his/her error (use JOptionPane methods) and your program should continue.

NOTE:            You do not have to check to make sure that the stock ticker symbol entered is for an actual company, but you must make sure it conforms to the requirements of a ticker symbol (1-5 characters in length & all letters).

After getting user data, your program should do the following:

·        Calculates the market cap of each company.

·        Display the market cap of each company as a whole number in abbreviated form, meaning no commas (‘,’) are necessary. For example “$299 billion”, or “$89 million” (only worry about companies with market caps in the billions & millions).

·        State which company has the greater market cap value.

 

EXAMPLE  DISPLAY for your JTextArea:

MSFT beats IBM in market cap

        MSFT's market cap is $298 billion

        IBM's market cap is $170 billion