{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Investments

# Investments - R L Hendrix CSC 119-01 Program#3 Algorithm...

This preview shows pages 1–4. Sign up to view the full content.

R. L. Hendrix CSC 119 -01 February 16, 2011 Program #3 Algorithm used to solve: I used Inheritance to do this program as well as get and set methods and override. Data used to test: public abstract class Investment { protected String name; public Investment( String myname ) { name = myname; } public void setName( String myname ) { name = myname; } public String getName() { return name; } public abstract double getValue(); @Override public String toString() { return String.format( "Name: %s\n\$%.2f", name, getValue() ); } } public class Stocks extends Investment { private double pricePerShare; private int noSharesOwned; private double dividend; public Stocks( String myname, double mypricePerShare, int mynoSharesOwned, double mydividend ) { super( myname );

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
pricePerShare = mypricePerShare; noSharesOwned = mynoSharesOwned; dividend = mydividend; } public void setPricePerShare( double mypricePerShare ) { pricePerShare = mypricePerShare; } public double getPricePerShare() { return pricePerShare; } public void setNoSharesOwned( int mynoSharesOwned ) { noSharesOwned = mynoSharesOwned; } public int getNoSharesOwned() { return noSharesOwned; } public void setDividend( double mydividend ) { dividend = mydividend; } public double getDividend() { return dividend; } @Override public double getValue() { return dividend * ( pricePerShare * noSharesOwned ); } @Override public String toString() { return String.format( "Name: %s\nPrice per Share: \$%.2f # of Shares Owned: %d Dividend: \$%.2f\nValue: \$%.2f", name, pricePerShare, noSharesOwned, dividend, getValue() ); } } public class MutualFunds extends Investment {
private double pricePerShare; private int noSharesOwned; public MutualFunds( String myname, double mypricePerShare, int mynoSharesOwned ) { super( myname ); pricePerShare = mypricePerShare;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

Investments - R L Hendrix CSC 119-01 Program#3 Algorithm...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online