Handling 8 toggle buttons in a point-of-sale application
Short answer: You need the Java Collections framework.

Instead of eight standalone variables cust1...cust8, you should put them into a Collection so that you can easily iterate through them:

// assuming the buttons are of JButton type
Collection&lt;JButton&gt; buttons = Arrays.asList(cust1, cust2, /* ... */, cust8);
for (JButton button : buttons) {
    if (button.isSelected()) {
        cust = custDAO.getCustById(Integer.getInteger(button.getText()));
        int sales = cust.getTotalSales();
        cust.setTotalSales(sales + subtotal);
        custDAO.updateCustomer(cust);
    }
}


Longer answer...

It is not known how these lines are being run, but you can also consider writing event listeners, which is the typical implementation for checking if buttons have selected. For example, to use an ActionListener:

JButton button = new JButton();
// lambda expression below requires Java 8
button.addActionListener(actionEvent -&gt; {
    JButton source = (JButton) actionEvent.getSource();
    // using valueOf() as getInteger() looks at System.getProperty(),
    // unless that is really the intended usage
    cust = custDAO.getCustById(Integer.valueOf(source.getText()));
    int sales = cust.getTotalSales();
    cust.setTotalSales(sales + subtotal);
    custDAO.updateCustomer(cust);
});


Instead of having cust as a method, or even class, variable, you should scope it appropriately to eliminate any possible mis-references. Also, you can consider adding a more expressive method updateTotalSales(int incoming) that returns the object itself, so that you do not have to perform that 'manually' here:

public Customer {

    // ...

    public Customer updateTotalSales(int incoming) {
        setTotalSales(getTotalSales() + incoming);
        return this;
    }
}




JButton button = new JButton();
button.addActionListener(actionEvent -&gt; {
    JButton source = (JButton) actionEvent.getSource();
    Customer cust = custDAO.getCustById(Integer.valueOf(source.getText()));
    custDAO.updateCustomer(cust.updateTotalSales(subtotal));
});


In the unlikely (?) event that you still prefer/require the original iteration method by checking on isSelected(), the Collection-based implementation, coupled with stream-based processing, can also achieve the same outcome with the following, for simplicity:

// buttons from the short answer
buttons.stream().filter(JButton::isSelected).findFirst()
        .map(i -&gt; custDAO.getCustById(Integer.valueOf(i.getText())))
        .ifPresent(cust -&gt; custDAO.updateCustomer(cust.updateTotalSales(subtotal)));



By using a method reference JButton::isSelected, filter for the JButton where that is true.
Use findFirst() to 'get' it in the form of an Optional wrapper.
From the JButton instance, map() it to the desired Customer object, and finally call custDAO to 'consume' it via the ifPresent(Consumer) method.