Koszelak_N_CIS355_Week2_Practice.docx

Override public void ae boolean valid if ainvoice

This preview shows page 4 - 6 out of 6 pages.

@Override public void actionPerformed(ActionEvent ae) { boolean valid; if (aInvoice == null) { //TODO: create a new invoice object System.out.println("Calc clicked"); aInvoice = new Invoice(); } aInvoice.setProductName(txtProductName.getText()); try { int quanity = Integer.parseInt(txtQuantity.getText()); aInvoice.setQuantityPurchased(quanity); valid = true; }
Image of page 4

Subscribe to view the full document.

catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Quantity needs to be a number between 1 and 1000", "Illegal Quanity value", JOptionPane.ERROR_MESSAGE); valid = false; txtQuantity.setText(""); txtQuantity.requestFocus(); } if (valid) { try { double cost = 0; //TODO: write the state to extract the double value from the txtCost field aInvoice.setPricePerItem(cost); } catch (NumberFormatException ex) { valid = false; JOptionPane.showMessageDialog(null, "Costs needs to be a number between 10 and 10000", "Illegal Cost value", JOptionPane.ERROR_MESSAGE); valid = false; txtCostPerItem.setText(""); txtCostPerItem.requestFocus(); } } if (valid) { //TODO: using the toString method of the invoice object to set the output text
Image of page 5
} } } }
Image of page 6
You've reached the end of this preview.
  • Summer '12
  • all
  • Physical quantity, The Double, Professor Ricky Sethi

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern