troubleshooting Question

How do I cycle through an array in Java pt. 2

Avatar of shenanigans
shenanigans asked on
Java
33 Comments1 Solution302 ViewsLast Modified:
I'm doing the same thing as another poster, but my array is made in the main method
public static void main(String[] args)
 
{
    Cartestadd[] carArray = new Cartestadd[1];
    for (int i = 0; i < carArray.length; i++)
{
	carArray[i] = new Cartestadd();
 
    String stockNumberString = JOptionPane.showInputDialog(" Enter the stock number: ");
    int stockNumber = Integer.parseInt(stockNumberString); //function that converts strng to int
    carArray[i].setStockNumber(stockNumber);
 
     String stockNameString = JOptionPane.showInputDialog(" Enter stock name: ");
     carArray[i].setStockName(stockNameString);
 
 
     String inStockString = JOptionPane.showInputDialog(" Enter number of units in stock: ");
     int inStock = Integer.parseInt(inStockString);
     carArray[i].setInStock(inStock);
 
    String stockPriceString = JOptionPane.showInputDialog(" Enter stock price per unit: ");
    double stockPrice = Double.parseDouble(stockPriceString);
    carArray[i].setStockPrice(stockPrice);
 
 
 
 
}
 
for (int i = 0; i < carArray.length; i++)
   JOptionPane.showMessageDialog(null, carArray[i].toString());
 
int i = 0;
 
JFrame frame = new Inventorytest();
 
 
//JButton jbtOK = new JButton(carArray[i].toString());
//frame.add(jbtOK);
 
frame.setTitle("Inventory program");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
 
 
 
 
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 33 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 33 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros