Investments

Investments - R. L. Hendrix CSC 119 -01 February 16, 2011...

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

View Full Document Right Arrow Icon
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 );
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 {
Background image of page 2
private double pricePerShare; private int noSharesOwned; public MutualFunds( String myname, double mypricePerShare, int mynoSharesOwned ) { super( myname ); pricePerShare = mypricePerShare;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/15/2011 for the course CS 119 taught by Professor Jackson during the Fall '10 term at Jackson State.

Page1 / 8

Investments - R. L. Hendrix CSC 119 -01 February 16, 2011...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online