nathan rivera nathan rivera - 1 year ago 127
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 Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download