我之前已经问过这个问题并尽可能地遵循反馈,但我仍然在存储用户输入到数组中的信息时遇到问题。
这是第一次尝试: OOP Java:创建库存盘点程序
所以我需要总共三个课程(这是必需的)。库存,库存库存,然后是用户界面。该程序的目的是要求用户输入公司名称、股票评级、价格和股票数量。当然,然后我必须做其他事情。我想我对其余的没问题,问题是 stockInterface,我在下面发布的最后一段代码。
public class Stock {
private String companyName;
private String stockRating;
private int price;
private int numberOfShares;
public String getCompanyName() {
return companyName;
}
public int getStockRating() {
return stockRating;
}
public String getPrice() {
return price;
}
public int getNumberOfShares() {
return numberOfShares;
}
public Stock(String companyName, String stockRating, int price, int numberOfShares) {
super();
this.companyName = companyName;
this.stockRating = stockRating;
this.price = price;
this.numberOfShares = numberOfShares;
}
import java.util.*;
public class StockInvetory {
private static final int INVENTORY_SIZE = 12;
private Stock [] stocks;
public StockInvetory() {
stocks = new Stock [INVENTORY_SIZE];
}
public class StockInterface() {
private static StockInventory stockPortfolio;
public static void main (String [] args){
System.out.println ("Stock's name:");
String stockName = console.next();
System.out.println ("Stock's rating");
String stockRating= console.next();
System.out.println ("Stock's price:");
int stockPrice = console.nextInt();
System.out.println ("Numbers of shares: ");
int numberShares= console.nextInt();
stockPortfolio [0]= new Stock(stockName, stockRatings, stockPrice, numberShares);
}
这段代码不起作用。
stockPortfolio [0]= new Stock(stockName, stockRatings, stockPrice, numberShares)
有人可以告诉我将信息存储到数组中的正确方法吗?非常感谢。