In: Computer Science
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects.
public class DemoSalesperson
{
public static void main (String args[])
{
// your code here
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
public class Salesperson
{
// constructor
// get and set methods
}
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package demosalesperson;
import java.util.*;
/**
*
* @author Addy
*/
class Salesperson{
private int id;
private double annualSalesAmount;
//constructor
public Salesperson(int ID, double annualSalary) {
id=ID;
annualSalesAmount=annualSalary;
}
//setter
public void setID(int i){
id=i;
}
public void setSalesAmount(double sal){
annualSalesAmount=sal;
}
//getter
public int getID(){
return id;
}
public double getSalesAmount(){
return annualSalesAmount;
}
}
public class DemoSalesperson {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Salesperson[] salePerson = new Salesperson[10];
//array pf objects
for(int i = 0; i < 10;
i++){
salePerson[i] =
new Salesperson(9999, 0); //setting
}
for(int i = 0; i < 10;
i++){
//display
System.out.println("ID: "+
salePerson[i].getID() + " Sales Amount: " +
salePerson[i].getSalesAmount());
}
}
}
OUTPUT:
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP