Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 08:32 PM
Member
 
Join Date: Nov 2007
Posts: 4
Alex89 is on a distinguished road
Stocks.
I am pretty new to java and have just started getting back into it. I have to create a program that tests stocks, but I do not know how to even begin starting. Any help would be greatly appreciated.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 09:25 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
We'll need some more information about this. What is a stock and how do you want to test it?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2007, 09:30 PM
Member
 
Join Date: Nov 2007
Posts: 4
Alex89 is on a distinguished road
I hav to create a class named Stock to model a stock on the stock market. The properties and methods of the class are shown below. The method changePercent computes the percentage of the change between the current price and the previous closing price.

2. Write a client program to test the stock class. In the client program, create a Stock object and test it.


Stock UML

-symbol: string
-name: string
-previousClosingPrice: double
-currentPrice: double

+Stock()
+Stock(symbol:String, name:String)
+getSymbol():String
+getName() :String
+getPreviousClosingPrice(): double
+getCurrentPrice(): Double
+setSymbol(symbol: String): void
+setName(name: String): void
+setPreviousClosingPrice(price: double):void
+setCurrentPrice(price: double): void
+changePercentage(): double

I hope this helps.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2007, 10:02 PM
Member
 
Join Date: Nov 2007
Posts: 4
Alex89 is on a distinguished road
I have created the class for my stock now I need to create a client program to test my class. I need help with the client program.



This is my class for the stock.

public class Stock {

private string symbol;
private string name;
private double previousClosingPrice;
private double currentPrice;

public stock ()
{

symbol = "";
name = "";
previousClosingPrice = 0.0;
currentPrice = 0.0;
}
public stock (String symbola, String namea)
{
this.symbol = symbola;
this.name = namea;
previousClosingPrice = 0.0;
currentPrice = 0.0;
}
public String getSymbol ()
{
return symbol;
}
public String getName ()
{
return name;
}
public double getPreviousClosingPrice () { return previousClosingPrice;}
public double getCurrentPrice () { return currentPrice;}

public void setSymbol (String symbol)
{
this.symbol = Symbol;
}
public void setName (String name) { this.name = Name;}
public void setPreviousClosingPrice (double cost)
{
this.previousClosingPrice = cost;
}
public void setCurrentPrice (double morecost ) {this.currentPrice = morecost}

public double changePercentage ()
{
return currentPrice/previousClosingPrice;
}
}
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-03-2007, 11:18 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
public class StockTest { public static void main(String[] args) { Stock stock = new Stock(); // Call methods in the stock instance // to test/exercise your Stock class. stock.setPreviousClosingPrice(5.00); stock.setCurrentPrice(3.00); // ... Stock stock2 = new Stock("GV", "Google"); // Test stock2... } } class Stock { private String symbol; private String name; private double previousClosingPrice; private double currentPrice; public Stock() { this("", ""); } public Stock(String symbola, String namea) { this.symbol = symbola; this.name = namea; previousClosingPrice = 0.0; currentPrice = 0.0; } public String getSymbol() { return symbol; } public String getName() { return name; } public double getPreviousClosingPrice() { return previousClosingPrice; } public double getCurrentPrice() { return currentPrice; } public void setSymbol(String symbol) { // this.memberVariable = localVariable // "this" refers to the enclosing class, ie, Stock this.symbol = symbol; } public void setName(String name) { this.name = name; } public void setPreviousClosingPrice(double price) { this.previousClosingPrice = price; } public void setCurrentPrice(double price) { this.currentPrice = price; } public double changePercentage() { return currentPrice/previousClosingPrice; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 05:56 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org