CS310 Java Assignment

I am needing help completing this assignment. It is due by midnight

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

 Tuesday, January 23rd,

©RegisUniversity, All Rights Reserved

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

Regis University CC&IS

CS310 Data Structures

Programming Assignment 1: Create class domains in NetBeans and test them

Problem Scenario

A local mutual fund company is in need of a Java programmer to assist them with some of their needs.

Various fund managers in the office take care of multiple stocks in the manager’s fund.

The company needs to be able to track information about their fund managers and their stock trades.

For each FundManager, the office needs to know:

 Broker’s license number (Unique String – three letters followed by five digits)

 Broker’s first name (String)

 Broker’s last name (String)

 Broker’s department number (String of digits and a dash, formatted as “###-###”)

 Broker’s commission rate (double representing a percentage)

The mutual fund company has had issues with incorrect license numbers and department numbers, so they

are requesting a way to be able to determine if the they are correct.

For each StockTrade, the stock broker’s office wants to track:

 Stock symbol (Unique 3 or 4-char string, all uppercased)

 Stock price per share (double)

 Stock number of shares (int) NOTE: Only whole shares can be traded for this program

 Broker’s license number (to match license number in FundManager)

 Whether trade is taxable (boolean)

The mutual fund company has also had issues with incorrect stock symbols, prices, and number of shares,

so they are requesting a way to be able to determine if the they are correct.

Program Requirements

The assignment this week is to create and test some of the classes for the problem scenario above.

These classes will be used to implement data structures in later assignments.

The program must follow the CS310 Coding Standards from Content section 1.9.

To set up a project directory for your program:

o Create a new project in NetBeans, and name it CS310 + last name (e.g. CS310Smith).

o Use the default Main Class name provided by NetBeans (e.g. cs310smith.CS310Smith).
This will cause NetBeans to create a package for your source code files.

o NetBeans will create the default folders for the project.

o NetBeans will create the main method within the main class (e.g. CS310Smith.java)

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

After creating the project, when you view the Files tab, the project structure will look like this:

You will create two additional classes in the same CS310 folder as the

CS310.java file (click on the CS310 folder before selecting New File).

The additional classes are:

 a FundManager class

 a StockTrade class

These classes will be used for creating and manipulating the FundManager and StockTrade objects, and

will not contain a main method. All class attributes/properties/data fields will be encapsulated within the

objects, and therefore will be defined as private.

After you create the FundManager and StockTrade classes, use the tips provided in the NetBeans reader

to generate the following methods for both classes:

constructors, getters, and setters

equals() – must compare ALL attribute values

toString() – must include ALL attribute values

The FundManager and StockTrade classes should include two constructors each:

an empty constructor

a constructor that accepts all of the attributes of the class as parameters

While NetBeans can help you create the basic methods, you will also need to add additional data error

checking methods, as follows:

Error checking methods defined within the FundManager class:

 Check the broker’s license

o contains 3 letters followed by 5 digits within the String.

 Check the department number

o 7 chars long and contains a dash and digits in the correct places, and all of the first three
digits are 1, 2, or 3

Error checking methods defined within the StockTrade class:

 Check the stock symbol

o is 3 or 4 uppercased alphabetic characters long

 Check the stock price

o is not over $1000.00 per share

 Check the number of shares

o is not over 100,000

All of these error checking methods will simply check the proper attribute and return a true or false.

Use appropriate method names that reflect the true case for the returned value.

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

Input Data File

You will use a simple csv file input file for this program (see the online Content for information on how

to read a csv file). The file will contain lines of data about fund managers and stock trades.

This week’s input file, assn1input.txt, will contain only a few data lines, in the following format:

BROKER,ADD/DEL,brokerLicense,firstName,lastName,department,commissionRate

TRADE,BUY/SELL,stockSymbol,sharePrice,numberOfShares,brokerLicense,taxable

NOTE: Taxable will be stored in the data file as Y for yes, or N for no.

Here is an example of a file containing two lines of FundManager data, followed by two lines of

StockTrade data.

Sample Input File Lines
BROKER,ADD,XYZ98765,Jose,Ferguson,321-111,

0.02

BROKER,DEL,ABC12345,Andrea,Smith,123-222,

0.025

TRADE,BUY,MMM,88.88,650,XYZ98765,Y

TRADE,SELL,DGLB,124.44,1022,ABC12345,N

This file will be placed in an input directory within your project (see Deliverables section below for how

to create new directories within your project). Within your code, define a constant to hold this filename,

as follows:
final String INPUT_FILENAME = “input/assn1input.txt”;

Testing

This week, the main method in the CS310Lastname class will be used to test your FundManager and

StockTrade classes. The main method will run 3 sets of tests.

NOTE: Before each test, display a message stating which test is being run.

Also display a blank line between each of the tests.

Test Set 1

The first set of tests will test the constructors with parameters for each attribute and the toString()

method for each class.

Test 1a:

Instantiate a FundManager object by hardcoding argument values of your choice in the call to

the constructor. Then print the attribute values to the console, using the toString() instance

method to

send a message to the object.

Test 1b:

Instantiate a StockTrade object by hardcoding argument values of your choice in the call to the

constructor. Then print the attribute values to the console, using the toString() instance method to

send a message to the object.

Example:
MyClass myObjectName = new MyClass(“abc”, 123, false);

System.out.println( myObjectName.toString() );

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

Test Set 2

The second set of tests will test the equals() methods for both classes.

Test 2a:

 Instantiate a second FundManager object with the same values used for the object created
in test 1a.

 Display a label identifying the object and then use the toString() method to display the
attribute values of the second object.

 Use the equals() method to compare the first and second objects, and display a message
stating whether they are equal or not.

Test 2b:

 Instantiate a third FundManager object that differ from the first two (by at least 1 field
value).

 Display a label identifying the object and then use the toString() method to display the
attribute values of the third object.

 Use the equals() method to compare the first and third objects, and display a message
stating whether they are equal or not.

Test 2c:

 Instantiate a second StockTrade object with the same values used for the object created in
test 1b.

 Display a label identifying the object and then use the toString() method to display the
attribute values of the second object.

 Use the equals() method to compare to compare the first and second objects, and display a
message stating whether they are equal or not.

Test 2d:

 Instantiate a third StockTrade object that differ from the first two (by at least 1 field
value).

 Display a label identifying the object and then use the toString() method to display the
attribute values the third object.

 Use the equals() method to compare to compare the first and third objects, and display a
message stating whether they are equal or not.

Test Set 3

The third set of tests will test the empty constructors, setters and getters, and will also test reading

data from the input data file.

Before running the tests, try to open the input data file.

 Throw an exception of the data file cannot be found.

 The exception handler should display an error message and include the name of the file
that could not be found in the message, and then exit the program with error code 1.

If the file opens successfully, in a loop, read data lines until the end of the file.

For each line read:

 Use split() to parse the line read into an array of String values.

 If the first item on the data line is the String “BROKER”:

Display whether a fund manager is being added or deleted.

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

Instantiate a FundManager object, using the empty constructor.

Call a static setFundManagerAttributes() method. This main class method will:

o Pass in the FundManager object and array of String values as parameters

o Use the setters to set each attribute value

o Return the FundManager object with all attributes set.

Using the returned object, call methods to validate the broker’s license number and

department.

o If either of these items are invalid, use toString() to display the attributes, along
with an error message explaining what is invalid.

o Otherwise, call a static displayFundManagerAttributes() method. This main
class method will:

 Pass in the FundManager object as a parameter.

 Use the getters to display each attribute value, one per line.

 If the first item on the data line is the String “TRADE”:

Display whether a stock is being bought or sold.

Instantiate a StockTrade object, using the empty constructor.

Call a static setStockTradeAttributes() method. This main class method will:

o Pass in the StockTrade object and array of String values as parameters

o Use the setters to set each attribute value

o Return the StockTrade object with all attributes set.

Using the returned object, call methods to validate the stock symbol, stock price, and

number of shares.

o If any of these items are invalid, use toString() to display the attributes, along
with an error message explaining what is invalid.

o Otherwise, call a static displayStockTradeAttributes() method. This main class
method will:

 Pass in the StockTrade object as a parameter.

 Use the getters to display each attribute value, one per line

Close the input data file when you have completed reading the file Test Set 3.

Notes on Validating your Code

In order to validate your code, you will need to run your test code multiple times, each time using

different sets of data. For example:

Run 1: No test data input file in input folder.

Runs 2 – X: In the file data

For the FundManager objects,

one broker’s license is invalid and one department number is invalid.

For the StockTrade objects,

one stock symbol is invalid, one stock price is invalid, and one number of shares

is invalid, and lines contain at least one taxable and one non-taxable trade.

You must supply enough test files to test all possible ways the tests might fail.

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

Sample Output Display

Running Test 1a:

First FundManager object:

FundManager{brokerLicense=AAA11111, firstName=John, lastName=Smith,

dept=313-3333, commissionRate=0.03}

Running Test 1b:

First StockTrade object:

StockTrade{stockSymbol=XXWW, pricePerShare=11.11, wholeShares=33,

brokerLicense=RTA33344, taxable=false}

Running Test 2a:

Second FundManager object:

FundManager{brokerLicense=AAA22222, firstName=John, lastName=Smith,

dept=313-3333, commissionRate=0.03}

First and second FundManager objects are NOT equal

Third FundManager object:

FundManager{brokerLicense=AAA11111, firstName=John, lastName=Smith,
dept=313-3333, commissionRate=0.03}

First and third FundManager objects ARE equal

Running Test 2c:

Second StockTrade object:

StockTrade{stockSymbol=XXWW, pricePerShare=11.11, wholeShares=33,

brokerLicense=RTA33344, taxable=true}

First and second StockTrade objects NOT are equal

Running Test 2d:

Third StockTrade object:

StockTrade{stockSymbol=XXWW, pricePerShare=11.11, wholeShares=33,
brokerLicense=RTA33344, taxable=false}

First and third StockTrade objects ARE equal

Running Test 3:

ADDING BROKER

XYZ98765

Jose

Ferguson

321-111

0.02

DELETING BROKER

ABC12345

Antonia

Smith

123-222

0.025

DELETING BROKER

FundManager{brokerLicense=EEE1234, firstName=Harry, lastName=Houdini,

dept=555-666, commissionRate=0.011}

ERROR: Invalid broker licence number format: EEE1234

SELLING STOCK

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

StockTrade{stockSymbol=XYZ, pricePerShare=9999.0, wholeShares=450,

brokerLicense=ABC12345, taxable=false}

ERROR: Invalid share price: 9999.00

BUYING STOCK

DGLB

124.40

1022

ABC12345

False

Additional Requirements

 Use NetBeans to build comment headers. You are responsible for completing the comment headers
created. Refer to the NetBeans reader on how to use NetBeans to insert your comment headers.

 Add an input folder. To create a new folder in NetBeans:

o Right click on the project name (top level folder).

o On the next dialog box, select New.

o Another dialog box will pop up. Look for “Folder” (the order of the list varies based on what
the last actions you have done). Select Folder.

o When prompted, name the new folder “input”.

Place all test data files that you create to test your program in the input folder of your project, and

name them as follows:
assn1input1.txt

assn1input2.txt (i.e. number each data file after the filename of assn1input.txt)

Together, all of your test data files should demonstrate that you have tested all possible code paths.

 Use the same method as above to add a documentation folder.

o Add screen shots of a clean compile of each of your classes to the documentation folder.

o If you have compile errors, a red error symbol is placed on the file and folder name tabs.
Be sure to clear all compile errors before capturing the screen shot.

o You can paste your image file into the documentation folder, as follows:

 Right click on the documentation folder name, and select Paste.

WARNING: Submittals without the clean compile screenshots will not be accepted.

(This means that programs that do not compile will not be accepted)

Program Submission

This programming assignment is due by midnight of the date listed on the Course Assignments by Week

page of the Content.

You will submit a zip file containing your project files. To submit your project:

 First export your project from NetBeans. To do this:
o Highlight the project name.
o Click on File from the top menu, and select Export Project.
o Select To ZIP

©Regis University, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law

o Name your export file in the following format:
CS310Assn.zip

For example:
CS310SmithAssn1.zip

NOTE: Save this zip file to some other directory, not your project directory.

 Then submit your .zip file to the Prog Assn 1 Submission Folder (located under Assignments tab in
online course).

Warning: Only NetBeans export files will be accepted.

Do not use any other kind of archive or zip utility.

Grading

This program will be graded using the rubric that is linked under Student Resources page.

WARNING:

Programs submitted more than 5 days past the due date will not be accepted,

and will receive a grade of 0.

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER