Design a class named Stock that contains the following:
A Symbol enum field named symbol for the stocks symbol
A double data field name previousClosingPrice that stores the stock price for the previous day
A double data field named currentPrice that stores the stock price for the current time
A constructor that creates a stock with specified symbol and name
The accessor functions for all data fields
The mutator functions for previousClosingPrice and currentPrice
A function named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice
The Enum Symbol will be used to denote stock for companies
Declare the stock symbols for the following: Microsoft, Apple, Google, Amazon, ATT
The symbol should have a string value which is the company name
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:
Design: Figure out what classes and methods you need to develop. Ex. Utility classes, class to represent Morse code generator, etc
Architecture: Create a UML of your architecture idea. Make it re-usable and configurable by someone other than yourself
The input can be given in two ways
Command line args
Passed into a function
Use string buffers when you are (or are going to) manipulating large Strings
Use appropriate accessors for your variables and methods
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 cars fuel gauge and odometer. The classes you will design are the following:
The FuelGauge class: This class will simulate a fuel gauge. Its responsibilities are as follows:
To know the cars current amount of fuel, in gallons
To report the cars current amount of fuel in gallons
To be able to increment he amount of fuel by 1 gallon. This simulates putting fuel in the car (The car can hold max 15 gallons)
To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons. This simulates burning fuel as the car runs.
The Odometer class: This class will simulate the cars odometer. Its responsibilities are as follows:
To know the cars current mileage
To report the cars current mileage
To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store is 999,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0
To be able to work with a FuelGauge object. It should decrease the FuelGuage objects current amount of fuel by 1 gallon for every 22 miles travelled. (The cars fuel economy is 22 miles per gallon)
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and the run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print the cars current mileage and amount of fuel.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.