Question
Programming Assignment 02 Overview We are building on the start made in PA01 to continue building the reporting system for our investment management company. In
Programming Assignment 02
Overview
We are building on the start made in PA01 to continue building the reporting system for our investment management company. In this assignment, you will build a basic framework for the securities management portion of the system.
Startup Materials
The following have been provided to you:
These instructions
UML Class Diagrams for:
o Security
o MutualFund
o Stock
o CostBasis (interface)
A test harness for use in testing your code: Test_SecurityHierarchy.java
Sample expected output results
Requirements
CostBasis - Create the CostBasis interface according to the requirements in the UML. The interface will be used in the classes of the Security hierarchy to calculate the cost basis for a given investment, according to the instructions provided in the individual class diagrams.
Security - Create the Security class according to the requirements in the UML Class Diagram. Note that the UML Class Diagram provided does not include required standard methods these should be included at all times as defaults. Naming for such methods MUST follow standard naming conventions. All classes in the Security hierarchy must implement the CostBasis interface.
MutualFund - Create the MutualFund class according to the requirements in the UML Class Diagram. Note that the UML Class Diagram provided does not include required standard methods these should be included at all times as defaults. Naming for such methods MUST follow standard naming conventions. The MutualFund class must provide concrete instructions for implementation of the CostBasis interface.
Stock - Create the Stock class according to the requirements in the UML Class Diagram. Note that the UML Class Diagram provided does not include required standard methods these should be included at all times as defaults. Naming for such methods MUST follow standard naming conventions. The Stock class must provide concrete instructions for implementation of the CostBasis interface.
/** * This is a SIMPLE test harness for the Security class. * * Keyboard input is accepted from the user and then used to instantiate a Security object. * Once an object has been instantiated, it will be stored in an array. * An enhanced for loop will then be used to output information about all objects in the array. */
import java.util.Scanner; // to accept keboard input
public class Test_SecurityHierarchy { private static int limit = 8; private static Security[] custArray = new Security[ limit ]; // declared globally for simplicity public static void main(String[] args) { loadArray( ); outputSecuritys( ); } // end main private static void loadArray( ) { /************************************************************************************************************ * The first part of this method is simply 'set up' for the real work to be done later. * We will: * > Instantiate the Scanner here to accept keyboard input * > Create a 'holding' space for the Security object(s) to be isntantiated * > Declare variables to hold the user responses * > Declare a variable to use in controlling the input loop ************************************************************************************************************/ Scanner input = new Scanner( System.in ); // instantiate Scanner for use; tie to keyboard Security newSecurity; // "holding reference" for the Security object // Both Stock AND MutualFund objects 'fit' here /* * Create prompts for use in input loop */ // Aks what type of object String askObjType = "Do you wish to enter a Stock (1) or a MutualFund (2) ?: "; // Security-level prompts (for SUPERclass instance values) String askCustNumber = "Enter a Customer Number as 7 digits: "; String askPurchDt = "Enter a purchase date in yyyyddd (Julian) format: "; String askPurchPrc = "Enter the purchase price per share: "; String askShares = "Enter the number of shares purchased: "; String askSymbol = "Enter the symbol for the Security: "; // MutualFund prompts (for SUBclass instance values) String askType = "What type of Mutual Fund is this?: "; String askAdmin = "What is the administrative cost cap? Enter as cents per dollar: "; String askRptPeriod = "What is the reporting Period? Enter A (annual), Q (quarterly), or M (monthly): "; String askMgmt = "Is this fund actively (true) or passively (false) managed?: "; // Stock prompts (for SUBclass instance values) String askExchg = "On which exchange is this Stock traded?: "; String askDividends = "Does this Stock pay dividends? (true or false): "; String askDivDate = "In which quarter are dividends paid? Enter 0 if no dividends: "; String askDivAmount = "What is the expectged dividend per share? Enter 0 if no dividends: "; /* * Declare variables to hold the user responses */ // to hold SUPERclass instance values String custNumber; int purchDt; double purchPrc; double shares; String symbol; //================== // to hold SUBclass instance values String type; double admin; char rptPeriod; boolean mgmt; //================== // to hold SUBclass instance values String exchange; boolean dividends; int divDate; double divAmount; // Declare a variable to test type of object int objType = 0; // Declare a loop control variable int countObjects = 0;
/************************************************************************************************************ * The data input loop will continue until the array has been filled. * * Each prompt is offered in turn; the response from the user is stored in the appropriate variable ************************************************************************************************************/ while( countObjects
for( Security someone: custArray ) { System.out.printf( "%s", someone.toString( ) ); System.out.printf( "The cost basis for this investment is: $%,.2f%n", someone.calcCost( ) ); } } // end outputSecuritys } // end Test_SecurityHierarchy
Security (Abstract) Interface: CostBasis Attributes private custNumber: String private purchDt: int A unique identifier for a customer; must be 7 digits in length; must be greater than 10000 Purchase date of Security in Julian date format: yyyyddd. The value for year must be greater than 1900. The value for days must be between 1 and 365, inclusive Purchase price of Se Number of shares purchased; for display purposed, decimal positions should be limited to three (3) Market symbol of S private purchPrc: double private shares: double private symbol: String r share, in dollars Operations public Security nbr String, Full constructor date: int, price: double, qty: double sym: String ): public toString(): String Returns a formatted String object describing the Security object: The Security belongs to Customer# custNumber, shares shares of symbol were purchased on purchDt for SpurchPrc per share. NOTES: The interface method calcCost is not given a concrete definition here There can be no null constructor defined for this classStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started