Question
Language: Java I will really appreciate it if somebody could help me with this. Thank you! /** * This is a SIMPLE test harness for
Language: Java
I will really appreciate it if somebody could help me with this. Thank you!
/** * 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
Expectedek The following is sample output from the test harness Test_SecurityHierarchy. Your output will depend on the test cases you use. Please keep in mind that multiple, and different, test harnesses will be used when grading your submission - so test thoroughly! Data input complete. Thank you The Mutua!Fund belongs to Customer# 1111111; 25845.000 shares of AAAA were purchased on 2001001 for $1.00 per share This is a MoneyMarket fund Admin costs are capped at 0.001200 Reporting cycle is Monthly The fund is managed passively The cost basis for this investment is: $25,876.01 The Mutua!Fund belongs to Customer# 2222222; 2000.000 shares of BBBB were purchased on 2002002 for $500.00 per share This is a ETF fund Admin costs are capped at 0.00420 Reporting cycle is Annual The fund is managed actively The cost basis for this investment is: $1,004, 200.00 The stock belongs to Customer# 3333333; 100.000 shares of DDDD were purchased on 2003003 for $28.06 per share. This Stock is traded on the NYSE exchange This stock does not pay dividends The cost basis for this investment is: $2,806.00 Expectedek The following is sample output from the test harness Test_SecurityHierarchy. Your output will depend on the test cases you use. Please keep in mind that multiple, and different, test harnesses will be used when grading your submission - so test thoroughly! Data input complete. Thank you The Mutua!Fund belongs to Customer# 1111111; 25845.000 shares of AAAA were purchased on 2001001 for $1.00 per share This is a MoneyMarket fund Admin costs are capped at 0.001200 Reporting cycle is Monthly The fund is managed passively The cost basis for this investment is: $25,876.01 The Mutua!Fund belongs to Customer# 2222222; 2000.000 shares of BBBB were purchased on 2002002 for $500.00 per share This is a ETF fund Admin costs are capped at 0.00420 Reporting cycle is Annual The fund is managed actively The cost basis for this investment is: $1,004, 200.00 The stock belongs to Customer# 3333333; 100.000 shares of DDDD were purchased on 2003003 for $28.06 per share. This Stock is traded on the NYSE exchange This stock does not pay dividends The cost basis for this investment is: $2,806.00
Step 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