-
Stock exchange program
Hey guys. I got great help last time I need help and I would greatly appreciate steps in the right direction and any help/advice you can offer now. I am making a stock exchange program (requirements here: link) and this is what I have got up to now.
I am trying to parse this text file and store the values into portfolio objects(these things hold all the information of one particular fund). I want to store all these objects into an array as well. I am getting a few errors in the class that is parsing the text file.
Code:
import java.util.Scanner;
import java.io.*;
public class Portfolio
{
String name;
String symbol;
double buyingPrice;
double currentPrice;
double floorSellingPrice;
double ceilingSellingPrice;
double profit;
int shares;
enum Type{bond, stock, cash};
Type type;
String info;
public Portfolio(String EXname, String EXsymbol, Type EXtype, double EXbuyingPrice, int EXshares, double EXfloorSellingPrice, double EXceilingSellingPrice, String EXinfo)
{
name = EXname;
symbol = EXsymbol;
type = EXtype;
buyingPrice = EXbuyingPrice;
shares = EXshares;
floorSellingPrice = EXfloorSellingPrice;
ceilingSellingPrice = EXceilingSellingPrice;
info = EXinfo;
}
public Portfolio inputPortfolio(String input)
{
int indexPosition = 0;
int arrLength = 0;
try
{
String fileName = "c://portfolio.txt"; //sets s to value of location of the text file
FileInputStream fi = new FileInputStream(fileName); //creating new file input source object
Scanner scan = new Scanner(fi); //creating file reader object
Portfolio[] arrFundHolder;
try //finding how many objects are in the text file
{
while(scan.hasNextLine())
{
arrLength++;
}
arrFundHolder = new Portfolio[arrLength];
}
catch(Exception e) //catching exception
{
System.out.println(e);
}
arrFundHolder = new Portfolio[arrLength];
while(scan.hasNextLine())
{
String TEMPname = scan.next();
String TEMPsymbol = scan.next();
Type TEMPtype = scan.next();
double TEMPbuyingPrice = scan.nextDouble();
int TEMPshares = scan.nextInt();
double TEMPfloorSellingPrice = scan.nextDouble();
double TEMPceilingSellingPrice = scan.nextDouble();
String TEMPinfo = scan.next();
return new Portfolio(TEMPname,TEMPsymbol,TEMPtype,TEMPbuyingPrice,TEMPshares,TEMPfloorSellingPrice,TEMPceilingSellingPrice,TEMPinfo);
arrFundHolder[indexPostion] = Portfolio();
indexPosition++;
scan.close();
fi.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
/*public double getCurrentPrices()
{
prompt for current prices
}*/
/*public double computerProfit()
{
compute profit for stock and bond funds
}*/
/*public String displayAnalysis()
{
display a sell or hold reccomendation
}*/
}
errors:
Code:
Portfolio.java:61: cannot find symbol
symbol : method nextString()
location: class java.util.Scanner
Type TEMPtype = scan.nextString();
^
Portfolio.java:68: cannot find symbol
symbol : variable indexPostion
location: class Portfolio
arrFundHolder[indexPostion] = Portfolio();
^
Portfolio.java:68: cannot find symbol
symbol : method Portfolio()
location: class Portfolio
arrFundHolder[indexPostion] = Portfolio();
^
3 errors
Thanks guys!
-
Quote:
Originally Posted by
askinne2
errors:
Code:
Portfolio.java:61: cannot find symbol
symbol : method nextString()
location: class java.util.Scanner
Type TEMPtype = scan.nextString();
^
Portfolio.java:68: cannot find symbol
symbol : variable indexPostion
location: class Portfolio
arrFundHolder[indexPostion] = Portfolio();
^
Portfolio.java:68: cannot find symbol
symbol : method Portfolio()
location: class Portfolio
arrFundHolder[indexPostion] = Portfolio();
^
3 errors
The code you posted is not the code that caused the error diagnostic messages, e.g. there is no nextString() method to be seen in your code. We can't help you further than to repeat the compiler on the other error message: the variable 'indexPostion' is never declared in your code.
kind regards,
Jos
-
Thanks for your reply. I have solved all my issues now though so I am good to go!