nathan rivera nathan rivera - 2 months ago 17
Java Question

Java <Identifier> expected for method

getting started on a homework assignment where I'm required to use set/get methods. I have started writing the script however I run into a "identifier expected" error. I'm probably doing this very wrong. Any suggestions?

public class Stock {

private String stockName;
private int quantity;
private double purchasePrice;
private double currentPrice;

public Stock(stockName, quantity, purchasePrice,currentPrice)
{

}
}


The public Stock methods is what is causing the error.

Answer

You are missing types for the arguments in your constructor.

public Stock(String stockName, int quantity, 
            double purchasePrice, double currentPrice) {
    this.stockName = stockName;
    this.quantity = quantity;
    this.purchasePrice = purchasePrice;
    this.currentPrice = currentPrice;
}
Comments