Note that there are some explanatory texts on larger screens.

plurals
  1. POOOP Java: Creating a stock inventory program
    primarykey
    data
    text
    <p>I am fairly new to object oriented programming, so I am still having some trouble grasping some of the basic concepts. So here I am trying to create a basic inventory program to keep track of stocks. Each stock contains couple details: company name, stock rating (AAA, AAa, Aaa, stuff like that), purchase price and numbers of shares. The program will ask user to input these details through command line prompt. And users can only input at most 12 stocks. If the user enters a stock twice, it will print out an error. And if the user has inputted one stock twice, it will also print out an error message. </p> <p>Here is what I have done so far: Stock object</p> <pre><code> 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; } </code></pre> <p>Now, I am trying to create stock inventory program </p> <pre><code>import java.util.*; public class StockInvetory { private static final int INVENTORY_SIZE = 12; private Stock [] stocks; public StockInvetory() { stocks = new Stock [INVENTORY_SIZE]; } private static void StockInventory() { for (int i = 0; i&lt;INVENTORY_SIZE; i++){ Scanner console = new Scanner(System.in); 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(); stocks [i]= new Stock(stockName, stockRatings, stockPrice, numberShares); } public static void main (String [] args){ StockInventory(); } </code></pre> <p>}</p> <p>So my questions are the following:</p> <p>The first stock object program should be okay, my problem is the stock inventory program. With this code, private Stock [] stocks, does it mean that the stock inventory program will store the info into an array? If it is, how do I store all the details associated with a particular stock, company name, price, etcs together. Do I have to create a multi-dimensional array in order of keep track of all the details? Like one row contains all the details about one stock, and second row contains details about another stock. And to determine if the user has entered one stock twice, do I use "equalsIgnoreCase" to do the comparison? I know I probably need to create another method for the stock Inventory. </p> <p>Thank you very much in advance for your assistance. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload