I am trying to solve this without the use of JOptionPane.showInputDialog, we hav
ID: 3759626 • Letter: I
Question
I am trying to solve this without the use of JOptionPane.showInputDialog, we have not learned that yet. Your help is appreciated
A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5000, or a total of $650. You’ve been supplied with a list of the items sold by each salesperson. The values of these items are as follows: Item Value 1 239.99 2 129.75 3 99.95 4 350.89 Develop a Java application that inputs one salesperson’s items sold for last week and calculates and displays that salesperson’s earnings. There’s no limit to the number of items that can be sold.
Explanation / Answer
public class SalesCommissionCalculator
{
private String item;
private double value;
public SalesCommissionCalculator()
{
setItem("");
setValue(0.0);
}
public SalesCommissionCalculator(String i, double v)
{
setItem(i);
setValue(v);
}
public void setItem(String i)
{
item = i;
}
public void setValue(double v)
{
value = v;
}
public String getItem()
{
return item;
}
public double getValue()
{
return value;
}
public String toString()
{
return ("Item"+item+"Value"+value);
}
}
import javax.swing.JOptionPane;
import java.util.Scanner;
public class SalesCommissionCalculatorTest
{
public static void main(String args [])
{
int quantity;
int item;
double salary = 200.00;
double commission = 0.09;
double total= 0;
String msg="";
SalesCommissionCalculator item1 = new SalesCommissionCalculator("1", 239.99);
SalesCommissionCalculator item2 = new SalesCommissionCalculator("2", 129.75);
SalesCommissionCalculator item3 = new SalesCommissionCalculator("3", 99.95);
SalesCommissionCalculator item4 = new SalesCommissionCalculator("4", 350.89);
item=Integer.parseInt(JOptionPane.showInputDialog("Enter item number 1, 2, 3 or 4. Enter -1 to quit."));
while(item != -1)
{
switch(item)
{
case 1: quantity=Integer.parseInt(JOptionPane.showInputDialog("Enter quantity"));
total += (quantity*item1.getValue());
break;
case 2: quantity=Integer.parseInt(JOptionPane.showInputDialog("Enter quantity"));
total+= (quantity*item2.getValue());
break;
case 3: quantity=Integer.parseInt(JOptionPane.showInputDialog("Enter quantity"));
total += (quantity*item3.getValue());
break;
case 4: quantity=Integer.parseInt(JOptionPane.showInputDialog("Enter quantity"));
total += (quantity*item4.getValue());
break;
default:
System.out.println("Invalid Item Number");
}
item=Integer.parseInt(JOptionPane.showInputDialog("Enter item number 1, 2, 3 or 4. Enter -1 to quit."));
}
msg = msg + String.format("Your Commission is $%.2f", (total*commission)+salary);
JOptionPane.showMessageDialog(null, msg);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.