Answer to Question #59138 in Java | JSP | JSF for James

Question #59138
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a double annual 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. Save the files as Salesperson.java and DemoSalesperson.java.
1
Expert's answer
2016-04-12T15:07:04-0400
package com.company;
public class DemoSalesperson {
public static void main(String[] args) {
Salesperson[] salesperson = new Salesperson[10];
for(int i = 0; i < 10; i++) {
salesperson[i] = new Salesperson();
salesperson[i].setId(9990 + i);
salesperson[i].setannualSalesAmount(0);
System.out.println(salesperson[i]);
}
}
}





package com.company;
public class Salesperson {
private int Id;
private double annualSalesAmount;
/**
Constructs a Salesperson object
*/
public Salesperson() {
}
/**
Constructs a Salesperson object
*/
public Salesperson(int id, double annualSalesAmount) {
this.Id = id;
this.annualSalesAmount = annualSalesAmount;
}
/**
Returns the id of the salesperson
@return Id of the salesperson
*/
public int GetId (){
return Id;
}
/**
Returns the annual sales amount of the salesperson
@return annualSalesAmount of the salesperson
*/
public double getannualSalesAmount (){
return annualSalesAmount;
}
/**
Sets the id to the parameter value
@param newId the id of the salesperson
*/
public void setId(int newId) {
Id = newId;
}
/**
Sets the annual sales amount to the parameter value
@param newannualSalesAmount the annual sales amount of the salesperson
*/
public void setannualSalesAmount(double newannualSalesAmount) {
annualSalesAmount = newannualSalesAmount;
}

public String toString (){
return this.Id + " annual sales amount: " + this.annualSalesAmount;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS