Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to solve this without the use of JOptionPane.showInputDialog, or JOp

ID: 3759711 • Letter: I

Question

I am trying to solve this without the use of JOptionPane.showInputDialog, or JOption. We have not learned that yet. We have only covered the first 3 chapters of Programming with Java 10th edition. I need a simple answer if possible. 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

import java.util.Scanner; class SalesPerson{ private String name; private int items; private double itemValue[]; public SalesPerson(String name,int items){ this.name = name; this.items = items; itemValue = new double[items]; } public void addItem(double value,int index){ itemValue[index] = value; } public double earnLastWeek(){ double sales = 0.0,earn = 0.0; for(int i=0;i<items;i++){ sales += itemValue[i]; } earn = sales * (9.0/100) + 200; return earn; } } public class SalesPersonEarning { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int salesPersonCount,counter=0; System.out.print(" Enter number of sales person :"); salesPersonCount = sc.nextInt(); while(counter "); System.out.print("Person Name :"); sc.nextLine(); n = sc.nextLine(); System.out.print("Items sold :"); items = sc.nextInt(); SalesPerson sp = new SalesPerson(n,items); for(int i=0;i<items;i++){ System.out.print(" Items " + (i+1) + " value :"); double value = sc.nextDouble(); sp.addItem(value,i); } double spEarning = sp.earnLastWeek(); System.out.print("Last week earning of " + n + " is : " + spEarning); counter++; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote