Explanation of Solution
Program:
File name: “SalespersonDatabase.java”
//Import necessary header files
import java.util.*;
//Define a class named SalespersonDatabase
public class SalespersonDatabase
{
//Define main method
public static void main(String[] args)
{
//Create an array of objects
SalesPerson[] salespeople = new SalesPerson[20];
//Declare variables
int x;
int id;
int count = 0;
double sales;
final int QUIT = 999;
char option;
String message = "";
//Create an object for Scanner class
Scanner keyboard = new Scanner(System.in);
//Prompt the user to enter an option
System.out.print("Do you want to (A)dd, (D)elete, or (C)hange a record or (Q)uit >> ");
option = keyboard.nextLine().charAt(0);
//While condition exists if option entered by the user is not equal to Quit
while(option != 'Q')
{
//If option is to Add a record
if(option == 'A')
count = addOption(salespeople, count);
//If option is to Delete a record
else
if(option == 'D')
count = deleteOption(salespeople, count);
//If option is to Change a record
else
if(option == 'C')
changeOption(salespeople, count);
//Invalid
else
//Print the result
System.out.println("Invalid entry");
//Prompt the user to enter an option
System.out.print("Do you want to (A)dd, (D)elete, or (C)hange a record or (Q)uit >> ");
option = keyboard.nextLine().charAt(0);
}
}
//Define a method for add option
public static int addOption(SalesPerson[] array, int count)
{
//Create an object for Scanner class
Scanner keyboard = new Scanner(System.in);
//Declare variables
int id;
double sales;
boolean alreadyEntered;
//Check if
if(count == array.length)
//Print the result
System.out.println("Sorry - array is full -- cannot add a record");
//if database is not full
else
{
//Prompt the user to enter the ID of the salesperson
System.out.print("Enter salesperson ID >> ");
id = keyboard.nextInt();
alreadyEntered = false;
for(int x = 0; x < count; ++x)
//Check if ID number already exists
if(array[x].getId() == id)
{
//Print the result
System.out.println("Sorry -- ID number already exists");
alreadyEntered = true;
}
//Check if ID number does not exists
if(!alreadyEntered)
{
//Prompt the user to enter the sales
System.out.print("Enter sales >> ");
sales = keyboard.nextDouble();
array[count] = new SalesPerson(id, sales);
//Increment the count
++count;
}
}
//Display the database values
display(array, count);
keyboard.nextLine();
//Return the value
return count;
}
//Define a method for delete option
public static int deleteOption(SalesPerson[] array, int count)
{
//Create an object for Scanner class
Scanner keyboard = new Scanner(System.in);
//Declare variables
int id;
int position = 0;
//Check if database is empty
if(count == 0)
//Print the result
System.out.println("Cannot delete - no records in database");
//if database is not empty
else
{
//Prompt the user to enter the ID of the salesperson
System.out.print("Enter ID to delete >> ");
id = keyboard.nextInt();
boolean exists = false;
for(int x = 0; x < count; ++x)
//Check if ID number already exists
if(array[x].getId() == id)
{
exists = true;
position = x;
}
//if ID number does not exists
if(!exists)
//Print the result
System...
Trending nowThis is a popular solution!
Chapter 9 Solutions
MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
- A manipulator is identified by the following table of parameters and variables:a. Obtain the transformation matrices between adjacent coordinate frames and calculate the global transformation matrix.arrow_forwardWhich tool takes the 2 provided input datasets and produces the following output dataset? Input 1: Record First Last Output: 1 Enzo Cordova Record 2 Maggie Freelund Input 2: Record Frist Last MI ? First 1 Enzo Last MI Cordova [Null] 2 Maggie Freelund [Null] 3 Jason Wayans T. 4 Ruby Landry [Null] 1 Jason Wayans T. 5 Devonn Unger [Null] 2 Ruby Landry [Null] 6 Bradley Freelund [Null] 3 Devonn Unger [Null] 4 Bradley Freelund [Null] OA. Append Fields O B. Union OC. Join OD. Find Replace Clear selectionarrow_forwardWhat are the similarities and differences between massively parallel processing systems and grid computing. with referencesarrow_forward
- Modular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forwardBased on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forwardBased on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forward
- Question: Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forward23:12 Chegg content://org.teleg + 5G 5G 80% New question A feed of 60 mol% methanol in water at 1 atm is to be separated by dislation into a liquid distilate containing 98 mol% methanol and a bottom containing 96 mol% water. Enthalpy and equilibrium data for the mixture at 1 atm are given in Table Q2 below. Ask an expert (a) Devise a procedure, using the enthalpy-concentration diagram, to determine the minimum number of equilibrium trays for the condition of total reflux and the required separation. Show individual equilibrium trays using the the lines. Comment on why the value is Independent of the food condition. Recent My stuff Mol% MeOH, Saturated vapour Table Q2 Methanol-water vapour liquid equilibrium and enthalpy data for 1 atm Enthalpy above C˚C Equilibrium dala Mol% MeOH in Saturated liquid TC kJ mol T. "Chk kot) Liquid T, "C 0.0 100.0 48.195 100.0 7.536 0.0 0.0 100.0 5.0 90.9 47,730 928 7,141 2.0 13.4 96.4 Perks 10.0 97.7 47,311 87.7 8,862 4.0 23.0 93.5 16.0 96.2 46,892 84.4…arrow_forwardYou are working with a database table that contains customer data. The table includes columns about customer location such as city, state, and country. You want to retrieve the first 3 letters of each country name. You decide to use the SUBSTR function to retrieve the first 3 letters of each country name, and use the AS command to store the result in a new column called new_country. You write the SQL query below. Add a statement to your SQL query that will retrieve the first 3 letters of each country name and store the result in a new column as new_country.arrow_forward
- We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure. Alice's public key (n,public_key) is (247,7). A code breaker manages to factories 247 = 13 x 19 Determine Alice's secret key. To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.arrow_forwardConsider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.arrow_forwardPllleasassseee ssiiirrrr soolveee thissssss questionnnnnnnarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning