Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having issues with getting the cancel button to work for the empCode. Any suggestions? import javax.swing.JOptionPane; public class TravelCommission { // declare and

I am having issues with getting the cancel button to work for the empCode. Any suggestions?

import javax.swing.JOptionPane;

public class TravelCommission {

// declare and construct variables

double dollars =0;

public static void main(String[] args)

{

// call methods

double sales=getSales();

int code=getCode();

double comm=getComm(sales, code);

output(sales, comm);

finish();

}

//-------------------------------------------------------

public static double getSales()

{

double dollars = 0;

boolean done = false;

while (!done)

{

try

{

dollars = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the sales amount do not use commas or dollar signs or click cancel to exit "));

if (dollars <=0) throw new Exception("Error- Enter a number greater than zero");

done = true;

}

catch (NumberFormatException ex)

{

JOptionPane.showMessageDialog(null,"Your entry must be a number.","Error",JOptionPane.INFORMATION_MESSAGE);

}

catch(Exception ie)

{

JOptionPane.showMessageDialog(null,"Your entry must be an integer greater than 0.","Error",JOptionPane.INFORMATION_MESSAGE);

}

}

return dollars;

}

//---------------------------------------------------------------

public static int getCode()

{ boolean done = false;

int empCode=0;

while (!done)

{

try

{

empCode = Integer.parseInt(JOptionPane.showInputDialog(null, "enter the commission code; 1) Telephone Sales 2) In-Store Sales 3) Outside Sales"));

if (empCode == null)

{System.exit(0);}

if (empCode<1 || empcode>3) throw new Exception("Please enter a 1, 2 or 3");

done = true;

}

catch (NumberFormatException ex)

{

JOptionPane.showMessageDialog(null,"Please enter a 1,2 or 3.","Error",JOptionPane.INFORMATION_MESSAGE);

}

catch(Exception ie)

{

JOptionPane.showMessageDialog(null,"Please enter a 1, 2 or 3.","Error",JOptionPane.INFORMATION_MESSAGE);

}

}

return empCode;

}

public static double getComm(double dollars, int empCode) {

double answer=0;

if (empCode == 1)

{

answer = dollars *(0.10);

}

else if (empCode == 2)

{

answer = dollars * (0.14);

}

else {

answer = dollars * (0.18);

}

return answer;

}

public static void output(double dollars, double answer) {

JOptionPane.showMessageDialog(null,"Your commission on sales of "+dollars+ " is "+answer,"Commission Totals",JOptionPane.INFORMATION_MESSAGE);

}

//The finish() method ends the program.

public static void finish()

{

System.exit(0);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago