Question
In Chapter 8, you created a Salespersonclass with fields for an ID number and sales values. Now, create an application that allows you to store
In Chapter 8, you created a Salespersonclass 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 four options: to (A)dd a record to the database, to (D)elete a record from the database, to (C)change a record in the database, or to (Q)uit. Then proceed as follows:
If the user selects the add option, issue an error message, Sorry - array is full -- cannot add a record, if the database is full. Otherwise, prompt the user for an ID number. If the ID number already exists in the database, issue the error message Sorry -- ID number already exists. Otherwise, prompt the user for a sales value and add the new record to the database.
If the user selects the delete option, issue the error message, Cannot delete - no records in database, if the database is empty. Otherwise, prompt the user for an ID number. If the ID number does not exist, issue the error message, Sorry - ID number #xxx does not exist in the database. Otherwise, do not access the record for any future processing.
If the user selects the change option, issue the error message, Database is empty -- cannot change record, if the database is empty. Otherwise, prompt the user for an ID number. If the requested record does not exist, issue the error message, Sorry - ID number #xxx does not exist in the database. Otherwise, prompt the user for a new sales value and change the sales value 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.
Salesperson.java
public class Salesperson {
private int id;
private double sales;
Salesperson(int idNum, double amt) {
}
public int getId() {
}
public double getSales() {
}
public void setId(int idNum) {
}
public void setSales(double amt) {
}
}
SalespersonDatabase.java
import java.util.*;
public class SalespersonDatabase {
public static void main(String[] args) {
// Write your code here
}
public static int addOption(Salesperson[] array, int count) {
// Write your code here
}
public static int deleteOption(Salesperson[] array, int count) {
// Write your code here
}
public static void changeOption(Salesperson[] array, int count) {
// Write your code here
}
public static void display(Salesperson[] array, int count) {
// Write your code here
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started