In java language, Process sales information for each of the salesperson in a fir
ID: 3863586 • Letter: I
Question
In java language,
Process sales information for each of the salesperson in a firm.Ask the user to enter the number of salespeople.Store the name of each salesperson and the amount of sales in two parallel arrays. Allow to continue only if the user inputs positive number for sales. Use continuous loop. Calculate commission for each salesperson in dollars and store it in another array based on the following.
-Less than $2000, 5% commission
-more than $2000 and less than $5000, 10% commission
-more than $5000, 20% commission
Write a method for each of the following:
-to input and return the number of salesperson
-to gather the required input data.
-to calculate the commission array.
-to calculate and return total sales for the firm. Totals sales does not include the commission.
-to calculate and return average sales for the firm. The average sales value does not include the commission.
-to calculate and return the total commission for the firm.
-Write a method to display the salesperson's name and amount of sales and the amount of commission for all salesperson in a tabular format.
-Write a method that accepts the name of a salesperson as its parameter and returns the amount of commission for the given salesperson. If the given name does not exist, issue an error message.
Explanation / Answer
/*
you can test this program by writing your own main method
as per your needs.
*/
import java.util.Scanner;
public class Sales {
int num=0;
Scanner sc=new Scanner(System.in);
private int getNoofSP(){
System.out.println("Enter number of sales Persons:");
int num1=sc.nextInt(); //read number of salespersons from users
num=num1;
return num;
}
private String[] getSP(){
int num=getNoofSP();
String[] sPersons=new String[num];
//ask user to enter name of sales persons
System.out.println("Enter names of sales Persons one by one:");
for(int i=0;i<num;i++){
sPersons[i]=sc.nextLine();
sc.nextLine();
}
return sPersons;
}
private int[] getSales(){
int sales[]=new int[num];
//ask user to enter sales amount of sales persons
System.out.println("Enter sales amount for each sales person");
for(int i=0;i<num;i++){
sales[i]=sc.nextInt();
//continue asking until positive value is enetered
while(sales[i]<0){
System.out.println("Enter positive value");
sales[i]=sc.nextInt();
}
}
return sales;
}
private double[] calculateCommision(){
int[] sales=getSales();
double[] comm=new double[num];
for(int i=0;i<num;i++){
if(sales[i]<2000){
//5% commission
comm[i]=(sales[i]*5)/100.00;
}
else if(sales[i]>2000 && sales[i]<5000){
//10% commission
comm[i]=(sales[i]*10)/100.00;
}
else if(sales[i]>5000){
//20% commission
comm[i]=(sales[i]*20)/100.00;
}
}
return comm;
}
private int calculateTotalSales(){
int[] sales=getSales();
int sum=0;
for(int i=0;i<num;i++){
sum+=sales[i];
}
return sum;
}
private double calculateAvgSales(){
int sum=calculateTotalSales();
double avg=(double)sum/num;
return avg;
}
private double calculateTotalComission(){
double[] sales=calculateCommision();
double sum=0.0;
for(int i=0;i<sales.length;i++){
sum+=sales[i];
}
return sum;
}
private void printSalesInfo(){
String[] persons=getSP();
int[] sales=getSales();
double[] comm=calculateCommision();
System.out.println("SalesPerson SalesAmount Commisiion");
for(int i=0;i<sales.length;i++){
System.out.println(persons[i]+" "+sales[i]+" "+comm[i]);
}
}
private double getCommision(String person){
String[] persons=getSP();
double[] comm=calculateCommision();
for(int i=0;i<persons.length;i++){
if(persons[i].equals(person)){
return comm[i];
}
}
System.err.println(person+" does not exists");
return 0.0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.