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

Hello, I am wondering if someone could help me figure out problem7. I am having

ID: 3758240 • Letter: H

Question

Hello, I am wondering if someone could help me figure out problem7. I am having a hard time with arrays and I would greatly appreciate it if someone would help me solve problem 7. Thank you

6. A) 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 method 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.
  
B) Modify the DemoSalesperson application so each Salesperson has a successive ID number from 111 through 120 and a sales value that ranges from $25,000 to $70,000, increasing by $5,000 for each successive Salesperson. Save the file as DemoSalesperson.java


7) In problem 6, you created a Salesperson class with fields for an ID number and sales values. Now, create an application that allows you to store an array that acts as a database of any number of Salesperson objects up to 20. While the user decides to continue, offer three options: to add a record to the database, to delete a record from the database, or to change a record in the database. Then proceed as follows.

•   If the user selects the add option, issue an error message if the database is full. Otherwise, prompt the user from an ID number. If the ID number already exists in the database, issue an error message. Otherwise, prompt the user for a sales value, and add the new record to the database.
•   If the user selects the delete option, issue an error message if the database is empty. Otherwise, prompt the user for an ID number. If the ID number does not exist, issue an error message. Otherwise, do not access the record for any future processing.
•   If the user selects the change option, issue an error message if the database is empty. Otherwise, prompt the user for an ID number. If the requested record does not exist, issue an error message. Otherwise, prompt the user for a new sales value, and change the sales values for the record.

After each option executes, display the updated database in ascending order by Salesperson ID number, and prompt the user to select the next action. Save the application as SalespersonDatabase.java

Explanation / Answer

Please find the required solution:

public class Salesperson {
   // properties of sales Person
   int id;
   double annualSales;

   // 2 argument constructor that initializes the state of sales person
   public Salesperson(int id, double annualSales) {
       super();
       this.id = id;
       this.annualSales = annualSales;
   }

   // getter and setters of properties of sales person
   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public double getAnnualSales() {
       return annualSales;
   }

   public void setAnnualSales(double annualSales) {
       this.annualSales = annualSales;
   }

}//end of class Salesperson

public class DemoSalesperson {
   public static void main(String[] args) {
       // declaration of the salesPersons array
       Salesperson[] salesPersons = new Salesperson[10];
      
       // Add 10 salesPerson to array with id 9999 and annual sales 0
       for (int i = 0; i < salesPersons.length; i++) {
           salesPersons[i] = new Salesperson(9999, 0);
       }

       /*
       * Modify the DemoSalesperson application so each Salesperson has a
       * successive ID number from 111 through 120 and a sales value that
       * ranges from $25,000 to $70,000, increasing by $5,000 for each
       * successive Salesperson)
       */
       int initId = 111;
       double initSales = 25000;
       for (int i = 0; i < salesPersons.length; i++) {
           salesPersons[i] = new Salesperson(initId, initSales);
           initId++;
           initSales += 5000;
       }
   }
}// end of class DemoSalesperson

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