Question: This Java program must use classes and object-oriented design (OOD) as I'm in a more advanced Java class. (Sales Commission Calculator) A large company pays
This Java program must use classes and object-oriented design (OOD) as I'm in a more advanced Java class.
(Sales Commission Calculator) 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 $5000 worth of merchandise in a week receives $200 plus 9% of $5000, or a total of $650. Youve 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 salespersons items sold for last week and calculates and displays that salespersons earnings. Theres no limit to the number of items that can be sold.
IMPORTANT NOTE!!: As stated above, this program must use classes and object-oriented design (OOD). Also, please add detailed, but brief comments to most, if not all of the code to explain what is being used in the code and what is does so I have a better understanding of the code. For example:
// Condition to check the price is less than zero or not.
if (price < 0)
Thank you! :)
Here's what I have so far:
import javax.swing.JOptionPane; public class SalesCommissionCalculator { public static void main( String args[] ) { //Declaring the required variables. double gross = 0.0, earnings; int product = 0, number; String input; while ( product < 4 ) { product++; // Read number from user as a string. input =JOptionPane.showInputDialog("Enter number sold of product #" + product + ":" ); // Converts numbers from type String to type int. number = Integer.parseInt( input ); //Calculating the sales. if ( product == 1 ) gross = gross + number * 239.99; else if ( product == 2 ) gross = gross + number * 129.75; else if ( product == 3 ) gross = gross + number * 99.95; else if ( product == 4 ) gross = gross + number * 350.89; } earnings = 0.09 * gross + 200; //Printing the result. String result = "Weekly Earnings: " + earnings; JOptionPane.showMessageDialog(null, result, "Sales",JOptionPane.INFORMATION_MESSAGE ); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
