Write a java program with comments using the following instructions: A company h
ID: 3806849 • Letter: W
Question
Write a java program with comments using the following instructions:
A company has sales reps that sell two different product lines. The sales amounts for each product are recorded, and commission is calculated based on the total sales. Commission is:
-5% of sales for sales < 4000
-7% of sales for 4000 to < 8000
-10% of sales for 8000 or above
Create a class called SalesRep with attributes (private data members) of:
-Salesrep name
-Product1 sales amount
-Product2 sales amount
Include these methods (note that you may or may not use all of them in your app)
-Create a default and parameterized constructor
-Create set / get methods for name
-Create get methods to calculate and return total sales, commission
Create your “app” class, SalesRepTest. In main, you will create an arrayList (or static array, your choice) of these SalesRep objects. (If you use a static array, make it large enough to hold 20 salesreps, but there may be less than 20 entered). Implement the following menu options:
1 – Add sales rep prompt for name and the two sales amounts, add to arrayList or array
2 - Print sales report prints the name, total sales, and commission for all reps entered into the system in the format shown below on sample output. Also calculate and print the total sales and commission of all reps (note totals calculated in app, not in class).
3 - Print Diamond Club Prints the name and total sales of all reps with $10000 or more in total sales
4 - Exit
You should validate the menu choice with a loop. You can assume all sales rep data is valid
SAMPLE OUTPUT: (must caculate total sales and commision on our own which is why answer is not given)
Explanation / Answer
import java.lang.*;
import java.util.Scanner;
public class SalesRep
{
private String sname;
private long pr1,pr2;
double p1[]=new double[20];
double p2[]=new double[20];
double ts[]=new double[20];
double tc[]=new double[20];
String sn[]=new String[20];
int a=0,b=0,c=0,f=0,g=0,k=0;
HelloWorld()
{
sname="";
pr1=0;
pr2=0;
}
void addrep()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name:" );
sname=sc.nextLine();
System.out.println("Enter Product 1 sales:");
pr1=sc.nextLong();
System.out.println("Enter Product 2 sales:");
pr2=sc.nextLong();
sn[a++]=sname;
p1[b++]=pr1;
p2[c++]=pr2;
}
void details()
{
int i;
for(i=0;i<20;i++)
{
System.out.println(sn[i]);
System.out.println(p1[i]);
System.out.println(p2[i]);
}
}
void getmethod()
{
int i;
double sum,com;
double tss=0,tcc=0;
for(i=0;i<20;i++)
{
sum=p1[i]+p2[i];
if(sum<4000)
com=0.05*sum;
else if(sum >=4000 && sum < 8000)
com=0.07*sum;
else
com=0.1*sum;
ts[f++]=sum;
tc[g++]=com;
}
System.out.println("Salesperson"+" "+"Total Sales"+" "+"Total Commision");
for(i=0;i<a;i++)
{
System.out.println(sn[i]+" "+ts[i]+" "+tc[i]);
}
for(i=0;i<20;i++)
{
tss=tss+ts[i];
tcc=tcc+tc[i];
}
System.out.print("Total");
System.out.println(" "+tss+" "+tcc);
}
void diamond()
{
int i,j;
double sum;
for(j=0;j<20;j++)
{
sum=p1[j]+p2[j];
ts[k++]=sum;
}
System.out.println("Diamond Club Qualified");
System.out.println("Name"+" "+"Total Sales");
for(i=0;i<20;i++)
{
if(ts[i]>=10000)
{
System.out.println(sn[i]+" "+ts[i]);
}
}
}
public static void main(String []args)
{
int c;
SalesRep obj=new SalesRep();
Scanner sc=new Scanner(System.in);
do
{
System.out.println("Sales Reporting System");
System.out.println("1- Add rep");
System.out.println("2- Print sales report");
System.out.println("3- Print Diamond Club");
System.out.println("4- Exit");
System.out.println("Enter your choice");
c=sc.nextInt();
switch(c)
{
case 1:
obj.addrep();
break;
case 2:
obj.getmethod();
break;
case 3:
obj.diamond();
break;
case 4:
System.out.println("Goodbye!");
System.exit(0);
default:
System.out.println("Invalid Choice");
break;
}
}while(c!=4);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.