Starting from:

$30

Homework 2 - Solved

 More on Strings, Classes and UML 

Part 1: The Stock class (edu.albany.hw2.stock)
Design a class named Stock that contains the following:

1.       A Symbol enum field named symbol for the stock’s symbol

2.       A double data field name previousClosingPrice that stores the stock price for the previous day

3.       A double data field named currentPrice that stores the stock price for the current time

4.       A constructor that creates a stock with specified symbol and name

5.       The accessor functions for all data fields

6.       The mutator functions for previousClosingPrice and currentPrice

7.       A function named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice

8.       The Enum “Symbol” – will be used to denote stock for companies

a.       Declare the stock symbols for the following: Microsoft, Apple, Google, Amazon, AT&T

b.       The symbol should have a string value which is the company name

c.       Example Symbol.MSFT represents Microsoft stock.

Draw the UML diagram(s). Implement the classes. Write a test program that creates a Stock object with the stock symbol MSFT and the previous closing stock price of 58.9. Set a new current price to 59 and display the price change percentage. Repeat for one other company.

Part 2: Morse code generator (edu.albany.hw2.morse)
Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes. Figure 1 shows part of the code. Write a program that asks the user to enter a string and then converts that string into Morse code. Use hyphens for dashes and periods for dots.

Some points to consider:

1.       Design: Figure out what classes and methods you need to develop. Ex. Utility classes, class to represent Morse code generator, etc

2.       Architecture: Create a UML of your architecture idea. Make it re-usable and configurable by someone other than yourself

3.       The input can be given in two ways

a.       Command line args

b.       Passed into a function  

4.       Use string buffers when you are (or are going to) manipulating large Strings

5.       Use appropriate accessors for your variables and methods

6.       EXPLAIN: What strategy you used to store the morse code encoding table and WHY? (-10 points if this is missing). Can add it as comment on the class. 

Part 3: Car Instrument Simulator (edu.albany.hw2.car)
For this part, you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are the following:



 


More products