How abstract class works?

hello, every!
i can't quite understand the abstract class.
can a abstract class be inherited by a class in different package?
thanks!

you means define the class like this:
public abtract class ClassA{
a class can be define as public and abtract at the
same time??Yes, certainly. Why don't you try it yourself?you are right.
thanks.

Similar Messages

  • Getting an abstract class working

    Simply put, something is going wrong with my abstract class, now my assignArray method wont work and my frame wont compile at all anymore.
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    public abstract class bankPresentation extends JFrame implements ActionListener {
         //define the frame properties
         private static final int FRAME_WIDTH = 300;
         private static final int FRAME_HEIGHT = 600;
         private static final int FRAME_X_ORIGIN = 150;
         private static final int FRAME_Y_ORIGIN = 250;
         private static final int BUTTON_WIDTH = 80;
         private static final int BUTTON_HEIGHT = 30;
         //define all the frame elements
         JRadioButton depositRadioButton = new JRadioButton("Deposit");
         JRadioButton withdrawRadioButton = new JRadioButton("Withdraw");
         ButtonGroup bankButtonGroup = new ButtonGroup();
         JLabel amountLabel;
         JTextField amountField;
         JTextArea textArea;
         JScrollPane textBoxScroll;
         JButton newAccountButton;
         JButton summaryButton;
         JButton depositWithdrawButton;
         double initialAmountDouble;
         DecimalFormat formatDecimal = new DecimalFormat("$0.00");
         //create a new array, size is 10
         bankSummary customerList[] = new bankSummary[10];
         public static void main(String[] args) {
              bankPresentation frame = new bankPresentation();
              frame.setVisible(true);
         public bankPresentation() {
              Container contentPane;
              //create the deposit and withdraw radio buttons, put them in a group
              //and add them to the frame
              bankButtonGroup.add(depositRadioButton);
              bankButtonGroup.add(withdrawRadioButton);
              setSize(FRAME_WIDTH, FRAME_HEIGHT);
              setResizable(false);
              setTitle("Ch13 Project");
              setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
              contentPane = getContentPane();
              contentPane.setLayout(new FlowLayout());
              contentPane.add(withdrawRadioButton);
              contentPane.add(depositRadioButton);
              //add a large text area to the pane
              textArea = new JTextArea();
              textArea.setColumns(25);
              textArea.setRows(20);
              textArea.setLineWrap(true);
              textBoxScroll = new JScrollPane(textArea);
              textBoxScroll
                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              textArea.setBorder(BorderFactory.createLineBorder(Color.RED));
              // Set to non edit
              textArea.setEditable(false);
              contentPane.add(textBoxScroll);
              //create new buttons to create accounts, deposit/withdraw with existing ones, and
              //get a statement with existing ones
              newAccountButton = new JButton("Create Account");
              newAccountButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(newAccountButton);
              summaryButton = new JButton("Summary");
              summaryButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(summaryButton);
              depositWithdrawButton = new JButton("Deposit/Withdraw");
              depositWithdrawButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
              contentPane.add(depositWithdrawButton);
              //add actionlisteners to all buttons
              summaryButton.addActionListener(this);
              newAccountButton.addActionListener(this);
              depositRadioButton.addActionListener(this);
              withdrawRadioButton.addActionListener(this);
              depositWithdrawButton.addActionListener(this);
              //initialize the array with some existing accounts
              assignArray();
          abstract void assignArray() {
              for (int i = 0; i < customerList.length; i++) {
                   customerList[i] = new bankSummary();
              customerList[0].setValues("Bob", "Ghost", "1234", "Savings", 500);
              customerList[1].setValues("Joe", "Shmo", "1333", "Checking", 600);
              customerList[2].setValues("Jack", "Biggs", "9023", "Savings", 200);
         public void actionPerformed(ActionEvent event) {
              int arrayIndexInt = 3;
              // Determine source of event
              Object sourceObject = event.getSource();
              //if a new account is created, ask for first name, last name, pin number, and whether it
              //be a checking or savings account, and the initial amount you're depositing
              if (sourceObject == newAccountButton) {
                   String fNameString = JOptionPane.showInputDialog("First Name: ");
                   String lNameString = JOptionPane.showInputDialog("Last Name: ");
                   String pinString = JOptionPane
                             .showInputDialog("Desired Pin Number: ");
                   String accountType = JOptionPane
                             .showInputDialog("Checking or Savings Account? Enter (Checking or Savings)");
                   String initialAmountStr = JOptionPane
                             .showInputDialog("Initial Deposit Amount: ");
                   double initialAmountDouble = Double.parseDouble(initialAmountStr);
                   customerList[arrayIndexInt].setValues(fNameString, lNameString,
                             pinString, accountType, initialAmountDouble);
                   arrayIndexInt += 1;
                   JOptionPane.showMessageDialog(null, "Account Created!");
              //if the summary button is pressed, ask for the first name on the account
              //then ask for the pin, display the balance for that said account
              if (sourceObject == summaryButton) {
                   String nameVerifyStr = JOptionPane
                             .showInputDialog("Firstname on Account: ");
                   String pinVerifyStr = JOptionPane.showInputDialog("Pin Number: ");
                   if (nameVerifyStr.equals(customerList[0].getFirstName())
                             && pinVerifyStr.equals(customerList[0].getPin())) {
                        textArea.append("Customer: " + customerList[0].getFirstName()
                                  + " " + customerList[0].getLastName() + "\nAccount: "
                                  + customerList[0].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[0].getBalance()));
                   if (nameVerifyStr.equals(customerList[1].getFirstName())
                             && pinVerifyStr.equals(customerList[1].getPin())) {
                        textArea.append("Customer: " + customerList[1].getFirstName()
                                  + " " + customerList[1].getLastName() + "\nAccount: "
                                  + customerList[1].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[1].getBalance()));
                   if (nameVerifyStr.equals(customerList[2].getFirstName())
                             && pinVerifyStr.equals(customerList[2].getPin())) {
                        textArea.append("Customer: " + customerList[2].getFirstName()
                                  + " " + customerList[2].getLastName() + "\nAccount: "
                                  + customerList[2].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[2].getBalance()));
                   if (nameVerifyStr.equals(customerList[3].getFirstName())
                             && pinVerifyStr.equals(customerList[3].getPin())) {
                        textArea.append("Customer: " + customerList[3].getFirstName()
                                  + " " + customerList[3].getLastName() + "\nAccount: "
                                  + customerList[3].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[3].getBalance()));
                   if (nameVerifyStr.equals(customerList[4].getFirstName())
                             && pinVerifyStr.equals(customerList[4].getPin())) {
                        textArea.append("\nCustomer: " + customerList[4].getFirstName()
                                  + " " + customerList[4].getLastName() + "\nAccount: "
                                  + customerList[4].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[4].getBalance()));
                   if (nameVerifyStr.equals(customerList[5].getFirstName())
                             && pinVerifyStr.equals(customerList[5].getPin())) {
                        textArea.append("\nCustomer: " + customerList[5].getFirstName()
                                  + " " + customerList[5].getLastName() + "\nAccount: "
                                  + customerList[5].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[5].getBalance()));
                   if (nameVerifyStr.equals(customerList[6].getFirstName())
                             && pinVerifyStr.equals(customerList[6].getPin())) {
                        textArea.append("\nCustomer: " + customerList[6].getFirstName()
                                  + " " + customerList[6].getLastName() + "\nAccount: "
                                  + customerList[6].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[6].getBalance()));
                   if (nameVerifyStr.equals(customerList[7].getFirstName())
                             && pinVerifyStr.equals(customerList[7].getPin())) {
                        textArea.append("\nCustomer: " + customerList[7].getFirstName()
                                  + " " + customerList[7].getLastName() + "\nAccount: "
                                  + customerList[7].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[7].getBalance()));
                   if (nameVerifyStr.equals(customerList[8].getFirstName())
                             && pinVerifyStr.equals(customerList[8].getPin())) {
                        textArea.append("\nCustomer: " + customerList[8].getFirstName()
                                  + " " + customerList[8].getLastName() + "\nAccount: "
                                  + customerList[8].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[8].getBalance()));
                   if (nameVerifyStr.equals(customerList[9].getFirstName())
                             && pinVerifyStr.equals(customerList[9].getPin())) {
                        textArea.append("\nCustomer: " + customerList[9].getFirstName()
                                  + " " + customerList[9].getLastName() + "\nAccount: "
                                  + customerList[9].getAccountType() + "\nBalance: "
                                  + formatDecimal.format(customerList[9].getBalance()));
                   textArea.append("\n===========================");
              //if the deposit/withdraw button is pressed, ask how much to deposit or withdraw
              //depending on which radio button is selected
              //Verify the name and pin on the account
              if (sourceObject == depositWithdrawButton) {
                   String nameVerifyStr = JOptionPane
                             .showInputDialog("Firstname on Account: ");
                   String pinVerifyStr = JOptionPane.showInputDialog("Pin Number: ");
                   if (depositRadioButton.isSelected()) {
                        String depositAmountStr = JOptionPane
                                  .showInputDialog("Deposit Amount: ");
                        double depositAmountDouble = Double
                                  .parseDouble(depositAmountStr);
                        if (nameVerifyStr.equals(customerList[0].getFirstName())
                                  && pinVerifyStr.equals(customerList[0].getPin())) {
                             double balanceDouble = customerList[0].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[0].setValues(customerList[0].getFirstName(),
                                       customerList[0].getLastName(), customerList[0]
                                                 .getPin(),
                                       customerList[0].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[0].getFirstName() + " "
                                       + customerList[0].getLastName() + "\nAccount: "
                                       + customerList[0].getAccountType() + "\nPin: "
                                       + customerList[0].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[1].getFirstName())
                                  && pinVerifyStr.equals(customerList[1].getPin())) {
                             double balanceDouble = customerList[1].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[1].setValues(customerList[1].getFirstName(),
                                       customerList[1].getLastName(), customerList[1]
                                                 .getPin(),
                                       customerList[1].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[1].getFirstName() + " "
                                       + customerList[1].getLastName() + "\nAccount: "
                                       + customerList[1].getAccountType() + "\nPin: "
                                       + customerList[1].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[2].getFirstName())
                                  && pinVerifyStr.equals(customerList[2].getPin())) {
                             double balanceDouble = customerList[2].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[2].setValues(customerList[2].getFirstName(),
                                       customerList[2].getLastName(), customerList[2]
                                                 .getPin(),
                                       customerList[2].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[2].getFirstName() + " "
                                       + customerList[2].getLastName() + "\nAccount: "
                                       + customerList[2].getAccountType() + "\nPin: "
                                       + customerList[2].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[3].getFirstName())
                                  && pinVerifyStr.equals(customerList[3].getPin())) {
                             double balanceDouble = customerList[3].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[3].setValues(customerList[3].getFirstName(),
                                       customerList[3].getLastName(), customerList[3]
                                                 .getPin(),
                                       customerList[3].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[3].getFirstName() + " "
                                       + customerList[3].getLastName() + "\nAccount: "
                                       + customerList[3].getAccountType() + "\nPin: "
                                       + customerList[3].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[4].getFirstName())
                                  && pinVerifyStr.equals(customerList[4].getPin())) {
                             double balanceDouble = customerList[4].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[4].setValues(customerList[4].getFirstName(),
                                       customerList[4].getLastName(), customerList[4]
                                                 .getPin(),
                                       customerList[4].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[4].getFirstName() + " "
                                       + customerList[4].getLastName() + "\nAccount: "
                                       + customerList[4].getAccountType() + "\nPin: "
                                       + customerList[4].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[5].getFirstName())
                                  && pinVerifyStr.equals(customerList[5].getPin())) {
                             double balanceDouble = customerList[5].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[5].setValues(customerList[5].getFirstName(),
                                       customerList[5].getLastName(), customerList[5]
                                                 .getPin(),
                                       customerList[5].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[5].getFirstName() + " "
                                       + customerList[5].getLastName() + "\nAccount: "
                                       + customerList[5].getAccountType() + "\nPin: "
                                       + customerList[5].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[6].getFirstName())
                                  && pinVerifyStr.equals(customerList[6].getPin())) {
                             double balanceDouble = customerList[6].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[6].setValues(customerList[6].getFirstName(),
                                       customerList[6].getLastName(), customerList[6]
                                                 .getPin(),
                                       customerList[6].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[6].getFirstName() + " "
                                       + customerList[6].getLastName() + "\nAccount: "
                                       + customerList[6].getAccountType() + "\nPin: "
                                       + customerList[6].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[7].getFirstName())
                                  && pinVerifyStr.equals(customerList[7].getPin())) {
                             double balanceDouble = customerList[7].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[7].setValues(customerList[7].getFirstName(),
                                       customerList[7].getLastName(), customerList[7]
                                                 .getPin(),
                                       customerList[7].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[7].getFirstName() + " "
                                       + customerList[7].getLastName() + "\nAccount: "
                                       + customerList[7].getAccountType() + "\nPin: "
                                       + customerList[7].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[8].getFirstName())
                                  && pinVerifyStr.equals(customerList[8].getPin())) {
                             double balanceDouble = customerList[8].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[8].setValues(customerList[8].getFirstName(),
                                       customerList[8].getLastName(), customerList[8]
                                                 .getPin(),
                                       customerList[8].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[8].getFirstName() + " "
                                       + customerList[8].getLastName() + "\nAccount: "
                                       + customerList[8].getAccountType() + "\nPin: "
                                       + customerList[8].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[9].getFirstName())
                                  && pinVerifyStr.equals(customerList[9].getPin())) {
                             double balanceDouble = customerList[9].getBalance();
                             balanceDouble += depositAmountDouble;
                             customerList[9].setValues(customerList[9].getFirstName(),
                                       customerList[9].getLastName(), customerList[9]
                                                 .getPin(),
                                       customerList[9].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[9].getFirstName() + " "
                                       + customerList[9].getLastName() + "\nAccount: "
                                       + customerList[9].getAccountType() + "\nPin: "
                                       + customerList[9].getPin() + "\nChanges: +"
                                       + depositAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                   if (withdrawRadioButton.isSelected()) {
                        String withdrawAmountStr = JOptionPane
                                  .showInputDialog("Withdraw Amount: ");
                        double withdrawAmountDouble = Double
                                  .parseDouble(withdrawAmountStr);
                        double chargeDouble;
                        if (withdrawAmountDouble > 2000) {
                             chargeDouble = 0.75;
                        } else if (withdrawAmountDouble > 750) {
                             chargeDouble = 0.50;
                        } else {
                             chargeDouble = 0;
                        if (nameVerifyStr.equals(customerList[0].getFirstName())
                                  && pinVerifyStr.equals(customerList[0].getPin())) {
                             double balanceDouble = customerList[0].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[0].setValues(customerList[0].getFirstName(),
                                       customerList[0].getLastName(), customerList[0]
                                                 .getPin(),
                                       customerList[0].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[0].getFirstName() + " "
                                       + customerList[0].getLastName() + "\nAccount: "
                                       + customerList[0].getAccountType() + "\nPin: "
                                       + customerList[0].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[1].getFirstName())
                                  && pinVerifyStr.equals(customerList[1].getPin())) {
                             double balanceDouble = customerList[1].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[1].setValues(customerList[1].getFirstName(),
                                       customerList[1].getLastName(), customerList[1]
                                                 .getPin(),
                                       customerList[1].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[1].getFirstName() + " "
                                       + customerList[1].getLastName() + "\nAccount: "
                                       + customerList[1].getAccountType() + "\nPin: "
                                       + customerList[1].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[2].getFirstName())
                                  && pinVerifyStr.equals(customerList[2].getPin())) {
                             double balanceDouble = customerList[2].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[2].setValues(customerList[2].getFirstName(),
                                       customerList[2].getLastName(), customerList[2]
                                                 .getPin(),
                                       customerList[2].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[2].getFirstName() + " "
                                       + customerList[2].getLastName() + "\nAccount: "
                                       + customerList[2].getAccountType() + "\nPin: "
                                       + customerList[2].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[3].getFirstName())
                                  && pinVerifyStr.equals(customerList[3].getPin())) {
                             double balanceDouble = customerList[3].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[3].setValues(customerList[3].getFirstName(),
                                       customerList[3].getLastName(), customerList[3]
                                                 .getPin(),
                                       customerList[3].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[3].getFirstName() + " "
                                       + customerList[3].getLastName() + "\nAccount: "
                                       + customerList[3].getAccountType() + "\nPin: "
                                       + customerList[3].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[4].getFirstName())
                                  && pinVerifyStr.equals(customerList[4].getPin())) {
                             double balanceDouble = customerList[4].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[4].setValues(customerList[4].getFirstName(),
                                       customerList[4].getLastName(), customerList[4]
                                                 .getPin(),
                                       customerList[4].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[4].getFirstName() + " "
                                       + customerList[4].getLastName() + "\nAccount: "
                                       + customerList[4].getAccountType() + "\nPin: "
                                       + customerList[4].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[5].getFirstName())
                                  && pinVerifyStr.equals(customerList[5].getPin())) {
                             double balanceDouble = customerList[5].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[5].setValues(customerList[5].getFirstName(),
                                       customerList[5].getLastName(), customerList[5]
                                                 .getPin(),
                                       customerList[5].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[5].getFirstName() + " "
                                       + customerList[5].getLastName() + "\nAccount: "
                                       + customerList[5].getAccountType() + "\nPin: "
                                       + customerList[5].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[6].getFirstName())
                                  && pinVerifyStr.equals(customerList[6].getPin())) {
                             double balanceDouble = customerList[6].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[6].setValues(customerList[6].getFirstName(),
                                       customerList[6].getLastName(), customerList[6]
                                                 .getPin(),
                                       customerList[6].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[6].getFirstName() + " "
                                       + customerList[6].getLastName() + "\nAccount: "
                                       + customerList[6].getAccountType() + "\nPin: "
                                       + customerList[6].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[7].getFirstName())
                                  && pinVerifyStr.equals(customerList[7].getPin())) {
                             double balanceDouble = customerList[7].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[7].setValues(customerList[7].getFirstName(),
                                       customerList[7].getLastName(), customerList[7]
                                                 .getPin(),
                                       customerList[7].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[7].getFirstName() + " "
                                       + customerList[7].getLastName() + "\nAccount: "
                                       + customerList[7].getAccountType() + "\nPin: "
                                       + customerList[7].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[8].getFirstName())
                                  && pinVerifyStr.equals(customerList[8].getPin())) {
                             double balanceDouble = customerList[8].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[8].setValues(customerList[8].getFirstName(),
                                       customerList[8].getLastName(), customerList[8]
                                                 .getPin(),
                                       customerList[8].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[8].getFirstName() + " "
                                       + customerList[8].getLastName() + "\nAccount: "
                                       + customerList[8].getAccountType() + "\nPin: "
                                       + customerList[8].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
                        if (nameVerifyStr.equals(customerList[9].getFirstName())
                                  && pinVerifyStr.equals(customerList[9].getPin())) {
                             double balanceDouble = customerList[9].getBalance();
                             if (withdrawAmountDouble + chargeDouble > balanceDouble) {
                                  JOptionPane.showMessageDialog(null,
                                            "Withdraw Exceeds Balance!");
                             } else {
                                  balanceDouble -= (withdrawAmountDouble + chargeDouble);
                             customerList[9].setValues(customerList[9].getFirstName(),
                                       customerList[9].getLastName(), customerList[9]
                                                 .getPin(),
                                       customerList[9].getAccountType(), balanceDouble);
                             textArea.append("\nCustomer: "
                                       + customerList[9].getFirstName() + " "
                                       + customerList[9].getLastName() + "\nAccount: "
                                       + customerList[9].getAccountType() + "\nPin: "
                                       + customerList[9].getPin() + "\nChanges: -"
                                       + withdrawAmountDouble + "\nBalance: "
                                       + formatDecimal.format(balanceDouble));
    }Any suggestions would be much appreciated
    - Thanks - GoOsE

    (1) thanks for the wall of code.
    (2) thanks for providing readers with the compilation errors.
    (3) why are you using camelcase for Class names?
    [*READ THIS*|http://mindprod.com/jgloss/abstract.html]
    the errors seem very straight forward to me:
    bankPresentation.java:34: cannot find symbol
    symbol : class bankSummary
    location: class bankPresentation
         bankSummary customerList[] = new bankSummary[10];
         ^
    bankPresentation.java:34: cannot find symbol
    symbol : class bankSummary
    location: class bankPresentation
         bankSummary customerList[] = new bankSummary[10];
         ^
    bankPresentation.java:38: bankPresentation is abstract; cannot be instantiated
              bankPresentation frame = new bankPresentation();
              ^
    bankPresentation.java:103: abstract methods cannot have a body <---- PAY ATTENTION
         abstract void assignArray() {
         ^
    4 errors
    Tool completed with exit code 1

  • How Abstract class differ, When we call class to be Abstract data type?

    We say as Classes as a realization of Abstract data types, then why should we declare that to be abstract ?
    Hope, the key word Abstract in both ADT and abstract classname mean the same.!!!!

    No, abstract is in the case of "abstract data type" a more general term, whereas in "abstract class" it is a technical term in Java.
    Are you not satisfied with the answers here?
    http://forum.java.sun.com/thread.jspa?threadID=5303930&messageID=10297137#10297137

  • Getting my head around DocumentListener and how inner classes work

    So I'm trying to get my first Swing GUI up and running and I cannot get my head around the DocumentListener.
    I have a JTextArea element called textArea which has the following code for it's listener:
    public class Gui extends JFrame {
        public Gui() {
            // Add the Text area
            JTextArea textArea = new JTextArea(textDoc);
            add(scrollPane, BorderLayout.CENTER);
            textArea.getDocument().addDocumentListener(new DocumentListener() {
                public void changeUpdate(DocumentEvent e) {
                public void insertUpdate(DocumentEvent e) {
                    saveText();
                public void removeUpdate(DocumentEvent e) {
                public void changedUpdate(DocumentEvent e) {
                    throw new UnsupportedOperationException("Not supported yet.");
        public void saveText() {
            System.out.println("saving");
    }Now of course this will not work. The method saveText() is in the parent class. So how do I invoke this method???
    Instead of calling the saveText() method I could interact with the variables of the parent class so why can't I invoke the method?

    OllieL wrote:
    public void insertUpdate(DocumentEvent e) {
    saveText();
    }Now of course this will not work. The method saveText() is in the parent class. So how do I invoke this method???Really? What happened when you tried? What does "will not work" mean? A compile error?
    Anyway, if there actually were a conflict (there isn't here, that's not why it's not working) you can always qualify the member further:
    //for instance member
    Gui.this.saveText();
    //for static member
    Gui.otherMethod();

  • Why how Abstract class   for java.util.set

    I need to use Set i din't find any impelemnted class for Set, i don't want HashSet or LinkedHashSet just a Set is enough for my purpose.
    How can i take instance of AbstractSet it is abstract.....
    Is the only way is to write my own class extending AbstractSet.
    Or is there something which i'm missing
    TIA Nas

    Because Vector isn't an ancsetor of AbstractList.
    What you are trying to do is the same as saying that becasue my cousin and I have the same grandfather we must have the same parent which isn't true.
               Collection
            Set         List
       AbstractSet      AbstractList
       HashSet              Vector

  • Abstract class confusion

    I am writing a J2ME application, and I want to write a Record management system (RMS) that I can use in other J2ME programs. I have a Record class that RMS classes need to know about. The idea is that the Record class is abstract, and the implementation is defined by a subclass - depending on what the application needs to store. Any Record must provide the following:
    1) A constructor which takes a single byte[] parameter, which is the data read in from the RecordStore by the RMS. The implementation depends on what information is stored in this type of Record - it might be a String, series of ints, etc...
    2) A method getStorageFormat() which returns a btye[] representing the data to be stored in the RecordStore. Again, this is dependent on the application.
    I think that I have to use an abstract class here, so I have written an abstract class called Record - here's what it looks like:
    public abstract class Record {
         public Record(byte[] bytes) { }; //Should this be an empty constructor?
         public abstract byte[] getStorageFormat();
    }My problem is that I can't define a subclass of Record that works! Here's an example:
    public class MyRecord extends Record {
           String data1, data2, data3; //Some data that is stored in this record
           public MyRecord(byte[] bytes) {
                  String data = new String(bytes);
                  // do some processing to extract the data...
           public byte[] getStorageFormat() {
                  String sep = ","; //A seperator
                  String tmp = data1 + sep + data2 + sep + data3; //put all the data together with
                  return tmp.getBytes();
    }}I get an error in Eclipse with the MyRecord constructor that says:" The implicit super constructor Record() is undefined. Must explicity invoke another constructor". I tried super() but I get the same error. Can anyone please tell me what I am doing wrong? It seems to me that I am misunderstanding something about how abstract classes work.

    Because you defined a ctor that takes args, the implicit one that takes no args--super()--is no longer implicitly supplied. You have to either put a no-arg ctor into the parent class, or call the one that you already have.
    public Record(byte[] bytes) { }; //Should this be an empty constructor?
    public abstract byte[] getStorageFormat();
    }No. You don't want a ctor that takes args and does nothing. If you're taking that arg, then you should use it to initialize the state of the object.
    Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a
    public MyClass() {...}
    if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor
    super(...)
    or a call to another ctor of this class
    this(...)
    2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor
    super()
    as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Why does this abstract class and method work without implement it?

    hi,
    I have seen many times that in some examples that there are objects made from abstract classes directly. However, in all books, manual and tutorials that I've read explain that we MUST implement those methods in a subclass.
    An example of what I'm saying is the example code here . In a few words that example makes Channels (java.nio.channel) and does operations with them. My problem is in the class to make this channels, because they used the ServerSockeChannel class and socket() method directly despite they are abstracts.
       // Create a new channel: if port == 0, FileChannel on /dev/tty, else
       // a SocketChannel from the first accept on the given port number
    private static ByteChannel newChannel (int netPort)
          throws Exception
          if (netPort == 0) {
             FileInputStream fis = new FileInputStream ("/dev/tty");
             return (fis.getChannel());
          } else {
    //CONFLICT LINES
             ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
             ssc.socket().bind (new InetSocketAddress (netPort)); //<--but here, this method (socket) is abstract. WHY RETURN A SOCKET????????  this mehod should be empty by default.
             System.out.print ("Waiting for connection on port "
                + netPort + "...");
             System.out.flush();
             ByteChannel channel = ssc.accept();
             ssc.close();
             System.out.println ("Got it");
             return (channel);
       } I test this code and works fine. So why can it be??
    Also, I read that the abstract classes can't have static methods. Is it true???
    Please Help!!
    PS: i have seen this kind of code many times. So i feel that I don't understand how its really the abstract methods are made.
    PS2: I understand that obviously you don't do something like this: *"obj = new AbstractClass(); "*. I dont understand how it could be: ServerSocketChannel ssc = ServerSocketChannel.open(); and the compiler didn't warn.

    molavec wrote:
    ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
    The static method creates an instance of a class which extends ServerSocketChannel, but is actually another non-abstract class.I thought that, but reading the documentation I saw that about open() method:
    Opens a server-socket channel.
    The new channel is created by invoking the openServerSocketChannel method of the system-wide default SelectorProvider object.
    The new channel's socket is initially unbound; it must be bound to a specific address via one of its socket's bind methods before connections can be accepted.
    ...and the problem is the same openServerSocketChannel is abstract, so i don't understand how it could return a ServerSocketChannel.There is a concrete implementation class that has implemented that method.
    I guess that really the open() method use a SelectorProvider's subclase but it doesn't appear in the doc.It doesn't need to. First, you don't care about those implementation details, and second, you know that if the class is abstract, it must use some concrete subclass.
    Ok, I speak Spanish by default (<-- this sounds like "I am a machine", ^_^' ). So, I didn't know how to say that the method would be {}. Is there a way to say that?? I recommendable for me to know, for the future questions o answers.Not sure what you're saying here. But the other respondent was trying to explain to you the difference between an abstract method and an empty method.
    // abstract method
    public abstract void foo();
    // empty method
    public void bar() {
    Which class does extend ServerSocketChannel? I can not see it.It may be a package-private class or a private nested class. There's no need to document that specific implementation, since you never need to use it directly.

  • How to implement the abstract classes MessageDigest and Signature?

    Hi all,
    I've recently started working on JCDK 2.2.1.
    I have a problem to share and get suggestions from you!
    My aim is to implement ECDSA on Java card
    I have seen the Javacard API and tried to program using the classes
    MessageDigest and Signature. They are abstract classes and except the
    Method getInstance in them, the rest of all methods are declared abstract.
    Does that mean we have to give definition for them or else can we use
    them as they are?
    I tried giving some definitions, but to my surprise there's no such
    initiation of any variable to the algorithm we provide in the method
    "getInstance"! Then, it's not possible to give defn,. for other
    methods like getAlgorithm, reset, etc. How can we resolve this ?
    Any ideas?
    Regards,
    Johnbuchk

    try this...
    http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_java_0501.jsp
    hope it can help u

  • EJB question: How to use abstract class in writing a session bean?

    I had written an abstract class which implements the session bean as follow:
    public abstract class LoggingSessionBean implements SessionBean {
    protected SessionContext ctx;
    protected abstract Object editRecord(Object obj) throws Exception;
    public LoggingSessionBean()
    super();
    private final String getBeforeUpdateImage(Object obj) throws Exception {
    // implement the details of extracting the backup image ...
    public void setSessionContext(SessionContext ctx)
    this.ctx = ctx;
    private final void writeThisImageToDatabase(String aStr) {
    // connect to database to write the record ...
    public final Object update(final Object obj) {
    try {
    final String aStr = getBeforeUpdateImage(obj);
    writeThisImageToDatabase(aStr);
    editRecord(obj);
    } catch (Exception e) {
    ctx.setRollbackOnly();
    This abstract class is to write the backup image to the database so that other session beans extending it only need to implement the details in editRecord(Object Obj) and they do not need to take care of the operation of making the backup image.
    However, some several questions for me are:
    1. If I write a class ScheduleSessionBean extending the above abstract class and the according 2 interfaces ScheduleSession and ScheduleSessionHome for this session bean (void update(Object obj); defined in ScheduleSession), do I still need to write the interfaces for LoggingSession and LoggingSessionHome?
    2. If I wrote the interface LoggingSession extending EJBObject where it defined the abstract methods "void update(Object obj);" and "void setSessionContext(SessionContext ctx);", that this meant I needed to write the ScheduleSession to implement the Logging Session?
    3. I used OC4J 9.0.4. How can I define the ejb-jar.xml in this case?

    Hi Maggie,
    1. do I still need to write
    the interfaces for LoggingSession and
    LoggingSessionHome?"LoggingSessionBean" can't be a session bean, because it's an abstract class. Therefore there's no point in thinking about the 'home' and 'remote' interfaces.
    2. this
    meant I needed to write the ScheduleSession to
    implement the Logging Session?Again, not really a question worth considering, since "LoggingSessionBean" can't be an EJB.
    3. I used OC4J 9.0.4. How can I define the
    ejb-jar.xml in this case?Same as you define it for any version of OC4J and for any EJB container, for that matter, since the "ejb-jar.xml" file is defined by the EJB specification.
    Let me suggest that you create a "Logging" class as a regular java class, and give your "ScheduleSessionBean" a member that is an instance of the "Logging" class.
    Alternatively, the "ScheduleSessionBean" can extend the "Logging" class and implement the "SessionBean" interface.
    Good Luck,
    Avi.

  • "Export classes in frame x" in AS3: how does it work?

    My steps:
    1. I have some beefy classes
    2. I want my SWF to show a preload anim while it loads these
    classes
    3. Using the "Export classes in frame: " option, I move my
    classes to frame 10
    4. I put a stop(); on the first frame and test w/ the
    bandwidth profiler visible.
    Desired + expected behavior:
    1. My preloader spins, and I have minimal K on the first
    frame and then the main hit on the chosen export frame.
    Observed behavior:
    1. all of my classes are available on the first frame (ala,
    all of my logic can be performed on the first frame, even though
    the framehead is sitting firmly on frame 1)
    2. there is still a spike in K on the output frame
    Notes:
    - am I just missing the point here? Is this how it always
    worked?
    - why is the Document Class available in the first frame? Is
    this mandatory w/ the new structure?
    Thanks for your time and help-
    cgs

    Thanks, moccamaximum, I believe this did open up a connection and now I have no errors.
    However, my problem still persists.
    Here is what it says in the output of my AS3 flash site:
    _root
    SWFBridge (AS3) connected: host
    SWFBridge (AS2) connected as client
    imgNum: 10
    thumb: images/image1.jpg
    image: images/image1.jpg
    thumb: thumbs/image2.jpg
    image: images/image2.jpg
    thumb: thumbs/image3.jpg
    image: images/image3.jpg
    thumb: thumbs/image4.jpg
    image: images/image4.jpg
    thumb: thumbs/image5.jpg
    image: images/image5.jpg
    thumb: thumbs/image6.jpg
    image: images/image6.jpg
    thumb: thumbs/image7.jpg
    image: images/image7.jpg
    thumb: thumbs/image8.jpg
    image: images/image8.jpg
    thumb: thumbs/image9.jpg
    image: images/image9.jpg
    thumb: thumbs/image10.jpg
    image: images/image10.jpg
    4
    _root
    4
    163
    _root
    163
    67
    _root
    67
    43
    _root
    43
    56
    _root
    56
    20
    _root
    20
    85
    _root
    85
    64
    _root
    64
    3
    _root
    3
    I don't understand how its able to trace that it is getting the images in the path, yet there are no images to be seen in the gallery!
    I found out that my gallery does work (with images and all) when loaded into a movieclip in a blank AS2 file instead of my AS3 site. Am I doomed since even localconnection will not help?

  • How to use function of an abstract class??

    Hi all,
    I want to use the format(object obj) function of the package java.text.Format. But as the Format class is an abstract class i could not instantiate it, so that i can call the format(object obj) method using the dot(.) operator.
    I know what is an abstract class. i've studied and tried to understand. as everybody knows, studied the perfect example(because i've read it in all the abstract class tutorial, books) of the Shape class. But still i dont understand how am i going to use that format(object obj) method. Please help me..

    Instead of using the abstract class Format use the
    concrete classes DecimalFormat
    SimpleDateFormat etc check java.text APIS
    http://java.sun.com/j2se/1.4.2/docs/api
    Hi!! Thanks both of you.
    If Sun has a abstract class then there must be a
    concrete class which extends that abstract class .It
    is always better to check the APIWhat do you mean by this line. Is it true for all the abstract classes in the jdk?

  • How to call Global Abstract Class in Report Program

    Hi All,
    Can Anyone tell me how call  global abstract class created in SE24.
    Thanks,
    Revanth

    Hi Revanth,
    What are you trying to do in abstract class?
    Are you inherit and trying to create object?
    Regards,
    A Vadamalai.

  • Properties Class, How does it work

    Hi
    I was struggling to find how to use Properties Object, to read properties file, then I saw the following solution:
    fis = <classname>.getClass().getResourceAsStream("<prop file>"); (1)
    prop = new Properties();(2)
    prop.load(fis);(3)
    fis.close();(4)
    This works fine, but I am not able to understand, how does it work?
    <classname>.getClass() should return a class object, and this class must be havaing getResourceAsStream() method, which is used by the properties object. But what is the need of first getting a "class" object. Our aim is to open the Properties file, then why do we need any reference to the current class.
    Can anybody explain the jargon of the line -(1)
    Gaurav

    the Class class is defined in the lava.lang package. The java virtual machine (JVM) uses a class loader to load class definitions from wherever <g> into memory, ok? The Class class represents the JVM's internal holding of a class definition (as opposed to instances of the class itself).
    To get the Class for any class, you can use the getClass() method on any object, or you can use the <classname>.class syntax. Either way, you get an instance of Class.
    The Class class contains some utility methods about class definitions prresent in the JVM. Importantly, the Class object for a class contains a reference to the class loader that loaded the class. You get it with the getClassLoader() method. The class loader is a thing that knows how to get a class definition from a local drive, or of a jar file, or off the web (if you are using an applet), or whatever. If one class needs another class to work, the class loader knows how to get the definition for that other class.
    Say I have a class
    class Foo {
       int bar(Baz baz);
    }and another one
    class Baz {
    }And both of these are in a jar file at http://z.com/applet1.jar
    An instance of URLClassLoader will be used to fetch class Foo. When Foo needs the definition of Baz, that same loader will be used to get Baz.
    A jar file (or a directory on your local drive) can contain anything at all, not just .class files. It might contain .prioperties files. These are called "resources". If you bundle them up with your class files, then the class loader that loaded the class files can also get them. So if your widget has gif files that it uses for icons, you just bundle them all up together.
    Of course, Class.getResource() is just a convenience method for Class.getClassLoader().getResource().

  • How the getNetworkInterfaces() of NetworkInterface class works

    Hi,
    I would like to know how the method getNetworkInterfaces() method in the NetworkInterface class works. Sometimes I get a cached data on the interfaces, sometimes I get an empty Enumeration getting returned. Does this method not get the refreshed values of the NetworkInterfaces??
    Thanks
    Swami

    I would like to know how the method getNetworkInterfaces() method in the NetworkInterface class works.
    Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
    List<InterfaceAddress> interfaces = new Vector<InterfaceAddress>(1,1);
    while(networkInterfaces.hasMoreElements())
    interfaces.addAll(networkInterfaces.nextElement().getInterfaceAddresses());
    }This code will extract all the interfaces present on your network and add then in a Vector.

  • Homework help--almost done but don't know how my class and main work?

    hello, i'm doing a project for my intro to java class. i'm almost done but i'm very confused on making my main and class work. the counter for my class slotMachine keeps resetting after 2 increments. also i don't not know how to make my quarters in the main receive a pay out from my class. Please guide me to understand what i have to do to solve this problem...I have listed my question page and my class and main of what i have done so far. Thank you .I will really appreciate the help.
    Objective: Create a class in Java, make instances of that class. Call methods that solve a particular problem Consider the difference between procedural and object-oriented programming for the same problem.
    Program Purpose:
    Find out how long it will take Martha to lose all of her money playing 3 instances of the slot machine class.
    Specification: Martha in Vegas
    Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 11 quarters every 10th time it is played. (If she played the 3rd machine only she would be a winner.)
    Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.
    Your program should output the number of times Martha plays until she goes broke.
    Sample Session. User input is in italics
    How many quarters does Martha have in the jar?
    48
    How many times has the first machine been played since playing out?
    30
    How many times has the second machine been played since paying out?
    10
    How many times has the third machine been played since paying out?
    9
    Martha plays XXX times
    Specific requirements: You must solve this using an object-oriented approach. Create a class called SlotMachine. Think about: What does a SlotMachine Have? What does it do? What information does it maintain? This is the state and behavior of the object. Each instance of this class will represent a single slot machine. Don�t put anything in the class unless it �belongs� to a single machine.
    In the main method, create 3 instances of the slot machine to solve the problem in the spec. Play the machines in a loop.
    ========================================================================
    my class
    ========================================================================
    public class SlotMachine{
    private int payOut;
    private int playLimit;
    private int counter;
    public SlotMachine (int payOut, int playLimit){
    this.payOut = payOut;
    this.playLimit = playLimit;
    public void setPayOut (int payOut){
    this.payOut = payOut;
    public int getPayOut(){
    return payOut;
    public void setPlayLimit (int playLimit){
    this.playLimit = playLimit;
    public int getPlayLimit(){
    return playLimit;
    public void slotCounter(){
    counter = SavitchIn.readLineInt();
    public int game(){
    counter++;
    if (counter == playLimit){
    counter = 0;
    return payOut - 1;
    return -1; // the game method was edited by my professor but i'm still confused to make it work
    =======================================================================
    my main
    =======================================================================     
    public class Gametesting{
    public static void main(String[]args){
    SlotMachine firstSlotMachine = new SlotMachine (2,3);
    SlotMachine secondSlotMachine = new SlotMachine (2,3);
    SlotMachine thirdSlotMachine = new SlotMachine (2,2);     
    int quarters;
    int playerCount = 0;
    System.out.println("How many quarters does Martha have in the jar?");
    quarters = SavitchIn.readLineInt();
    System.out.println("How many times has the first machine been played since paying out?");
    firstSlotMachine.slotCounter();
    System.out.println("How many times has the second machine been played since paying out?");
    secondSlotMachine.slotCounter();
    System.out.println("How many times has the third machine been played since paying out?");
    thirdSlotMachine.slotCounter();
    while (quarters != 0){
    playerCount++;
    quarters--;
    firstSlotMachine.game();
    if (quarters != 0){
    playerCount++;
    quarters--;
    secondSlotMachine.game();
    if (quarters != 0){
    playerCount++;
    quarters--;
    thirdSlotMachine.game();
    System.out.println("Martha plays " + playerCount + " times");

    The main problem is that you made the first and second slot machine to pay out 2 quarters after 3 games and the third machine pay out two quarters after two games. That is not what your assignment specified.
    SlotMachine firstSlotMachine = new SlotMachine (2,3);
    SlotMachine secondSlotMachine = new SlotMachine (2,3);
    SlotMachine thirdSlotMachine = new SlotMachine (2,2);
    The second problem is that you never add the payout of a machine to Martha's number of quarters.
    Look carefully at the way your professor implemented the game() method. If you think about it, what it returns is the net "gain" from playing a game. On jackpot it returns payOut -1 (jackpot less the one quarter Martha had to pay for the game), otherwise it returns -1 (Martha spends one quarter and wins nothing).
    So what you can do is simply add the returned value to the number of quarters in the jar -
    quarters = <machine>.game();
    instead of quarters--.

Maybe you are looking for